fix(ams): don't crash on rejected multiColorBox setInfo (Issue #100)
The printer replies with state="failed" and data as a 2-element list (["multi_color_box", [...]]) instead of the usual dict when it rejects a manual ACE slot filament assignment (e.g. custom-RFID/third-party material). _on_multicolor_box called data.get(...) unconditionally, crashing with AttributeError and silently dropping the report - including the regular slot-state update that would otherwise follow. Add a state="failed" guard plus a defensive isinstance check, and surface the rejection via _state["last_ams_set_error"] so the caller of handle_api_ams_set_slot's optimistic cache update isn't left showing a false success. Note: this fixes the crash, not necessarily the underlying rejection itself - the printer/ACE may still refuse assignments for material types it doesn't recognize.
This commit is contained in:
@ -1879,10 +1879,18 @@ class KobraXBridge:
|
||||
return activity
|
||||
|
||||
def _on_multicolor_box(self, payload: dict):
|
||||
if payload.get("state") == "failed":
|
||||
log.warning(f"multiColorBox/report failed: {payload.get('data')}")
|
||||
self._state["last_ams_set_error"] = True
|
||||
return
|
||||
data = payload.get("data") or {}
|
||||
if not isinstance(data, dict):
|
||||
log.warning(f"multiColorBox/report: unexpected data shape: {data!r}")
|
||||
return
|
||||
boxes = data.get("multi_color_box") or []
|
||||
if not boxes:
|
||||
return
|
||||
self._state["last_ams_set_error"] = False
|
||||
self._head_tools_model = int(data.get("head_tools_model", self._head_tools_model))
|
||||
self._filament_mode = self._detect_filament_mode(boxes, self._head_tools_model)
|
||||
self._state["filament_mode"] = self._filament_mode
|
||||
@ -4037,6 +4045,7 @@ class KobraXBridge:
|
||||
return web.json_response({"error": "color must be [r,g,b]"}, status=400)
|
||||
box_id, local_slot = self._global_to_box_slot(index)
|
||||
loop = asyncio.get_event_loop()
|
||||
self._state["last_ams_set_error"] = False
|
||||
# setInfo goes via the web/printer topic (like tempature/set). Verified via
|
||||
# Workbench-Vue mqtt_setInfo verifiziert — via slicer/printer/ wurden
|
||||
# slot changes are ignored by the printer and overwritten with the old
|
||||
|
||||
Reference in New Issue
Block a user