Skip to content

Commit 1dffae2

Browse files
committed
Add missing test cases
1 parent 75bb169 commit 1dffae2

2 files changed

Lines changed: 43 additions & 16 deletions

File tree

deebot_client/commands/xml/clean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
9191
event_bus.notify(StateEvent(State.CLEANING))
9292
elif clean_action == CleanAction.PAUSE:
9393
event_bus.notify(StateEvent(State.PAUSED))
94-
else:
95-
_LOGGER.debug("Ignored CleanState %s", clean_action)
94+
elif clean_action in (CleanAction.RESUME, CleanAction.STOP):
95+
event_bus.notify(StateEvent(State.IDLE))
9696

9797
return HandlingResult.success()

tests/commands/xml/test_clean.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33
import pytest
44

55
from deebot_client.command import CommandResult
6-
from deebot_client.commands.xml import GetCleanState
7-
from deebot_client.commands.xml.clean import CleanArea
6+
from deebot_client.commands.xml import Clean, CleanArea, GetCleanState
87
from deebot_client.events import FanSpeedEvent, FanSpeedLevel, StateEvent
98
from deebot_client.message import HandlingState
10-
from deebot_client.models import CleanMode, State
9+
from deebot_client.models import CleanAction, CleanMode, State
1110
from tests.commands import assert_command
1211

1312
from . import get_request_xml
1413

1514

15+
@pytest.mark.parametrize(
16+
("command", "command_result"),
17+
[
18+
(Clean(CleanAction.START, speed=FanSpeedLevel.MAX), HandlingState.SUCCESS),
19+
(Clean(CleanAction.PAUSE), HandlingState.SUCCESS),
20+
],
21+
)
22+
async def test_Clean(command: Clean, command_result: HandlingState) -> None:
23+
json = get_request_xml("<ctl ret='ok'/>")
24+
await assert_command(
25+
command, json, None, command_result=CommandResult(command_result)
26+
)
27+
28+
1629
@pytest.mark.parametrize(
1730
("command", "command_result"),
1831
[
@@ -27,37 +40,51 @@ async def test_CleanArea(command: CleanArea, command_result: HandlingState) -> N
2740

2841

2942
@pytest.mark.parametrize(
30-
("speed", "state", "expected_fan_speed_event", "expected_state_event"),
43+
("speed", "action", "expected_fan_speed_event", "expected_state_event"),
3144
[
3245
(
33-
"standard",
34-
"s",
46+
FanSpeedLevel.NORMAL,
47+
CleanAction.START,
3548
FanSpeedEvent(FanSpeedLevel.NORMAL),
3649
StateEvent(State.CLEANING),
3750
),
3851
(
39-
"strong",
40-
"s",
52+
FanSpeedLevel.MAX,
53+
CleanAction.START,
4154
FanSpeedEvent(FanSpeedLevel.MAX),
4255
StateEvent(State.CLEANING),
4356
),
4457
(
45-
"standard",
46-
"p",
58+
FanSpeedLevel.NORMAL,
59+
CleanAction.PAUSE,
4760
FanSpeedEvent(FanSpeedLevel.NORMAL),
4861
StateEvent(State.PAUSED),
4962
),
63+
(
64+
None,
65+
CleanAction.RESUME,
66+
None,
67+
StateEvent(State.IDLE),
68+
),
69+
(
70+
None,
71+
CleanAction.STOP,
72+
None,
73+
StateEvent(State.IDLE),
74+
),
5075
],
51-
ids=["standard_cleaning", "strong_cleaning", "paused"],
76+
ids=["standard_cleaning", "strong_cleaning", "paused", "resume/idle", "stop/idle"],
5277
)
5378
async def test_get_clean_state(
54-
speed: str,
55-
state: str,
79+
speed: FanSpeedLevel | None,
80+
action: CleanAction | None,
5681
expected_fan_speed_event: FanSpeedEvent,
5782
expected_state_event: StateEvent,
5883
) -> None:
84+
speed_section = f"speed='{speed.xml_value}'" if speed is not None else ""
85+
state_section = f"st='{action.xml_value}'" if action is not None else ""
5986
json = get_request_xml(
60-
f"<ctl ret='ok'><clean type='auto' speed='{speed}' st='{state}' t='0' a='0' s='0' tr=''/></ctl>"
87+
f"<ctl ret='ok'><clean type='auto' {speed_section} {state_section} t='0' a='0' s='0' tr=''/></ctl>"
6188
)
6289
await assert_command(
6390
GetCleanState(),

0 commit comments

Comments
 (0)