diff --git a/alarmdecoder/decoder.py b/alarmdecoder/decoder.py index 8c22757..827dbde 100644 --- a/alarmdecoder/decoder.py +++ b/alarmdecoder/decoder.py @@ -155,19 +155,9 @@ class AlarmDecoder(object): Sets configuration entries on the device. """ config_string = '' - - # HACK: Both of these methods are ugly.. but I can't think of an - # elegant way of doing it. - - #config_string += 'ADDRESS={0}&'.format(self.address) - #config_string += 'CONFIGBITS={0:x}&'.format(self.configbits) - #config_string += 'MASK={0:x}&'.format(self.address_mask) - #config_string += 'EXP={0}&'.format(''.join(['Y' if z else 'N' for z in self.emulate_zone])) - #config_string += 'REL={0}&'.format(''.join(['Y' if r else 'N' for r in self.emulate_relay])) - #config_string += 'LRR={0}&'.format('Y' if self.emulate_lrr else 'N') - #config_string += 'DEDUPLICATE={0}'.format('Y' if self.deduplicate else 'N') - config_entries = [] + + # HACK: This is ugly.. but I can't think of an elegant way of doing it. config_entries.append(('ADDRESS', '{0}'.format(self.address))) config_entries.append(('CONFIGBITS', @@ -437,7 +427,7 @@ class AlarmDecoder(object): """ self.on_read(args, kwargs) - msg = self._handle_message(kwargs['data']) + msg = self._handle_message(kwargs.get('data', None)) if msg: self.on_message(message=msg) diff --git a/alarmdecoder/devices.py b/alarmdecoder/devices.py index f179705..8d9dfd5 100644 --- a/alarmdecoder/devices.py +++ b/alarmdecoder/devices.py @@ -158,6 +158,7 @@ class USBDevice(Device): """Default baudrate for AD2USB devices.""" __devices = [] + __detect_thread = None @classmethod def find_all(cls, vid=FTDI_VENDOR_ID, pid=FTDI_PRODUCT_ID): @@ -638,10 +639,9 @@ class SerialDevice(Device): if self._port is None: raise NoDeviceError('No device interface specified.') - self._device.port = self._port - # Open the device and start up the reader thread. try: + self._device.port = self._port self._device.open() # NOTE: Setting the baudrate before opening the # port caused issues with Moschip 7840/7820 @@ -685,7 +685,7 @@ class SerialDevice(Device): try: self._device.write(data) - except serial.SerialTimeoutException, err: + except serial.SerialTimeoutException: pass except serial.SerialException, err: @@ -808,8 +808,7 @@ class SocketDevice(Device): :param value: Tuple containing the host and port to use. :type value: tuple """ - self._host = value[0] - self._port = value[1] + self._host, self._port = value @property def ssl(self): diff --git a/alarmdecoder/util.py b/alarmdecoder/util.py index f3bc5d9..4a48e70 100644 --- a/alarmdecoder/util.py +++ b/alarmdecoder/util.py @@ -49,6 +49,7 @@ class Firmware(object): STAGE_UPLOADING = 4 STAGE_DONE = 5 + # FIXME: Rewrite this monstrosity. @staticmethod def upload(dev, filename, progress_callback=None): """