-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathtest_wash_towel_mode.py
More file actions
200 lines (170 loc) · 5.49 KB
/
test_wash_towel_mode.py
File metadata and controls
200 lines (170 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
"""Tests for the WashTowelModeTrait class."""
from unittest.mock import AsyncMock, call
import pytest
from roborock.data import (
RoborockDockTypeCode,
WashTowelModes,
)
from roborock.devices.device import RoborockDevice
from roborock.devices.traits.v1.wash_towel_mode import WashTowelModeTrait
from roborock.roborock_typing import RoborockCommand
WASH_TOWEL_MODE_DATA = {"wash_mode": WashTowelModes.SMART.code}
@pytest.fixture(name="wash_towel_mode")
def wash_towel_mode_trait(
device: RoborockDevice,
discover_features_fixture: None,
) -> WashTowelModeTrait | None:
"""Create a WashTowelModeTrait instance with mocked dependencies."""
assert device.v1_properties
return device.v1_properties.wash_towel_mode
@pytest.mark.parametrize(
("dock_type_code"),
[
(RoborockDockTypeCode.s8_dock),
(RoborockDockTypeCode.p10_dock),
(RoborockDockTypeCode.qrevo_s_dock),
],
)
async def test_wash_towel_mode_available(
wash_towel_mode: WashTowelModeTrait | None,
mock_rpc_channel: AsyncMock,
dock_type_code: RoborockDockTypeCode,
) -> None:
"""Test successfully refreshing the wash towel mode."""
assert wash_towel_mode is not None
mock_rpc_channel.send_command.side_effect = [
WASH_TOWEL_MODE_DATA,
]
await wash_towel_mode.refresh()
mock_rpc_channel.send_command.assert_has_calls(
[
call(RoborockCommand.GET_WASH_TOWEL_MODE),
]
)
assert wash_towel_mode.wash_mode == WashTowelModes.SMART
@pytest.mark.parametrize(
("dock_type_code"),
[
(RoborockDockTypeCode.s7_max_ultra_dock),
(RoborockDockTypeCode.no_dock),
],
)
async def test_unsupported_wash_towel_mode(
wash_towel_mode: WashTowelModeTrait | None, dock_type_code: RoborockDockTypeCode
) -> None:
"""Test that the trait is not available for unsupported dock types."""
assert wash_towel_mode is None
@pytest.mark.parametrize(
("dock_type_code"),
[(RoborockDockTypeCode.s8_dock)],
)
@pytest.mark.parametrize(
("wash_mode"),
[
(WashTowelModes.SMART),
(WashTowelModes.LIGHT),
],
)
async def test_set_wash_towel_mode(
wash_towel_mode: WashTowelModeTrait | None,
mock_rpc_channel: AsyncMock,
wash_mode: WashTowelModes,
dock_type_code: RoborockDockTypeCode,
) -> None:
"""Test setting the wash towel mode."""
assert wash_towel_mode is not None
await wash_towel_mode.set_wash_towel_mode(wash_mode)
mock_rpc_channel.send_command.assert_called_with(
RoborockCommand.SET_WASH_TOWEL_MODE, params={"wash_mode": wash_mode.code}
)
@pytest.mark.parametrize(
("dock_type_code"),
[(RoborockDockTypeCode.s8_dock)],
)
async def test_start_wash(
wash_towel_mode: WashTowelModeTrait | None,
mock_rpc_channel: AsyncMock,
dock_type_code: RoborockDockTypeCode,
) -> None:
"""Test starting the wash."""
assert wash_towel_mode is not None
await wash_towel_mode.start_wash()
mock_rpc_channel.send_command.assert_called_with(RoborockCommand.APP_START_WASH)
@pytest.mark.parametrize(
("dock_type_code"),
[(RoborockDockTypeCode.s8_dock)],
)
async def test_stop_wash(
wash_towel_mode: WashTowelModeTrait | None,
mock_rpc_channel: AsyncMock,
dock_type_code: RoborockDockTypeCode,
) -> None:
"""Test stopping the wash."""
assert wash_towel_mode is not None
await wash_towel_mode.stop_wash()
mock_rpc_channel.send_command.assert_called_with(RoborockCommand.APP_STOP_WASH)
@pytest.mark.parametrize(
("dock_type_code"),
[(RoborockDockTypeCode.s8_dock)],
)
@pytest.mark.parametrize(
(
"is_super_deep_wash_supported",
"is_dirty_replenish_clean_supported",
"expected_modes",
),
[
(
False,
False,
[WashTowelModes.LIGHT, WashTowelModes.BALANCED, WashTowelModes.DEEP],
),
(
True,
False,
[
WashTowelModes.LIGHT,
WashTowelModes.BALANCED,
WashTowelModes.DEEP,
WashTowelModes.SUPER_DEEP,
],
),
(
False,
True,
[
WashTowelModes.LIGHT,
WashTowelModes.BALANCED,
WashTowelModes.DEEP,
WashTowelModes.SMART,
],
),
(
True,
True,
[
WashTowelModes.LIGHT,
WashTowelModes.BALANCED,
WashTowelModes.DEEP,
WashTowelModes.SMART,
],
),
],
)
async def test_wash_towel_mode_options(
wash_towel_mode: WashTowelModeTrait | None,
dock_type_code: RoborockDockTypeCode,
is_super_deep_wash_supported: bool,
is_dirty_replenish_clean_supported: bool,
expected_modes: list[WashTowelModes],
) -> None:
"""Test what modes are available based on device features."""
assert wash_towel_mode is not None
# We need to clear the cached property to ensure it re-reads the features
if "wash_towel_mode_options" in wash_towel_mode.__dict__:
del wash_towel_mode.__dict__["wash_towel_mode_options"]
# Mock the device features
assert wash_towel_mode.device_feature_trait is not None
wash_towel_mode.device_feature_trait.is_super_deep_wash_supported = is_super_deep_wash_supported
wash_towel_mode.device_feature_trait.is_dirty_replenish_clean_supported = is_dirty_replenish_clean_supported
assert wash_towel_mode.wash_towel_mode_options == expected_modes