uebelack / python-maxcube-api

A python api to control the Max! Cube thermostats.
https://github.com/uebelack/python-maxcube-api
MIT License
21 stars 26 forks source link

cube.set_mode(device,MAX_DEVICE_MODE_AUTOMATIC) failed #11

Closed Hagenmue closed 3 years ago

Hagenmue commented 6 years ago

device is a thermostat

cube.set_mode(device, MAX_DEVICE_MODE_MANUAL) works fine, but cube.set_mode(device,MAX_DEVICE_MODE_AUTOMATIC) failed with: Traceback (most recent call last): File "./test_einstellung.py", line 31, in <module> cube.set_mode(device,MAX_DEVICE_MODE_AUTOMATIC) File "/usr/local/lib/python2.7/dist-packages/maxcube/cube.py", line 253, in set_mode self.set_temperature_mode(thermostat, thermostat.target_temperature, mode) File "/usr/local/lib/python2.7/dist-packages/maxcube/cube.py", line 270, in set_temperature_mode command = 's:' + base64.b64encode(bytearray.fromhex(byte_cmd)).decode('utf-8') + '\r\n' ValueError: non-hexadecimal number found in fromhex() arg at position 20

Hagenmue commented 6 years ago

OK, I have found the problem. if hex(target_temperature)[2:]< 0x10 (this occure if mode=AUTOMATIC) the conversion fails, so I have changed the code to:

target_temperature = int(temperature * 2) + (mode << 6) tmp = hex(target_temperature)[2:] bl=len(tmp) if (bl % 2): tmp = '0' + tmp byte_cmd = '000440000000' + rf_address + room + tmp