API change and some additional notes
Posted: Sat Jan 24, 2015 6:36 pm
In the documentation online, it has the callback on_alarm taking a callback of (device, status) but in the new documentation, that callback has been changed.
The new alarm handling is comprised of two callbacks, on_alarm and on_alarm_restored:
device.on_alarm += handle_alarm
device.on_alarm_restored += handle_alarm_restored
and they as passed zones like this:
def handle_alarm(sender, zone):
s = 'ALARM TRIGGERED!: ' + zoneStr[int(zone)]
log_alert(s)
send_email(s)
Another thing to notice, I have mappings of the zone numbers to strings like this:
zoneStr = {
1: 'Front Door',
2: 'Office Exterior Door',
etc.
in my code and I noticed that the zone in handle_alarm is passed in as string '001'. To map it into the zoneStr mappings, I cast it to a int to remove the leading '00'.
One last note, if you block in the alarm decoder callbacks, you may miss events. If you do something like send off emails or do HTTP connections, you should do them in another thread not to block the alarm decoder.
Product works great, finished testing it today.
Oh one additional thing, when I got it and installed it, it gave me some expansion zone fault until I added it as an additional control panel in the alarm system control panel. So, when you wire it up the first time and turn the system on and see a zone expansion fault, finish the configuration before worrying about it if you see that.
The new alarm handling is comprised of two callbacks, on_alarm and on_alarm_restored:
device.on_alarm += handle_alarm
device.on_alarm_restored += handle_alarm_restored
and they as passed zones like this:
def handle_alarm(sender, zone):
s = 'ALARM TRIGGERED!: ' + zoneStr[int(zone)]
log_alert(s)
send_email(s)
Another thing to notice, I have mappings of the zone numbers to strings like this:
zoneStr = {
1: 'Front Door',
2: 'Office Exterior Door',
etc.
in my code and I noticed that the zone in handle_alarm is passed in as string '001'. To map it into the zoneStr mappings, I cast it to a int to remove the leading '00'.
One last note, if you block in the alarm decoder callbacks, you may miss events. If you do something like send off emails or do HTTP connections, you should do them in another thread not to block the alarm decoder.
Product works great, finished testing it today.
Oh one additional thing, when I got it and installed it, it gave me some expansion zone fault until I added it as an additional control panel in the alarm system control panel. So, when you wire it up the first time and turn the system on and see a zone expansion fault, finish the configuration before worrying about it if you see that.