From ab265bdb22c73ae7ceab8a550dfc34e38b3bccd7 Mon Sep 17 00:00:00 2001 From: Harley Watson Date: Tue, 26 Oct 2021 18:40:25 +0100 Subject: [PATCH] Check hex length before dec conversion --- custom_components/hildebrandglow/mqttpayload.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/custom_components/hildebrandglow/mqttpayload.py b/custom_components/hildebrandglow/mqttpayload.py index 406e5dd..10f99c3 100644 --- a/custom_components/hildebrandglow/mqttpayload.py +++ b/custom_components/hildebrandglow/mqttpayload.py @@ -181,7 +181,9 @@ def __init__(self, payload: Dict[str, Any]): def _hex_twos_complement_to_decimal(self, hex_value: str) -> int: """Perform signed 2's complement conversion.""" - return int(struct.unpack(">i", bytes.fromhex(hex_value))[0]) + if len(hex_value) == 8: + return int(struct.unpack(">i", bytes.fromhex(hex_value))[0]) + return int(hex_value, 16) class AlternativeHistoricalConsumption: """Information about the meter's altenative historical readings."""