Skip to content

Commit f83f36a

Browse files
authored
fix: correct mop intensity code for slider (#777)
1 parent fc7cf75 commit f83f36a

File tree

3 files changed

+78
-12
lines changed

3 files changed

+78
-12
lines changed

roborock/data/v1/v1_clean_modes.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ class WashTowelModes(RoborockModeEnum):
6868
SUPER_DEEP = ("super_deep", 8)
6969

7070

71+
WATER_SLIDE_MODE_MAPPING: dict[int, WaterModes] = {
72+
200: WaterModes.OFF,
73+
221: WaterModes.PURE_WATER_FLOW_START,
74+
225: WaterModes.PURE_WATER_FLOW_SMALL,
75+
235: WaterModes.PURE_WATER_FLOW_MIDDLE,
76+
245: WaterModes.PURE_WATER_FLOW_LARGE,
77+
248: WaterModes.PURE_WATER_SUPER_BEGIN,
78+
250: WaterModes.PURE_WATER_FLOW_END,
79+
}
80+
81+
7182
def get_wash_towel_modes(features: DeviceFeatures) -> list[WashTowelModes]:
7283
"""Get the valid wash towel modes for the device"""
7384
modes = [WashTowelModes.LIGHT, WashTowelModes.BALANCED, WashTowelModes.DEEP]
@@ -128,17 +139,9 @@ def get_clean_routes(features: DeviceFeatures, region: str) -> list[CleanRoutes]
128139

129140
def get_water_modes(features: DeviceFeatures) -> list[WaterModes]:
130141
"""Get the valid water modes for the device - also known as 'water flow' or 'water level'"""
131-
# If the device supports water slide mode, it uses a completely different set of modes. Technically, it can even
132-
# support values in between. But for now we will just support the main values.
142+
# Water slide mode supports a separate set of water flow codes.
133143
if features.is_water_slide_mode_supported:
134-
return [
135-
WaterModes.PURE_WATER_FLOW_START,
136-
WaterModes.PURE_WATER_FLOW_SMALL,
137-
WaterModes.PURE_WATER_FLOW_MIDDLE,
138-
WaterModes.PURE_WATER_FLOW_LARGE,
139-
WaterModes.PURE_WATER_SUPER_BEGIN,
140-
WaterModes.PURE_WATER_FLOW_END,
141-
]
144+
return list(WATER_SLIDE_MODE_MAPPING.values())
142145

143146
supported_modes = [WaterModes.OFF]
144147
if features.is_mop_shake_module_supported:
@@ -159,6 +162,18 @@ def get_water_modes(features: DeviceFeatures) -> list[WaterModes]:
159162
return supported_modes
160163

161164

165+
def get_water_mode_mapping(features: DeviceFeatures) -> dict[int, str]:
166+
"""Get water mode mapping by supported feature set.
167+
168+
WaterModes contains aliases for multiple codes that share the same value
169+
string (e.g. low can be 201 or 225). For water slide mode devices we need
170+
explicit code mapping to preserve those slide-specific codes.
171+
"""
172+
if features.is_water_slide_mode_supported:
173+
return {code: mode.value for code, mode in WATER_SLIDE_MODE_MAPPING.items()}
174+
return {mode.code: mode.value for mode in get_water_modes(features)}
175+
176+
162177
def is_mode_customized(clean_mode: VacuumModes, water_mode: WaterModes, mop_mode: CleanRoutes) -> bool:
163178
"""Check if any of the cleaning modes are set to a custom value."""
164179
return (

roborock/devices/traits/v1/status.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
from functools import cached_property
22
from typing import Self
33

4-
from roborock import CleanRoutes, StatusV2, VacuumModes, WaterModes, get_clean_modes, get_clean_routes, get_water_modes
4+
from roborock import (
5+
CleanRoutes,
6+
StatusV2,
7+
VacuumModes,
8+
WaterModes,
9+
get_clean_modes,
10+
get_clean_routes,
11+
get_water_mode_mapping,
12+
get_water_modes,
13+
)
514
from roborock.roborock_typing import RoborockCommand
615

716
from . import common
@@ -55,7 +64,7 @@ def water_mode_options(self) -> list[WaterModes]:
5564

5665
@cached_property
5766
def water_mode_mapping(self) -> dict[int, str]:
58-
return {mop.code: mop.value for mop in self.water_mode_options}
67+
return get_water_mode_mapping(self._device_features_trait)
5968

6069
@cached_property
6170
def mop_route_options(self) -> list[CleanRoutes]:

tests/devices/traits/v1/test_status.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
"""Tests for the StatusTrait class."""
22

3+
from typing import cast
34
from unittest.mock import AsyncMock
45

56
import pytest
67

8+
from roborock.data import SHORT_MODEL_TO_ENUM
79
from roborock.data.v1 import (
810
RoborockStateCode,
911
)
12+
from roborock.device_features import DeviceFeatures
1013
from roborock.devices.device import RoborockDevice
14+
from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait
1115
from roborock.devices.traits.v1.status import StatusTrait
1216
from roborock.exceptions import RoborockException
1317
from roborock.roborock_typing import RoborockCommand
18+
from tests import mock_data
1419
from tests.mock_data import STATUS
1520

1621

@@ -80,3 +85,40 @@ def test_options(status_trait: StatusTrait) -> None:
8085
assert len(status_trait.water_mode_options) > 0
8186
assert isinstance(status_trait.mop_route_options, list)
8287
assert len(status_trait.mop_route_options) > 0
88+
89+
90+
def test_water_slide_mode_mapping() -> None:
91+
"""Test feature-aware water mode mapping for water slide mode devices."""
92+
short_model = mock_data.A114_PRODUCT_DATA["model"].split(".")[-1]
93+
features = DeviceFeatures.from_feature_flags(
94+
new_feature_info=int(mock_data.SAROS_10R_DEVICE_DATA["featureSet"]),
95+
new_feature_info_str=mock_data.SAROS_10R_DEVICE_DATA["newFeatureSet"],
96+
feature_info=[],
97+
product_nickname=SHORT_MODEL_TO_ENUM[short_model],
98+
)
99+
status_trait = StatusTrait(cast(DeviceFeaturesTrait, features), region="eu")
100+
101+
assert features.is_water_slide_mode_supported
102+
assert status_trait.water_mode_mapping == {
103+
200: "off",
104+
221: "slight",
105+
225: "low",
106+
235: "medium",
107+
245: "moderate",
108+
248: "high",
109+
250: "extreme",
110+
}
111+
assert [mode.value for mode in status_trait.water_mode_options] == [
112+
"off",
113+
"slight",
114+
"low",
115+
"medium",
116+
"moderate",
117+
"high",
118+
"extreme",
119+
]
120+
121+
status_trait.water_box_mode = 225
122+
assert status_trait.water_mode_name == "low"
123+
status_trait.water_box_mode = 200
124+
assert status_trait.water_mode_name == "off"

0 commit comments

Comments
 (0)