Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Check hex length before dec conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
unlobito committed Oct 26, 2021
1 parent 6bdf84c commit ab265bd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/hildebrandglow/mqttpayload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit ab265bd

Please sign in to comment.