From 89352d372a8c2590ee990797805a81c1ded6195f Mon Sep 17 00:00:00 2001 From: Li Ji <60339402+Heartcoolman@users.noreply.github.com> Date: Thu, 24 Sep 2026 10:54:13 +0800 Subject: [PATCH] fix: drop non-UTF-8 cloud mips message instead of crashing mqtt loop (#1750) MipsCloudClient._on_mips_message decodes the push payload with a bare payload.decode('utf-8'). Some cloud pushes carry payloads that are not valid UTF-8, which raises UnicodeDecodeError inside paho's on_message, aborts the read loop and silently drops the message. Lost device online/offline pushes can leave a device stuck unavailable until the config entry is reloaded manually. Catch UnicodeDecodeError, log the topic and the payload hex for diagnosis, and skip the message so that one malformed push cannot break message processing. Related to #1749 --- custom_components/xiaomi_home/miot/miot_mips.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/custom_components/xiaomi_home/miot/miot_mips.py b/custom_components/xiaomi_home/miot/miot_mips.py index c9eca28..d083bcc 100644 --- a/custom_components/xiaomi_home/miot/miot_mips.py +++ b/custom_components/xiaomi_home/miot/miot_mips.py @@ -1102,7 +1102,16 @@ class MipsCloudClient(_MipsClient): if not bc_list: return # The message from the cloud is not packed. - payload_str: str = payload.decode('utf-8') + try: + payload_str: str = payload.decode('utf-8') + except UnicodeDecodeError as err: + # Some cloud pushes carry a payload that is not valid UTF-8. + # Drop the message instead of raising, otherwise the exception + # aborts paho's read loop and subsequent messages may be lost. + self.log_error( + f'on message, drop non-utf-8 payload, {err}, {topic}, ' + f'{payload.hex()}') + return # self.log_debug(f"on broadcast, {topic}, {payload}") for item in bc_list or []: if item.handler is None: