Browse Source

Added arm/disarm events.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
679080e5ef
2 changed files with 19 additions and 0 deletions
  1. +11
    -0
      pyad2usb/ad2usb.py
  2. +8
    -0
      test.py

+ 11
- 0
pyad2usb/ad2usb.py View File

@@ -151,6 +151,8 @@ class AD2USB(object):
"""

# High-level Events
on_arm = event.Event('Called when the panel is armed.')
on_disarm = event.Event('Called when the panel is disarmed.')
on_status_changed = event.Event('Called when the panel status changes.')
on_power_changed = event.Event('Called when panel power switches between AC and DC.')
on_alarm = event.Event('Called when the alarm is triggered.')
@@ -346,6 +348,15 @@ class AD2USB(object):
if old_status is not None:
self.on_bypass(self._bypass_status)

if (message.armed_away | message.armed_home) != self._armed_status:
self._armed_status, old_status = message.armed_away | message.armed_home, self._armed_status

if old_status is not None:
if self._armed_status:
self.on_arm()
else:
self.on_disarm()

def _on_open(self, sender, args):
"""
Internal handler for opening the device.


+ 8
- 0
test.py View File

@@ -44,6 +44,12 @@ def handle_bypass(sender, args):
def handle_message(sender, args):
print args

def handle_arm(sender, args):
print 'armed', args

def handle_disarm(sender, args):
print 'disarmed', args

def handle_firmware(stage):
if stage == pyad2usb.ad2usb.util.Firmware.STAGE_START:
handle_firmware.wait_tick = 0
@@ -220,6 +226,8 @@ def test_socket():
a2u.on_bypass += handle_bypass
a2u.on_boot += handle_boot
a2u.on_config_received += handle_config
a2u.on_arm += handle_arm
a2u.on_disarm += handle_disarm

a2u.open()
#a2u.save_config()


Loading…
Cancel
Save