1
0
mirror of https://github.com/pommi/python-itho-wpu.git synced 2024-11-22 14:02:15 +01:00

refactor(itho-wpu): check MessageType + move MessageClass check

MessageType 4th byte (5th if you include 0x80) is:
- 0x01: response
- 0x04: request
This commit is contained in:
Pim van den Berg 2020-11-14 15:25:57 +01:00
parent 152b6021cf
commit 11ae0978b3

View File

@ -151,14 +151,21 @@ class I2CMaster:
def process_response(action, response, args): def process_response(action, response, args):
if action == "getdatalog" and int(response[1], 0) == 0xA4 and int(response[2], 0) == 0x01: if int(response[3], 0) != 0x01:
measurements = process_datalog(response) logger.error(f"Response MessageType != 0x01 (response), but {response[3]}")
return
if args.export_to_influxdb: if action == "getdatalog":
export_to_influxdb(action, measurements) measurements = process_datalog(response)
if args.export_to_influxdb:
export_to_influxdb(action, measurements)
def process_datalog(response): def process_datalog(response):
if int(response[1], 0) != 0xA4 and int(response[2], 0) != 0x01:
logger.error(f"Response MessageClass != 0xA4 0x01 (getdatalog), but {response[1]} {response[2]}")
return
# 0 = Byte # 0 = Byte
# 1 = UnsignedInt # 1 = UnsignedInt
# 2 = SignedIntDec2 # 2 = SignedIntDec2