Skip to content

Commit 7baeb65

Browse files
lboueallenporter
andauthored
Q10: use readable YXCleanType values (vac_and_mop / vacuum / mop) (#794)
* refactor(q10): use readable YXCleanType values with legacy aliases * fix(cli): make clean mode option case insensitive * refactor(YXCleanType): move legacy values to a separate dictionary and update from_value method * test(YXCleanType): add tests for legacy clean type string aliases * refactor(YXCleanType): simplify clean type definitions and remove legacy alias support * test(YXCleanType): add tests for readable public values and compatibility with aliases * test(YXCleanType): add compatibility test for readable values in from_value method * test(q10): update clean type code mapping tests Co-authored-by: Allen Porter <allen.porter@gmail.com> * fix(q10): restrict clean mode cli choices * refactor(YXCleanType): remove legacy test for readable public values * test(YXCleanType): update test for readable values to use canonical names * test(YXCleanType): simplify test for readable values in from_value method --------- Co-authored-by: Allen Porter <allen.porter@gmail.com>
1 parent ad3ceea commit 7baeb65

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

roborock/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,12 @@ async def q10_empty_dustbin(ctx: click.Context, device_id: str) -> None:
12751275

12761276
@session.command()
12771277
@click.option("--device_id", required=True, help="Device ID")
1278-
@click.option("--mode", required=True, type=click.Choice(["bothwork", "onlysweep", "onlymop"]), help="Clean mode")
1278+
@click.option(
1279+
"--mode",
1280+
required=True,
1281+
type=click.Choice(["vac_and_mop", "vacuum", "mop"], case_sensitive=False),
1282+
help='Clean mode (preferred: "vac_and_mop", "vacuum", "mop")',
1283+
)
12791284
@click.pass_context
12801285
@async_command
12811286
async def q10_set_clean_mode(ctx: click.Context, device_id: str, mode: str) -> None:

roborock/data/b01_q10/b01_q10_code_mappings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ class YXRoomMaterial(RoborockModeEnum):
157157

158158
class YXCleanType(RoborockModeEnum):
159159
UNKNOWN = "unknown", -1
160-
BOTH_WORK = "bothwork", 1
161-
ONLY_SWEEP = "onlysweep", 2
162-
ONLY_MOP = "onlymop", 3
160+
VAC_AND_MOP = "vac_and_mop", 1 # bothwork
161+
VACUUM = "vacuum", 2 # onlysweep
162+
MOP = "mop", 3 # onlymop
163163

164164

165165
class YXDeviceState(RoborockModeEnum):

tests/data/test_code_mappings.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from roborock import HomeDataProduct, RoborockCategory
8-
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
8+
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP, YXCleanType
99

1010

1111
def test_from_code() -> None:
@@ -89,3 +89,17 @@ def test_homedata_product_unknown_category():
8989
product = HomeDataProduct.from_dict(data)
9090
assert product.id == "unknown_cat_id"
9191
assert product.category == RoborockCategory.UNKNOWN
92+
93+
94+
@pytest.mark.parametrize(
95+
("readable_value", "expected_clean_type"),
96+
[
97+
("vac_and_mop", YXCleanType.VAC_AND_MOP),
98+
("vacuum", YXCleanType.VACUUM),
99+
("mop", YXCleanType.MOP),
100+
],
101+
)
102+
def test_yx_clean_type_from_value_readable_values(readable_value: str, expected_clean_type: YXCleanType) -> None:
103+
"""Test YXCleanType accepts canonical readable values."""
104+
assert YXCleanType.from_value(readable_value) is expected_clean_type
105+
assert expected_clean_type.value == readable_value

tests/devices/traits/b01/q10/test_vacuum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def vacuumm_fixture(q10_api: Q10PropertiesApi) -> VacuumTrait:
3434
(lambda x: x.stop_clean(), {"206": {}}),
3535
(lambda x: x.return_to_dock(), {"203": {}}),
3636
(lambda x: x.empty_dustbin(), {"203": 2}),
37-
(lambda x: x.set_clean_mode(YXCleanType.BOTH_WORK), {"137": 1}),
37+
(lambda x: x.set_clean_mode(YXCleanType.VAC_AND_MOP), {"137": 1}),
3838
(lambda x: x.set_fan_level(YXFanLevel.BALANCED), {"123": 2}),
3939
],
4040
)

0 commit comments

Comments
 (0)