Skip to content

Commit

Permalink
Handle hex encoded #33
Browse files Browse the repository at this point in the history
  • Loading branch information
toreamun committed Apr 20, 2022
1 parent c86222a commit 44b4b38
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion custom_components/amshan/metercon.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,15 @@ def _try_read_meter_message(payload: bytes) -> han_type.MeterMessageBase | None:
if len(frames) > 0:
return frames[0]

return None
# is hex?
try:
int(payload, 16)
except ValueError:
return None

binary = (
bytes.fromhex(payload)
if isinstance(payload, str)
else bytes.fromhex(payload.decode("utf8"))
)
return _try_read_meter_message(binary)

0 comments on commit 44b4b38

Please sign in to comment.