Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions deebot_client/messages/xml/charge_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ def _parse_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
if (charge := xml.find("charge")) is not None and (
charge_type := charge.attrib["type"]
) is not None:
status: None | State = None
match charge_type.lower():
case "slotcharging" | "slot_charging" | "wirecharging":
status = State.DOCKED
case "idle":
status = State.IDLE
# Bot reports IDLE while not on the charger (e.g. while cleaning)
# We ignore this state since it will conflict with the actual cleaning state
pass
Comment thread
edenhaus marked this conversation as resolved.
case "going":
status = State.RETURNING
case _:
status = State.ERROR
event_bus.notify(StateEvent(status))
return HandlingResult.success()
if status:
event_bus.notify(StateEvent(status))
return HandlingResult.success()

return HandlingResult.analyse()
11 changes: 7 additions & 4 deletions tests/commands/xml/test_charge_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
("state", "expected_event"),
[
("SlotCharging", StateEvent(State.DOCKED)),
("Idle", StateEvent(State.IDLE)),
("Going", StateEvent(State.RETURNING)),
("unknown state returned", StateEvent(State.ERROR)),
],
ids=["slot_charging", "idle", "going", "unknown"],
ids=["slot_charging", "going", "unknown"],
)
async def test_get_charge_state(state: str, expected_event: Event) -> None:
json = get_request_xml(f"<ctl ret='ok'><charge type='{state}' g='0'/></ctl>")
Expand All @@ -34,8 +33,12 @@ async def test_get_charge_state(state: str, expected_event: Event) -> None:

@pytest.mark.parametrize(
"xml",
["<ctl ret='error'/>", "<ctl ret='ok'></ctl>"],
ids=["error", "no_state"],
[
"<ctl ret='error'/>",
"<ctl ret='ok'></ctl>",
"<ctl ret='ok'><charge type='Idle' g='0'/></ctl>",
],
ids=["error", "no_state", "idle"],
)
async def test_get_charge_state_error(xml: str) -> None:
json = get_request_xml(xml)
Expand Down
6 changes: 3 additions & 3 deletions tests/messages/xml/test_charge_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
("state", "expected_event"),
[
("SlotCharging", StateEvent(State.DOCKED)),
("Idle", StateEvent(State.IDLE)),
("Going", StateEvent(State.RETURNING)),
("unknown state returned", StateEvent(State.ERROR)),
],
ids=["slot_charging", "idle", "going", "unknown"],
ids=["slot_charging", "going", "unknown"],
)
async def test_charge_state(state: str, expected_event: Event) -> None:
xml_message = f'<ctl ts="1745329944849" td="ChargeState"><charge type="{state}" h="" r="" s="" g="0" /></ctl>'
Expand All @@ -28,8 +27,9 @@ async def test_charge_state(state: str, expected_event: Event) -> None:
"xml_message",
[
'<ctl ts="1745329944849" td="ChargeState" />',
'<ctl ts="1745329944849" td="ChargeState"><charge type="Idle" h="" r="" s="" g="0" /></ctl>',
],
ids=["missing_payload"],
ids=["missing_payload", "idle"],
)
async def test_charge_state_error(xml_message: str) -> None:
assert_message_failure(ChargeState, xml_message, HandlingState.ANALYSE_LOGGED)