Browse Source

Hack for existing installs without python-future.

pyserial_fix
Scott Petersen 8 years ago
parent
commit
644ded7038
3 changed files with 36 additions and 10 deletions
  1. +5
    -2
      alarmdecoder/decoder.py
  2. +27
    -7
      alarmdecoder/devices.py
  3. +4
    -1
      alarmdecoder/messages.py

+ 5
- 2
alarmdecoder/decoder.py View File

@@ -9,7 +9,10 @@ Provides the main AlarmDecoder class.
import time
import re

from builtins import chr
try:
from builtins import chr
except ImportError:
pass

from .event import event
from .util import InvalidMessageError
@@ -456,7 +459,7 @@ class AlarmDecoder(object):
def _handle_version(self, data):
"""
Handles received version data.
:param data: Version string to parse
:type data: string
"""


+ 27
- 7
alarmdecoder/devices.py View File

@@ -21,7 +21,7 @@ import serial
import serial.tools.list_ports
import socket
import select
from builtins import bytes
import sys

from .util import CommError, TimeoutError, NoDeviceError, InvalidMessageError
from .event import event
@@ -64,6 +64,20 @@ except ImportError:
have_openssl = False


def bytes_hack(buf):
"""
Hacky workaround for old installs of the library on systems without python-future that were
keeping the 2to3 update from working after auto-update.
"""
ub = None
if sys.version_info > (3,):
ub = buf
else:
ub = bytes(buf)

return ub


class Device(object):
"""
Base class for all `AlarmDecoder`_ (AD2) device types.
@@ -550,9 +564,11 @@ class USBDevice(Device):
buf = self._device.read_data(1)

if buf != b'':
self._buffer += buf
ub = bytes_hack(buf)

self._buffer += ub

if buf == b"\n":
if ub == b"\n":
self._buffer = self._buffer.rstrip(b"\r\n")

if len(self._buffer) > 0:
@@ -846,9 +862,11 @@ class SerialDevice(Device):

# NOTE: AD2SERIAL apparently sends down \xFF on boot.
if buf != b'' and buf != b"\xff":
self._buffer += buf
ub = bytes_hack(buf)

if buf == b"\n":
self._buffer += ub

if ub == b"\n":
self._buffer = self._buffer.rstrip(b"\r\n")

if len(self._buffer) > 0:
@@ -1149,9 +1167,11 @@ class SocketDevice(Device):
buf = self._device.recv(1)

if buf != b'':
self._buffer += buf
ub = bytes_hack(buf)

self._buffer += ub

if buf == b"\n":
if ub == b"\n":
self._buffer = self._buffer.rstrip(b"\r\n")

if len(self._buffer) > 0:


+ 4
- 1
alarmdecoder/messages.py View File

@@ -15,7 +15,10 @@ devices.
import re
import datetime

from reprlib import repr
try:
from reprlib import repr
except ImportError:
from repr import repr

from .util import InvalidMessageError
from .panels import PANEL_TYPES, ADEMCO, DSC


Loading…
Cancel
Save