A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

  1. import time
  2. from alarmdecoder import AlarmDecoder
  3. from alarmdecoder.devices import USBDevice
  4. # Configuration values
  5. TARGET_ZONE = 41
  6. WAIT_TIME = 10
  7. def main():
  8. """
  9. Example application that periodically faults a virtual zone and then
  10. restores it.
  11. This is an advanced feature that allows you to emulate a virtual zone. When
  12. the AlarmDecoder is configured to emulate a zone expander we can fault and
  13. restore those zones programmatically at will. These events can also be seen by
  14. others, such as home automation platforms which allows you to connect other
  15. devices or services and monitor them as you would any pyhysical zone.
  16. For example, you could connect a ZigBee device and receiver and fault or
  17. restore it's zone(s) based on the data received.
  18. In order for this to happen you need to perform a couple configuration steps:
  19. 1. Enable zone expander emulation on your AlarmDecoder device by hitting '!'
  20. in a terminal and going through the prompts.
  21. 2. Enable the zone expander in your panel programming.
  22. """
  23. try:
  24. # Retrieve the first USB device
  25. device = AlarmDecoder(USBDevice.find())
  26. # Set up an event handlers and open the device
  27. device.on_zone_fault += handle_zone_fault
  28. device.on_zone_restore += handle_zone_restore
  29. with device.open():
  30. last_update = time.time()
  31. while True:
  32. if time.time() - last_update > WAIT_TIME:
  33. last_update = time.time()
  34. device.fault_zone(TARGET_ZONE)
  35. time.sleep(1)
  36. except Exception, ex:
  37. print 'Exception:', ex
  38. def handle_zone_fault(sender, zone):
  39. """
  40. Handles zone fault messages.
  41. """
  42. print 'zone faulted', zone
  43. # Restore the zone
  44. sender.clear_zone(zone)
  45. def handle_zone_restore(sender, zone):
  46. """
  47. Handles zone restore messages.
  48. """
  49. print 'zone cleared', zone
  50. if __name__ == '__main__':
  51. main()