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.

71 lines
2.0 KiB

  1. import time
  2. from pyad2 import AD2
  3. from pyad2.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 AD2 is configured to emulate a relay expander we can fault and restore
  13. those zones programmatically at will. These events can also be seen by others,
  14. such as home automation platforms which allows you to connect other devices or
  15. 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 AD2 device by hitting '!' in a
  20. 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 = AD2(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, *args, **kwargs):
  39. """
  40. Handles zone fault messages.
  41. """
  42. zone = kwargs['zone']
  43. print 'zone faulted', zone
  44. # Restore the zone
  45. sender.clear_zone(zone)
  46. def handle_zone_restore(sender, *args, **kwargs):
  47. """
  48. Handles zone restore messages.
  49. """
  50. zone = kwargs['zone']
  51. print 'zone cleared', zone
  52. if __name__ == '__main__':
  53. main()