Skip to content

Doesn't work properly with python3 #4

@superm1

Description

@superm1

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions