whaleygeek / pyenergenie

A python interface to the Energenie line of products
MIT License
81 stars 51 forks source link

Error in Monitor.py if no records in received message #13

Closed whaleygeek closed 8 years ago

whaleygeek commented 8 years ago

This error occurs when using the eTRV.

Something on the network seems to have sent back a response with no records in it. The join functionality in the monitor.py cannot cope with zero records being sent back. Need to change the join response code to be more resilient to zero record responses.

readfifo:['0xa', '0x4', '0x3', '0x2f', '0xd2', '0x78', '0x36', '0x18', '0x48', '0xbc', '0xf1'] 0xa 0x4 0x3 0x2f 0xd2 0x0 0x4 0xae 0x0 0xe2 0xb1 {'header': {'encryptPIP': xxxxx, 'mfrid': 4, 'productid': 3, 'sensorid': xxxx}, 'recs': [], 'type': 'OK'} mfrid:0x4 prodid:0x3 sensorid:0x 1444680820.06,4,3,1198,00000,None,None,None,None,None Traceback (most recent call last): File "monitor.py", line 205, in monitor() File "monitor.py", line 177, in monitor if decoded["recs"][0]["paramid"] == OpenHEMS.PARAM_JOIN: IndexError: list index out of range

whaleygeek commented 8 years ago

This is now fixed:

https://github.com/whaleygeek/pyenergenie/commit/7fcf416e2d786b3c78629cef6e11df5ef4b9a785

Added extra guard code in monitor.py to count the number of records in any request, and skip it if it is empty. Tested with eTRV which sends an empty join request on startup.