Skip to content

Commit 30dc9f9

Browse files
committed
fix: add last HMS message tracking and check print_error for improved hms message handling
1 parent 45f792b commit 30dc9f9

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/bpm/bambuprinter.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(self, config: BambuConfig | None = None):
103103
* _sdcard_3mf_files `READ ONLY` `dict` (json) value of all `.3mf` files on the SDCard (requires `get_sdcard_3mf_files` be called first).
104104
* _hms_data `READ ONLY` `dict` (json) value of any active hms codes with descriptions attached if they are known codes.
105105
* _hms_message `READ ONLY` all hms_data `desc` fields concatinated into a single string for ease of use.
106+
* _last_hms_message `READ ONLY` a saved copy ofthe last hms_message in the event we get a repeat print_error.
106107
* _print_type `READ ONLY` can be `cloud` or `local`
107108
* _skipped_objects `READ ONLY` array of objects that have been skipped / cancelled
108109
* _nozzle_type `READ/WRITE` the type of nozzle loaded into the printer
@@ -183,6 +184,8 @@ class level attributes are marked private.
183184

184185
self._hms_data = None
185186
self._hms_message = ""
187+
self._last_hms_message = ""
188+
186189
self._print_type = ""
187190
self._skipped_objects = []
188191

@@ -1174,19 +1177,35 @@ def _on_message(self, message: str):
11741177
else:
11751178
self._spool_state = "Loaded"
11761179

1177-
self._hms_data = status.get("hms", [])
1178-
self._hms_message = ""
1179-
1180-
for hms in self._hms_data:
1181-
hms_attr = hex(hms.get("attr", 0))[2:].zfill(8).upper()
1182-
hms_code = hex(hms.get("code", 0))[2:].zfill(8).upper()
1183-
for entry in bambucommands.HMS_STATUS["data"]["device_hms"]["en"]:
1184-
if entry["ecode"] == f"{hms_attr}{hms_code}":
1185-
hms["desc"] = entry["intro"]
1186-
self._hms_message = f"{self._hms_message}{entry['intro']} "
1187-
break
1180+
if "print_error" in status:
1181+
err = status["print_error"]
1182+
if err == 0 and self._hms_data or self._hms_message:
1183+
logger.debug("clearing hms data and message")
1184+
self._hms_data = []
1185+
self._last_hms_message = self._hms_message
1186+
self._hms_message = ""
1187+
else:
1188+
if err != 0 and self._last_hms_message:
1189+
logger.debug("restoring last hms message")
1190+
self._hms_message = self._last_hms_message
1191+
1192+
if "hms" in status:
1193+
logger.debug(f"parsing hms data: [{status['hms']}]")
1194+
self._hms_data = status.get("hms", [])
1195+
self._hms_message = ""
1196+
for hms in self._hms_data:
1197+
hms_attr = hex(hms.get("attr", 0))[2:].zfill(8).upper()
1198+
hms_code = hex(hms.get("code", 0))[2:].zfill(8).upper()
1199+
for entry in bambucommands.HMS_STATUS["data"]["device_hms"]["en"]:
1200+
if entry["ecode"] == f"{hms_attr}{hms_code}":
1201+
hms["desc"] = entry["intro"]
1202+
self._hms_message = f"{self._hms_message}{entry['intro']} "
1203+
logger.debug(
1204+
f"found hms message: [{hms_attr}{hms_code} - {entry['intro']}]"
1205+
)
1206+
break
11881207

1189-
self._hms_message = self._hms_message.rstrip()
1208+
self._hms_message = self._hms_message.rstrip()
11901209

11911210
if "home_flag" in status:
11921211
flag = int(status["home_flag"])

0 commit comments

Comments
 (0)