From 679080e5ef3181cd8fffde52263fb02db99c9274 Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Sun, 9 Jun 2013 18:14:49 -0700 Subject: [PATCH] Added arm/disarm events. --- pyad2usb/ad2usb.py | 11 +++++++++++ test.py | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/pyad2usb/ad2usb.py b/pyad2usb/ad2usb.py index 760c00d..b568d54 100644 --- a/pyad2usb/ad2usb.py +++ b/pyad2usb/ad2usb.py @@ -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. diff --git a/test.py b/test.py index 02e70df..fff0bfb 100755 --- a/test.py +++ b/test.py @@ -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()