Skip to content

Commit 76cfa08

Browse files
committed
feat(v1): set the carpet mode
1 parent 8582d03 commit 76cfa08

5 files changed

Lines changed: 207 additions & 12 deletions

File tree

‎docs/V1_API_COMMANDS.md‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,53 @@ 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. The app sends `app_set_cross_carpet_cleaning_status` with
740+
status 0 after a vacuum only value (1 or 3) when the robot supports custom carpet clean, and sends nothing after 0 and 2.
741+
742+
Parameter example:
743+
744+
```json
745+
{"carpet_clean_mode": 3}
746+
```
747+
748+
**Supported devices:**
749+
750+
* Roborock Saros 10R: ✅
751+
752+
### app_set_cross_carpet_cleaning_status
753+
754+
Description: Turn the cross carpet mode on or off. It is read back from the 0x20 bit of `switch_status` in
755+
[get_prop](#get_prop).
728756

729757
Parameters:
730758

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

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

15761616
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.
1617+
carpet first and 0x20 is cross carpet. Also seen on Roborock Saros 10R.
15781618

15791619

15801620
### get_turn_server

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

Lines changed: 36 additions & 1 deletion
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__)
@@ -79,3 +79,38 @@ 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+
Raises RoborockUnsupportedFeature if the robot does not offer the mode.
87+
"""
88+
if mode not in self.options:
89+
raise RoborockUnsupportedFeature(f"Carpet mode {mode} is not supported by this device")
90+
features = self._device_features
91+
if mode is CarpetMode.CROSS:
92+
await self._set_cross(True)
93+
elif mode is CarpetMode.VACUUM_ONLY:
94+
adaption = (
95+
CarpetCleanMode.dynamic_adaption
96+
if features.is_dynamic_adaption_carpet_supported
97+
else CarpetCleanMode.self_adaption
98+
)
99+
await self._set_clean_mode(adaption)
100+
# Mode 3 leaves cross on (Saros 10R), so clear it.
101+
if features.is_carpet_custom_clean_supported:
102+
await self._set_cross(False)
103+
else:
104+
clean_mode = CarpetCleanMode.avoid if mode is CarpetMode.AVOID else CarpetCleanMode.vac_and_mop
105+
await self._set_clean_mode(clean_mode)
106+
await self.refresh()
107+
108+
async def _set_clean_mode(self, clean_mode: CarpetCleanMode) -> None:
109+
await self.rpc_channel.send_command(
110+
RoborockCommand.SET_CARPET_CLEAN_MODE, params={"carpet_clean_mode": clean_mode.value}
111+
)
112+
113+
async def _set_cross(self, enabled: bool) -> None:
114+
await self.rpc_channel.send_command(
115+
RoborockCommand.APP_SET_CROSS_CARPET_CLEANING_STATUS, params={"status": int(enabled)}
116+
)

‎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_mode.py‎

Lines changed: 122 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
"""Tests for the CarpetModeTrait class."""
22

3+
from dataclasses import replace
34
from unittest.mock import AsyncMock, call
45

56
import pytest
67

7-
from roborock.data import HomeDataDevice
8+
from roborock.data import HomeDataDevice, UserData
89
from roborock.data.v1 import CarpetCleanMode, CarpetMode
10+
from roborock.devices.cache import InMemoryCache
911
from roborock.devices.device import RoborockDevice
12+
from roborock.devices.device_manager import UserParams, create_device_manager
1013
from roborock.devices.traits.v1.carpet_mode import CarpetModeTrait
11-
from roborock.exceptions import RoborockTimeout
14+
from roborock.exceptions import RoborockTimeout, RoborockUnsupportedFeature
1215
from roborock.roborock_typing import RoborockCommand
16+
from roborock.testing import DEFAULT_APP_INIT, FakeRoborockCloud, V1VacuumSimulator
1317
from tests import mock_data
1418

1519
SAROS_10R = mock_data.DEVICE_PRODUCT_PAIRS["home_data_device_saros_10r.json"][0]
1620
S5E = mock_data.DEVICE_PRODUCT_PAIRS["home_data_device_s5e.json"][0]
21+
SAROS_FEATURE_STR = SAROS_10R.new_feature_set or ""
1722

1823

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