Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 6 additions & 1 deletion roborock/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,12 @@ async def q10_empty_dustbin(ctx: click.Context, device_id: str) -> None:

@session.command()
@click.option("--device_id", required=True, help="Device ID")
@click.option("--mode", required=True, type=click.Choice(["bothwork", "onlysweep", "onlymop"]), help="Clean mode")
@click.option(
"--mode",
required=True,
type=click.Choice(["vac_and_mop", "vacuum", "mop", "bothwork", "onlysweep", "onlymop"], case_sensitive=False),
Comment thread
lboue marked this conversation as resolved.
Outdated
help='Clean mode (preferred: "vac_and_mop", "vacuum", "mop")',
)
Comment thread
lboue marked this conversation as resolved.
Comment thread
lboue marked this conversation as resolved.
@click.pass_context
@async_command
async def q10_set_clean_mode(ctx: click.Context, device_id: str, mode: str) -> None:
Expand Down
26 changes: 23 additions & 3 deletions roborock/data/b01_q10/b01_q10_code_mappings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Self

from ..code_mappings import RoborockModeEnum


Expand Down Expand Up @@ -155,11 +157,29 @@ class YXRoomMaterial(RoborockModeEnum):
OTHER = "other", 255


_YX_CLEAN_TYPE_LEGACY_VALUES: dict[str, str] = {
"bothwork": "vac_and_mop",
"onlysweep": "vacuum",
"onlymop": "mop",
}
Comment thread
lboue marked this conversation as resolved.
Outdated


class YXCleanType(RoborockModeEnum):
UNKNOWN = "unknown", -1
BOTH_WORK = "bothwork", 1
ONLY_SWEEP = "onlysweep", 2
ONLY_MOP = "onlymop", 3
VAC_AND_MOP = "vac_and_mop", 1
VACUUM = "vacuum", 2
MOP = "mop", 3

# Legacy aliases
Comment thread
lboue marked this conversation as resolved.
Outdated
BOTH_WORK = VAC_AND_MOP
ONLY_SWEEP = VACUUM
ONLY_MOP = MOP

@classmethod
def from_value(cls, value: str) -> Self:
"""Find enum member by string value with legacy support."""
normalized_value = _YX_CLEAN_TYPE_LEGACY_VALUES.get(value.lower(), value)
return super().from_value(normalized_value)


Comment thread
lboue marked this conversation as resolved.
Comment thread
lboue marked this conversation as resolved.
Comment thread
lboue marked this conversation as resolved.
class YXDeviceState(RoborockModeEnum):
Expand Down
18 changes: 17 additions & 1 deletion tests/data/test_code_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from roborock import HomeDataProduct, RoborockCategory
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP
from roborock.data.b01_q10.b01_q10_code_mappings import B01_Q10_DP, YXCleanType


def test_from_code() -> None:
Expand Down Expand Up @@ -52,6 +52,22 @@ def test_invalid_from_value() -> None:
B01_Q10_DP.from_value("invalid_value")


@pytest.mark.parametrize(
("raw_value", "expected"),
[
("bothwork", YXCleanType.VAC_AND_MOP),
("onlysweep", YXCleanType.VACUUM),
("onlymop", YXCleanType.MOP),
("BothWork", YXCleanType.VAC_AND_MOP),
("ONLYSWEEP", YXCleanType.VACUUM),
("OnlyMop", YXCleanType.MOP),
],
)
def test_yxcleantype_from_value_legacy_aliases(raw_value: str, expected: YXCleanType) -> None:
"""Ensure legacy clean type strings resolve to canonical enum members."""
assert YXCleanType.from_value(raw_value) is expected


@pytest.mark.parametrize(
"input, expected",
[
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/traits/b01/q10/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def vacuumm_fixture(q10_api: Q10PropertiesApi) -> VacuumTrait:
(lambda x: x.stop_clean(), {"206": {}}),
(lambda x: x.return_to_dock(), {"203": {}}),
(lambda x: x.empty_dustbin(), {"203": 2}),
(lambda x: x.set_clean_mode(YXCleanType.BOTH_WORK), {"137": 1}),
(lambda x: x.set_clean_mode(YXCleanType.VAC_AND_MOP), {"137": 1}),
(lambda x: x.set_fan_level(YXFanLevel.BALANCED), {"123": 2}),
Comment thread
lboue marked this conversation as resolved.
],
)
Expand Down
Loading