sunspec / pysunspec

Python SunSpec Tools
MIT License
86 stars 50 forks source link

Bug in python3 version of model_11 #56

Open Heiner92 opened 6 years ago

Heiner92 commented 6 years ago

I found a bug the python 3 branch for model_11

The parsing of the MAC address should be different in py3. In Python 3 the sock.recvfrom(...) call returns bytes while Python 2.7 recvfrom returns a string. I couldn't find the line of code where sock.recvfrom(...) is called but this can be fixed in another way:

The function data_to_eui48 in core/util.py needs to be changed:

def data_to_eui48(data):
    return '%02X:%02X:%02X:%02X:%02X:%02X' % (ord(data[2]), ord(data[3]), ord(data[4]), ord(data[5]), ord(data[6]), ord(data[7]))

data is no longer of type str but of type bytes.

Therefore the line

data=data.decode('utf-8','backslashreplace') 

needs to be added.

A cleaner fix would be to search for all calls of sock.recvfrom(...) and change its output