Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work properly with python3 #4

Open
superm1 opened this issue Oct 12, 2016 · 4 comments
Open

Doesn't work properly with python3 #4

superm1 opened this issue Oct 12, 2016 · 4 comments

Comments

@superm1
Copy link

superm1 commented Oct 12, 2016

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()
@erikcw
Copy link
Owner

erikcw commented Dec 4, 2016

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

@ghost
Copy link

ghost commented Oct 1, 2017

@superm1 Did you get it into Home Assistant?

@superm1
Copy link
Author

superm1 commented Oct 1, 2017

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

@iCarl
Copy link

iCarl commented Nov 24, 2017

Please tell us when/if you get this to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants