From 5e1d3f5352561768a850c2c976340d47c1cf64ff Mon Sep 17 00:00:00 2001 From: Scott Petersen Date: Wed, 1 Feb 2017 11:20:58 -0800 Subject: [PATCH] Fix for Python 2 and unicode. --- alarmdecoder/decoder.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/alarmdecoder/decoder.py b/alarmdecoder/decoder.py index 057fb49..667ac34 100644 --- a/alarmdecoder/decoder.py +++ b/alarmdecoder/decoder.py @@ -6,6 +6,7 @@ Provides the main AlarmDecoder class. .. moduleauthor:: Scott Petersen """ +import sys import time import re @@ -248,7 +249,15 @@ class AlarmDecoder(object): """ if self._device: - self._device.write(str.encode(data)) + if isinstance(data, str): + data = str.encode(data) + + # Hack to support unicode under Python 2.x + if sys.version_info < (3,): + if isinstance(data, unicode): + data = bytes(data) + + self._device.write(data) def get_config(self): """