Skip to content

Commit 5d302c1

Browse files
authored
XML ChargeState IDLE should not produce any events (#956)
1 parent 9103bb5 commit 5d302c1

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

deebot_client/messages/xml/charge_state.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,20 @@ def _parse_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
3737
if (charge := xml.find("charge")) is not None and (
3838
charge_type := charge.attrib["type"]
3939
) is not None:
40+
status: None | State = None
4041
match charge_type.lower():
4142
case "slotcharging" | "slot_charging" | "wirecharging":
4243
status = State.DOCKED
4344
case "idle":
44-
status = State.IDLE
45+
# Bot reports IDLE while not on the charger (e.g. while cleaning)
46+
# We ignore this state since it will conflict with the actual cleaning state
47+
pass
4548
case "going":
4649
status = State.RETURNING
4750
case _:
4851
status = State.ERROR
49-
event_bus.notify(StateEvent(status))
50-
return HandlingResult.success()
52+
if status:
53+
event_bus.notify(StateEvent(status))
54+
return HandlingResult.success()
5155

5256
return HandlingResult.analyse()

tests/commands/xml/test_charge_state.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
("state", "expected_event"),
2222
[
2323
("SlotCharging", StateEvent(State.DOCKED)),
24-
("Idle", StateEvent(State.IDLE)),
2524
("Going", StateEvent(State.RETURNING)),
2625
("unknown state returned", StateEvent(State.ERROR)),
2726
],
28-
ids=["slot_charging", "idle", "going", "unknown"],
27+
ids=["slot_charging", "going", "unknown"],
2928
)
3029
async def test_get_charge_state(state: str, expected_event: Event) -> None:
3130
json = get_request_xml(f"<ctl ret='ok'><charge type='{state}' g='0'/></ctl>")
@@ -34,8 +33,12 @@ async def test_get_charge_state(state: str, expected_event: Event) -> None:
3433

3534
@pytest.mark.parametrize(
3635
"xml",
37-
["<ctl ret='error'/>", "<ctl ret='ok'></ctl>"],
38-
ids=["error", "no_state"],
36+
[
37+
"<ctl ret='error'/>",
38+
"<ctl ret='ok'></ctl>",
39+
"<ctl ret='ok'><charge type='Idle' g='0'/></ctl>",
40+
],
41+
ids=["error", "no_state", "idle"],
3942
)
4043
async def test_get_charge_state_error(xml: str) -> None:
4144
json = get_request_xml(xml)

tests/messages/xml/test_charge_state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
("state", "expected_event"),
1414
[
1515
("SlotCharging", StateEvent(State.DOCKED)),
16-
("Idle", StateEvent(State.IDLE)),
1716
("Going", StateEvent(State.RETURNING)),
1817
("unknown state returned", StateEvent(State.ERROR)),
1918
],
20-
ids=["slot_charging", "idle", "going", "unknown"],
19+
ids=["slot_charging", "going", "unknown"],
2120
)
2221
async def test_charge_state(state: str, expected_event: Event) -> None:
2322
xml_message = f'<ctl ts="1745329944849" td="ChargeState"><charge type="{state}" h="" r="" s="" g="0" /></ctl>'
@@ -28,8 +27,9 @@ async def test_charge_state(state: str, expected_event: Event) -> None:
2827
"xml_message",
2928
[
3029
'<ctl ts="1745329944849" td="ChargeState" />',
30+
'<ctl ts="1745329944849" td="ChargeState"><charge type="Idle" h="" r="" s="" g="0" /></ctl>',
3131
],
32-
ids=["missing_payload"],
32+
ids=["missing_payload", "idle"],
3333
)
3434
async def test_charge_state_error(xml_message: str) -> None:
3535
assert_message_failure(ChargeState, xml_message, HandlingState.ANALYSE_LOGGED)

0 commit comments

Comments
 (0)