From e867a4f3b408c197ed556e065daf1779df54b97b Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Tue, 17 Jun 2014 10:35:51 -0700 Subject: [PATCH] Added LRR example. Updated gitignore. --- .gitignore | 2 ++ examples/lrr_example.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/lrr_example.py diff --git a/.gitignore b/.gitignore index 921905b..8a9acf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +alarmdecoder.sublime-project +alarmdecoder.sublime-workspace build/ dist tmp diff --git a/examples/lrr_example.py b/examples/lrr_example.py new file mode 100644 index 0000000..ba1b627 --- /dev/null +++ b/examples/lrr_example.py @@ -0,0 +1,29 @@ +import time +from alarmdecoder import AlarmDecoder +from alarmdecoder.devices import USBDevice + +def main(): + """ + Example application that prints messages from the panel to the terminal. + """ + try: + # Retrieve the first USB device + device = AlarmDecoder(USBDevice.find()) + + # Set up an event handler and open the device + device.on_lrr_message += handle_lrr_message + with device.open(): + while True: + time.sleep(1) + + except Exception, ex: + print 'Exception:', ex + +def handle_lrr_message(sender, message): + """ + Handles message events from the AlarmDecoder. + """ + print sender, message.partition, message.event_type, message.event_data + +if __name__ == '__main__': + main()