mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-09 07:25:44 +02:00
fix(drying): stop false "drying complete" from killing the printer via smart-plug auto-off (#1462)
Reporter on X2D set a 1h AMS dry; the printer powered off seconds in.
Support log: every "Sent drying command duration=1" was followed 3-9s
later by "AMS 0 drying complete (dry_time 60 -> 0)" -- the completion
callback fired right after drying started, arming smart-plug auto-off.
Root cause: the tray-bearing branch of the AMS partial-update merge
rebuilt the unit as {**ams_unit, "tray": merged_trays}, never spreading
existing_unit. Tray-bearing partials carry no drying fields, so dry_time
(and info) was dropped; the falling-edge detector read the absent field
as 0 and saw a false 60->0 edge.
- Merge: tray branch now spreads existing_unit first, preserving
dry_time / info / humidity / temp across tray-only partials. Matches
the no-tray branch. Also fixes dry_status/dry_sub_status UI flapping.
- Detector: only evaluate the falling edge when dry_time is explicitly
present and parseable; skip otherwise without updating state.
This commit is contained in:
@@ -5132,3 +5132,23 @@ class TestDryingCompleteCallback:
|
||||
# And finishes.
|
||||
mqtt_client._handle_ams_data({"ams": [{"id": "0", "dry_time": 0, "tray": []}]})
|
||||
assert mqtt_client._drying_events == [0, 0]
|
||||
|
||||
def test_tray_only_partial_does_not_fake_completion(self, mqtt_client):
|
||||
"""#1462 — a tray-bearing partial update that omits dry_time must not
|
||||
be read as dry_time=0. The pre-fix merge dropped dry_time on such
|
||||
partials, so the falling-edge detector saw a 60→0 edge and fired a
|
||||
false 'drying complete' seconds after drying started — which armed
|
||||
smart-plug auto-off and killed the printer mid-cycle."""
|
||||
# Drying active, 60 minutes remaining.
|
||||
mqtt_client._handle_ams_data({"ams": [{"id": "0", "dry_time": 60, "tray": []}]})
|
||||
assert mqtt_client._drying_events == []
|
||||
|
||||
# Printer sends a tray-bearing partial carrying NO dry_time field.
|
||||
mqtt_client._handle_ams_data({"ams": [{"id": "0", "tray": []}]})
|
||||
assert mqtt_client._drying_events == []
|
||||
# dry_time survived the partial in the merged AMS state.
|
||||
assert mqtt_client.state.raw_data["ams"][0]["dry_time"] == 60
|
||||
|
||||
# Drying genuinely finishes → the real edge still fires exactly once.
|
||||
mqtt_client._handle_ams_data({"ams": [{"id": "0", "dry_time": 0, "tray": []}]})
|
||||
assert mqtt_client._drying_events == [0]
|
||||
|
||||
Reference in New Issue
Block a user