@@ -163,6 +163,7 @@ class AD2USB(object): | |||
on_config_received = event.Event('Called when the device receives its configuration.') | |||
on_zone_fault = event.Event('Called when the device detects a zone fault.') | |||
on_zone_restore = event.Event('Called when the device detects that a fault is restored.') | |||
on_low_battery = event.Event('Called when the device detects a low battery.') | |||
# Mid-level Events | |||
on_message = event.Event('Called when a message has been received from the device.') | |||
@@ -191,6 +192,7 @@ class AD2USB(object): | |||
self._bypass_status = None | |||
self._armed_status = None | |||
self._fire_status = None | |||
self._battery_status = None | |||
self.address = 18 | |||
self.configbits = 0xFF00 | |||
@@ -386,6 +388,15 @@ class AD2USB(object): | |||
else: | |||
self.on_disarm() | |||
# TODO: This needs a timeout or something.. only set on the LO BAT messages | |||
# instead of all messages after. | |||
if message.battery_low != self._battery_status: | |||
self._battery_status, old_status = message.battery_low, self._battery_status | |||
if old_status is not None and self._battery_status == True: | |||
self.on_low_battery(self._battery_status) | |||
# TODO: Also needs a timeout. | |||
if message.fire_alarm != self._fire_status: | |||
self._fire_status, old_status = message.fire_alarm, self._fire_status | |||
@@ -394,6 +405,7 @@ class AD2USB(object): | |||
self._update_zone_tracker(message) | |||
def _update_zone_tracker(self, message): | |||
# Retrieve a list of faults. | |||
# NOTE: This only happens on first boot or after exiting programming mode. | |||
@@ -90,6 +90,12 @@ def handle_fault(sender, args): | |||
def handle_restore(sender, args): | |||
print 'zone restored', args | |||
def handle_battery(sender, args): | |||
print 'low battery', args | |||
def handle_fire(sender, args): | |||
print 'FIRE!', args | |||
def upload_usb(): | |||
dev = pyad2usb.ad2usb.devices.USBDevice() | |||
@@ -227,7 +233,7 @@ def test_socket(): | |||
#a2u.on_read += handle_read | |||
#a2u.on_write += handle_write | |||
a2u.on_message += handle_message | |||
#a2u.on_message += handle_message | |||
a2u.on_power_changed += handle_power_changed | |||
a2u.on_alarm += handle_alarm_bell | |||
a2u.on_bypass += handle_bypass | |||
@@ -237,6 +243,10 @@ def test_socket(): | |||
a2u.on_disarm += handle_disarm | |||
a2u.on_zone_fault += handle_fault | |||
a2u.on_zone_restore += handle_restore | |||
# | |||
a2u.on_fire += handle_fire | |||
a2u.on_low_battery += handle_battery | |||
a2u.open() | |||
#a2u.save_config() | |||
@@ -251,15 +261,15 @@ def test_socket(): | |||
#a2u.emulate_lrr = False | |||
#a2u.deduplicate = False | |||
#time.sleep(3) | |||
#a2u.emulate_zone[1] = True | |||
time.sleep(3) | |||
#a2u.emulate_zone[1] = False | |||
#a2u.save_config() | |||
time.sleep(1) | |||
a2u.fault_zone(17, True) | |||
#time.sleep(1) | |||
#a2u.fault_zone(17, True) | |||
time.sleep(15) | |||
a2u.clear_zone(17) | |||
#time.sleep(15) | |||
#a2u.clear_zone(17) | |||
#time.sleep(1) | |||
#a2u.fault_zone((2, 2), True) | |||