niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

Fix for Issue #50 Python3 Fix in _build_command() #51

Closed jamesleesaunders closed 7 years ago

jamesleesaunders commented 7 years ago

Running code:

zigbee = ZigBee(serial)
zigbee.send('at', command='MY')

Running on python3 causes error:

  File "../pyalertme/base.py", line 119, in read_addresses
    self._xbee.send('at', command='MY')
  File "/usr/local/lib/python3.5/site-packages/xbee/base.py", line 394, in send
    self._write(self._build_command(cmd, **kwargs))
  File "/usr/local/lib/python3.5/site-packages/xbee/base.py", line 212, in _build_command
    packet += data
TypeError: can't concat bytes to str

Caused because _build_command() tries to concat bytes with at command 'MY' of type string. This solution proposes checking data type and converting to bytes.

Also written a small unit test to make sure now works. I am not totally sure if test_zigbee.py is the most appropriate place for it.

Fixes Issue #50

jamesleesaunders commented 7 years ago

@hansmosh @mattdodge Please could one of you give this a check over? I didn't want to merge this in until at least one of you had given it a look. I have written a test (albeit not sure in the right place?)