Skip to content

Commit 1c68fea

Browse files
committed
feat(v1): set the carpet mode
1 parent af8ff47 commit 1c68fea

5 files changed

Lines changed: 209 additions & 13 deletions

File tree

‎docs/V1_API_COMMANDS.md‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,54 @@ Return example:
721721

722722
Source: Roborock S7 MaxV Ultra
723723

724+
**Supported devices:**
725+
726+
* Roborock Saros 10R: ✅
724727

725728
### set_carpet_clean_mode
726729

727-
Description:
730+
Description: Set carpet clean mode. The app sends it as an object, not a list.
731+
732+
Parameters:
733+
734+
carpet_clean_mode: 0 avoid, 1 self adaption, 2 vacuum and mop, 3 dynamic adaption. The app writes 3 for
735+
"vacuum only" when the robot supports dynamic adaption, else 1.
736+
737+
Cross carpet is a separate flag, set with [app_set_cross_carpet_cleaning_status](#app_set_cross_carpet_cleaning_status).
738+
Write test on Roborock Saros 10R (2026-11-24): setting 0 (avoid) or 2 (vacuum and mop) clears the cross flag by
739+
itself. Setting 3 does not clear it, so cross stays on and must be turned off with
740+
`app_set_cross_carpet_cleaning_status` status 0 (only on robots that support custom carpet clean). Setting 0 left
741+
carpet boost and carpet deep clean unchanged.
742+
743+
Parameter example:
744+
745+
```json
746+
{"carpet_clean_mode": 3}
747+
```
748+
749+
**Supported devices:**
750+
751+
* Roborock Saros 10R: ✅
752+
753+
### app_set_cross_carpet_cleaning_status
754+
755+
Description: Turn the cross carpet mode on or off. It is read back from the 0x20 bit of `switch_status` in
756+
[get_prop](#get_prop).
728757

729758
Parameters:
730759

760+
status: 1 on, 0 off.
761+
762+
Parameter example:
763+
764+
```json
765+
{"status": 1}
766+
```
767+
768+
**Supported devices:**
769+
770+
* Roborock Saros 10R: ✅
771+
731772
### get_carpet_mode
732773

733774
Description:
@@ -1574,7 +1615,7 @@ Example:
15741615
Comment : This example returns the same as get_status. Initial testing has shown that not all get commands are supported by this method
15751616

15761617
With `["get_status"]` it returns the status plus `switch_status`, which plain `get_status` lacks. Bit 0x08 is
1577-
carpet first and 0x20 is cross carpet.
1618+
carpet first and 0x20 is cross carpet. Also seen on Roborock Saros 10R.
15781619

15791620

15801621
### get_turn_server

‎roborock/devices/traits/v1/carpet_clean_mode.py‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from roborock.data.v1 import CarpetCleanMode, CarpetMode, SwitchStatus
88
from roborock.devices.traits.v1 import common
99
from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait
10-
from roborock.exceptions import RoborockException, RoborockParsingException
10+
from roborock.exceptions import RoborockException, RoborockParsingException, RoborockUnsupportedFeature
1111
from roborock.roborock_typing import RoborockCommand
1212

1313
_LOGGER = logging.getLogger(__name__)
@@ -23,7 +23,7 @@ class CarpetCleanModeState(RoborockBase):
2323

2424

2525
class CarpetCleanModeTrait(CarpetCleanModeState, common.V1TraitMixin):
26-
"""Trait for reading how the robot treats carpets."""
26+
"""Trait for reading and setting the carpet clean mode."""
2727

2828
command = RoborockCommand.GET_CARPET_CLEAN_MODE
2929
requires_feature = "is_carpet_clean_mode_supported"
@@ -79,3 +79,39 @@ async def refresh(self) -> None:
7979
return
8080
self.carpet_first = switch_status.carpet_first
8181
self.cross_carpet = switch_status.cross_carpet
82+
83+
async def set_mode(self, mode: CarpetMode) -> None:
84+
"""Set the carpet mode and refresh the state.
85+
86+
Only the mode and the cross flag are written; carpet boost and deep clean are left as they are.
87+
Raises RoborockUnsupportedFeature if the robot does not offer the mode.
88+
"""
89+
if mode not in self.options:
90+
raise RoborockUnsupportedFeature(f"Carpet mode {mode} is not supported by this device")
91+
features = self._device_features
92+
if mode is CarpetMode.CROSS:
93+
await self._set_cross(True)
94+
elif mode is CarpetMode.VACUUM_ONLY:
95+
adaption = (
96+
CarpetCleanMode.dynamic_adaption
97+
if features.is_dynamic_adaption_carpet_supported
98+
else CarpetCleanMode.self_adaption
99+
)
100+
await self._set_clean_mode(adaption)
101+
# Mode 3 leaves cross on (Saros 10R), so clear it.
102+
if features.is_carpet_custom_clean_supported:
103+
await self._set_cross(False)
104+
else:
105+
clean_mode = CarpetCleanMode.avoid if mode is CarpetMode.AVOID else CarpetCleanMode.vac_and_mop
106+
await self._set_clean_mode(clean_mode)
107+
await self.refresh()
108+
109+
async def _set_clean_mode(self, clean_mode: CarpetCleanMode) -> None:
110+
await self.rpc_channel.send_command(
111+
RoborockCommand.SET_CARPET_CLEAN_MODE, params={"carpet_clean_mode": clean_mode.value}
112+
)
113+
114+
async def _set_cross(self, enabled: bool) -> None:
115+
await self.rpc_channel.send_command(
116+
RoborockCommand.APP_SET_CROSS_CARPET_CLEANING_STATUS, params={"status": int(enabled)}
117+
)

‎roborock/testing/v1_simulator.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ def _handle_set_water_box_custom_mode(self, params: Any) -> str:
350350
return "ok"
351351

352352
def _handle_set_carpet_clean_mode(self, params: Any) -> str:
353-
self.carpet_clean_mode = params[0]
354-
# The robot drops cross-carpet when the clean mode is set to avoid
355-
if self.carpet_clean_mode == 0:
353+
self.carpet_clean_mode = params["carpet_clean_mode"]
354+
# The robot drops cross-carpet on avoid and vac & mop (Saros 10R)
355+
if self.carpet_clean_mode in (0, 2):
356356
self.switch_status &= ~_SWITCH_CROSS_CARPET
357357
return "ok"
358358

‎tests/devices/traits/v1/test_carpet_clean_mode.py‎

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55

66
import pytest
77

8-
from roborock.data import HomeDataDevice, HomeDataProduct
8+
from roborock.data import HomeDataDevice, HomeDataProduct, UserData
99
from roborock.data.v1 import CarpetCleanMode, CarpetMode
10+
from roborock.devices.cache import InMemoryCache
1011
from roborock.devices.device import RoborockDevice
12+
from roborock.devices.device_manager import UserParams, create_device_manager
1113
from roborock.devices.traits.v1.carpet_clean_mode import CarpetCleanModeTrait
12-
from roborock.exceptions import RoborockTimeout
14+
from roborock.exceptions import RoborockTimeout, RoborockUnsupportedFeature
1315
from roborock.roborock_typing import RoborockCommand
16+
from roborock.testing import DEFAULT_APP_INIT, FakeRoborockCloud, V1VacuumSimulator
1417
from tests import mock_data
1518

1619
SAROS_10R, SAROS_10R_PRODUCT = mock_data.DEVICE_PRODUCT_PAIRS["home_data_device_saros_10r.json"]
1720
S5E = mock_data.DEVICE_PRODUCT_PAIRS["home_data_device_s5e.json"][0]
21+
SAROS_FEATURE_STR = SAROS_10R.new_feature_set or ""
1822

1923

2024
@pytest.fixture(name="device_info")
@@ -139,3 +143,118 @@ async def test_trait_absent_on_tanos_s_lite_in_us(
139143
assert device.v1_properties
140144
assert device.v1_properties.device_features.is_carpet_supported
141145
assert carpet_clean_mode_trait is None
146+
147+
148+
def _answer_reads(rpc: AsyncMock) -> None:
149+
"""Answer the refresh reads and accept every write."""
150+
151+
async def send_command(command: RoborockCommand, params: object = None) -> object:
152+
if command is RoborockCommand.GET_CARPET_CLEAN_MODE:
153+
return [{"carpet_clean_mode": 3}]
154+
if command is RoborockCommand.GET_PROP:
155+
return [{"switch_status": 0}]
156+
return "ok"
157+
158+
rpc.send_command.side_effect = send_command
159+
160+
161+
_SET_MODE = RoborockCommand.SET_CARPET_CLEAN_MODE
162+
_SET_CROSS = RoborockCommand.APP_SET_CROSS_CARPET_CLEANING_STATUS
163+
164+
165+
@pytest.mark.parametrize(
166+
("mode", "features", "expected"),
167+
[
168+
(CarpetMode.AVOID, {}, [call(_SET_MODE, params={"carpet_clean_mode": 0})]),
169+
(CarpetMode.VAC_AND_MOP, {}, [call(_SET_MODE, params={"carpet_clean_mode": 2})]),
170+
(
171+
CarpetMode.VACUUM_ONLY,
172+
{"is_dynamic_adaption_carpet_supported": True},
173+
[call(_SET_MODE, params={"carpet_clean_mode": 3}), call(_SET_CROSS, params={"status": 0})],
174+
),
175+
(
176+
CarpetMode.VACUUM_ONLY,
177+
{"is_dynamic_adaption_carpet_supported": False, "is_self_adaption_carpet_supported": True},
178+
[call(_SET_MODE, params={"carpet_clean_mode": 1}), call(_SET_CROSS, params={"status": 0})],
179+
),
180+
(
181+
CarpetMode.VACUUM_ONLY,
182+
{"is_carpet_custom_clean_supported": False},
183+
[call(_SET_MODE, params={"carpet_clean_mode": 1})],
184+
),
185+
(CarpetMode.CROSS, {}, [call(_SET_CROSS, params={"status": 1})]),
186+
],
187+
ids=["avoid", "vac_and_mop", "vacuum_only_dynamic", "vacuum_only_self", "vacuum_only_no_custom_clean", "cross"],
188+
)
189+
async def test_set_mode_sends_commands(
190+
carpet_clean_mode_trait: CarpetCleanModeTrait | None,
191+
mock_rpc_channel: AsyncMock,
192+
device: RoborockDevice,
193+
mode: CarpetMode,
194+
features: dict[str, bool],
195+
expected: list,
196+
) -> None:
197+
"""Each mode sends exactly its own writes, then refreshes."""
198+
assert carpet_clean_mode_trait is not None
199+
assert device.v1_properties
200+
for name, value in features.items():
201+
setattr(device.v1_properties.device_features, name, value)
202+
_answer_reads(mock_rpc_channel)
203+
204+
await carpet_clean_mode_trait.set_mode(mode)
205+
206+
assert mock_rpc_channel.send_command.call_args_list == [
207+
*expected,
208+
call(RoborockCommand.GET_CARPET_CLEAN_MODE),
209+
call(RoborockCommand.GET_PROP, params=["get_status"]),
210+
]
211+
212+
213+
async def test_set_unoffered_mode_raises_and_sends_nothing(
214+
carpet_clean_mode_trait: CarpetCleanModeTrait | None, mock_rpc_channel: AsyncMock, device: RoborockDevice
215+
) -> None:
216+
assert carpet_clean_mode_trait is not None
217+
assert device.v1_properties
218+
device.v1_properties.device_features.is_carpet_custom_clean_supported = False
219+
220+
with pytest.raises(RoborockUnsupportedFeature):
221+
await carpet_clean_mode_trait.set_mode(CarpetMode.CROSS)
222+
223+
mock_rpc_channel.send_command.assert_not_called()
224+
225+
226+
async def test_set_mode_round_trip_with_simulator() -> None:
227+
"""Writes land in the simulator and the refreshed trait reports them, including cross clearing."""
228+
sim = V1VacuumSimulator(
229+
duid="saros_carpet",
230+
app_init=replace(
231+
DEFAULT_APP_INIT, new_feature_info_str=SAROS_FEATURE_STR, new_feature_info=int(SAROS_FEATURE_STR, 16)
232+
),
233+
)
234+
cloud = FakeRoborockCloud()
235+
cloud.add_device(sim)
236+
with cloud.patch_device_manager():
237+
manager = await create_device_manager(
238+
user_params=UserParams(username="test_user", user_data=UserData.from_dict(mock_data.USER_DATA)),
239+
cache=InMemoryCache(),
240+
)
241+
device = (await manager.get_devices())[0]
242+
assert device.v1_properties
243+
trait = device.v1_properties.carpet_clean_mode
244+
assert trait is not None
245+
246+
await trait.set_mode(CarpetMode.CROSS)
247+
assert trait.mode is CarpetMode.CROSS
248+
249+
await trait.set_mode(CarpetMode.VACUUM_ONLY)
250+
assert trait.mode is CarpetMode.VACUUM_ONLY
251+
assert trait.cross_carpet is False
252+
253+
await trait.set_mode(CarpetMode.CROSS)
254+
await trait.set_mode(CarpetMode.AVOID)
255+
assert trait.mode is CarpetMode.AVOID
256+
assert trait.cross_carpet is False
257+
258+
await trait.set_mode(CarpetMode.CROSS)
259+
await trait.set_mode(CarpetMode.VAC_AND_MOP)
260+
assert trait.mode is CarpetMode.VAC_AND_MOP

‎tests/testing/test_v1_simulator.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,15 @@ async def test_simulator_carpet_commands() -> None:
428428

429429
assert await send("get_carpet_clean_mode") == [{"carpet_clean_mode": 0}]
430430

431-
await send("set_carpet_clean_mode", [3])
431+
await send("set_carpet_clean_mode", {"carpet_clean_mode": 3})
432432
await send("app_set_cross_carpet_cleaning_status", {"status": 1})
433433
assert await send("get_carpet_clean_mode") == [{"carpet_clean_mode": 3}]
434434
assert (await send("get_prop", ["get_status"]))[0]["switch_status"] == 0x20
435435

436-
# Like the robot, choosing the avoid mode drops the cross flag
437-
await send("set_carpet_clean_mode", [0])
436+
# Like the robot, choosing the avoid or vac & mop mode drops the cross flag
437+
await send("set_carpet_clean_mode", {"carpet_clean_mode": 0})
438438
assert sim.switch_status == 0
439439

440440
await send("app_set_cross_carpet_cleaning_status", {"status": 1})
441-
await send("app_set_cross_carpet_cleaning_status", {"status": 0})
441+
await send("set_carpet_clean_mode", {"carpet_clean_mode": 2})
442442
assert sim.switch_status == 0

0 commit comments

Comments
 (0)