From 58fcee2e7b61dd83a09dc1fac06d0acd8700a947 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Sat, 14 Nov 2020 15:25:57 +0100 Subject: [PATCH] refactor(itho-wpu): check MessageType + move MessageClass check MessageType 4th byte (5th if you include 0x80) is: - 0x01: response - 0x04: request --- itho-wpu.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/itho-wpu.py b/itho-wpu.py index 448a192..f7465a4 100755 --- a/itho-wpu.py +++ b/itho-wpu.py @@ -151,14 +151,21 @@ class I2CMaster: def process_response(action, response, args): - if action == "getdatalog" and int(response[1], 0) == 0xA4 and int(response[2], 0) == 0x01: - measurements = process_datalog(response) + if int(response[3], 0) != 0x01: + logger.error(f"Response MessageType != 0x01 (response), but {response[3]}") + return - if args.export_to_influxdb: - export_to_influxdb(action, measurements) + if action == "getdatalog": + measurements = process_datalog(response) + if args.export_to_influxdb: + export_to_influxdb(action, measurements) 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 # 1 = UnsignedInt # 2 = SignedIntDec2