Skip to content

Commit a853a75

Browse files
committed
Add missing test cases
1 parent fc63dfc commit a853a75

2 files changed

Lines changed: 56 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: 54 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,64 @@ 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+
),
75+
(
76+
FanSpeedLevel.MAX,
77+
None,
78+
FanSpeedEvent(FanSpeedLevel.MAX),
79+
None,
80+
),
81+
],
82+
ids=[
83+
"standard_cleaning",
84+
"strong_cleaning",
85+
"paused",
86+
"resume/idle",
87+
"stop/idle",
88+
"fanspeed_only",
5089
],
51-
ids=["standard_cleaning", "strong_cleaning", "paused"],
5290
)
5391
async def test_get_clean_state(
54-
speed: str,
55-
state: str,
92+
speed: FanSpeedLevel | None,
93+
action: CleanAction | None,
5694
expected_fan_speed_event: FanSpeedEvent,
5795
expected_state_event: StateEvent,
5896
) -> None:
97+
speed_section = f"speed='{speed.xml_value}'" if speed is not None else ""
98+
state_section = f"st='{action.xml_value}'" if action is not None else ""
5999
json = get_request_xml(
60-
f"<ctl ret='ok'><clean type='auto' speed='{speed}' st='{state}' t='0' a='0' s='0' tr=''/></ctl>"
100+
f"<ctl ret='ok'><clean type='auto' {speed_section} {state_section} t='0' a='0' s='0' tr=''/></ctl>"
61101
)
62102
await assert_command(
63103
GetCleanState(),

0 commit comments

Comments
 (0)