pycirculate icon indicating copy to clipboard operation
pycirculate copied to clipboard

Doesn't work properly with python3

Open superm1 opened this issue 8 years ago • 4 comments

I was looking into using this for home-assistant. In the process I noticed that it doesn't work properly with python3.

Traceback (most recent call last):
  File "anova.py", line 13, in <module>
    print(anova.read_unit())
  File "/srv/hass/lib/python3.4/site-packages/pycirculate/anova.py", line 74, in read_unit
    return self.send_command_async("read unit")
  File "/srv/hass/lib/python3.4/site-packages/pycirculate/anova.py", line 64, in send_command_async
    self._send_command(command)
  File "/srv/hass/lib/python3.4/site-packages/pycirculate/anova.py", line 54, in _send_command
    self.characteristic.write(command)
  File "/srv/hass/lib/python3.4/site-packages/bluepy/btle.py", line 148, in write
    self.peripheral.writeCharacteristic(self.valHandle, val, withResponse)
  File "/srv/hass/lib/python3.4/site-packages/bluepy/btle.py", line 458, in writeCharacteristic
    self._writeCmd("%s %X %s\n" % (cmd, handle, binascii.b2a_hex(val).decode('utf-8')))
TypeError: 'str' does not support the buffer interface

Making this change appears to fix it (although I don't know what it does to python2)

diff --git a/pycirculate/anova.py b/pycirculate/anova.py
index 3d39c25..b863a83 100644
--- a/pycirculate/anova.py
+++ b/pycirculate/anova.py
@@ -59,7 +59,7 @@ class AnovaController(object):

     def _send_command(self, command):
         command = "{0}\r".format(command)
-        self.characteristic.write(command)
+        self.characteristic.write(bytes(command, 'UTF-8'))

     def _read(self):
         #self.characteristic.read()

superm1 avatar Oct 12 '16 03:10 superm1

Pull requests welcome. Maybe use https://pypi.python.org/pypi/six for Python 2/3 compatibility.

erikcw avatar Dec 04 '16 23:12 erikcw

@superm1 Did you get it into Home Assistant?

ghost avatar Oct 01 '17 01:10 ghost

No I didn't. I ran into other troubles that were taking longer to debug so I got distracted.

superm1 avatar Oct 01 '17 10:10 superm1

Please tell us when/if you get this to work

iCarl avatar Nov 24 '17 12:11 iCarl