From 0a6d493d1153e0e05f934eeb7af9e43870e89ce7 Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Mon, 3 Feb 2014 12:59:42 -0800 Subject: [PATCH] Updated default address mask, proper handling of invalid messages, added fileno() to support use with select(). --- alarmdecoder/decoder.py | 2 +- alarmdecoder/devices.py | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/alarmdecoder/decoder.py b/alarmdecoder/decoder.py index 568de9d..074c98a 100644 --- a/alarmdecoder/decoder.py +++ b/alarmdecoder/decoder.py @@ -66,7 +66,7 @@ class AlarmDecoder(object): """The keypad address in use by the device.""" configbits = 0xFF00 """The configuration bits set on the device.""" - address_mask = 0x00000000 + address_mask = 0xFFFFFFFF """The address mask configured on the device.""" emulate_zone = [False for _ in range(5)] """List containing the devices zone emulation status.""" diff --git a/alarmdecoder/devices.py b/alarmdecoder/devices.py index 7fce36c..f1e7a7c 100644 --- a/alarmdecoder/devices.py +++ b/alarmdecoder/devices.py @@ -25,7 +25,7 @@ import socket from OpenSSL import SSL, crypto from pyftdi.pyftdi.ftdi import Ftdi, FtdiError -from .util import CommError, TimeoutError, NoDeviceError +from .util import CommError, TimeoutError, NoDeviceError, InvalidMessageError from .event import event @@ -149,7 +149,10 @@ class Device(object): except TimeoutError: pass - except Exception: + except InvalidMessageError: + pass + + except Exception, err: self._running = False @@ -234,7 +237,10 @@ class USBDevice(Device): """ cls.__detect_thread = USBDevice.DetectThread(on_attached, on_detached) - cls.find_all() + try: + cls.find_all() + except CommError: + pass cls.__detect_thread.start() @@ -390,6 +396,9 @@ class USBDevice(Device): except Exception: pass + def fileno(self): + raise NotImplementedError('USB devices do not support fileno()') + def write(self, data): """ Writes data to the device. @@ -670,6 +679,9 @@ class SerialDevice(Device): except Exception: pass + def fileno(self): + return self._device.fileno() + def write(self, data): """ Writes data to the device. @@ -944,6 +956,9 @@ class SocketDevice(Device): except Exception: pass + def fileno(self): + return self._device.fileno() + def write(self, data): """ Writes data to the device.