Skip to content

Commit

Permalink
Handle Unicode Decode errors from receiving data
Browse files Browse the repository at this point in the history
  • Loading branch information
kbickar committed Feb 1, 2024
1 parent 243a104 commit 4cf4042
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sense_energy/sense_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def connection_lost(self, exc) -> None:

def datagram_received(self, data: bytes, addr: Union[Tuple[str, int], Tuple[str, int, int, int]]) -> None:
"""Handle incoming UDP datagram."""
decrypted_data = tp_link_decrypt(data)
try:
decrypted_data = tp_link_decrypt(data)
except UnicodeDecodeError:
_LOGGER.debug(f"Failed to decrypt data from {addr}")
return

try:
json_data = orjson.loads(decrypted_data)
Expand Down

0 comments on commit 4cf4042

Please sign in to comment.