Skip to content

Commit 4cf4042

Browse files
committed
Handle Unicode Decode errors from receiving data
1 parent 243a104 commit 4cf4042

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sense_energy/sense_link.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def connection_lost(self, exc) -> None:
3737

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

4246
try:
4347
json_data = orjson.loads(decrypted_data)

0 commit comments

Comments
 (0)