Fix A1 Mini "unknown" status from non-UTF-8 MQTT payload (#549)

Some firmware versions send MQTT payloads with non-UTF-8 bytes.
  UnicodeDecodeError was uncaught, silently dropping the entire message
  and leaving printer status as "unknown" with 0°C temps and no AMS.

  Fall back to decode(errors="replace") to keep JSON parseable.
This commit is contained in:
maziggy
2026-02-28 10:26:39 +01:00
parent 04e64ffde1
commit 691234457c
2 changed files with 14 additions and 1 deletions
+13 -1
View File
@@ -442,7 +442,19 @@ class BambuMQTTClient:
def _on_message(self, client, userdata, msg):
try:
payload = json.loads(msg.payload.decode())
try:
raw = msg.payload.decode()
except UnicodeDecodeError:
# Some firmware versions (e.g. A1 Mini 01.07.02.00) send payloads
# with non-UTF-8 bytes. Replace invalid bytes to keep JSON parseable.
raw = msg.payload.decode(errors="replace")
logger.warning(
"[%s] MQTT payload contained non-UTF-8 bytes (topic=%s, len=%d)",
self.serial_number,
msg.topic,
len(msg.payload),
)
payload = json.loads(raw)
# Track last message time - receiving a message proves we're connected
self._last_message_time = time.time()
self.state.connected = True