From 97d9cb367aa26bb3fed2bc85ff6e8b3233da05a5 Mon Sep 17 00:00:00 2001 From: Harry Coureau Date: Sun, 15 Nov 2026 01:38:35 +0000 Subject: [PATCH 1/2] feat(v1): add clean_segments helper to CommandTrait Starting a V1 room clean meant building the app_segment_clean payload by hand, while Q7 and Q10 already expose clean_segments(segment_ids). CommandTrait.clean_segments(segment_ids) sends [{"segments": segment_ids}] and does not set a repeat count. --- roborock/devices/traits/v1/command.py | 7 +++++++ tests/devices/traits/v1/test_command.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/roborock/devices/traits/v1/command.py b/roborock/devices/traits/v1/command.py index 047383540..c5f4dc60b 100644 --- a/roborock/devices/traits/v1/command.py +++ b/roborock/devices/traits/v1/command.py @@ -25,6 +25,13 @@ def __post_init__(self) -> None: """ self._rpc_channel = None + async def clean_segments(self, segment_ids: list[int]) -> None: + """Start cleaning the given segments (rooms) of the current map. + + Segment ids are the `segment_id` values reported by the `rooms` trait. + """ + await self.send(RoborockCommand.APP_SEGMENT_CLEAN, params=[{"segments": segment_ids}]) + async def send(self, command: RoborockCommand | str, params: ParamsType = None) -> Any: """Send a command to the device. diff --git a/tests/devices/traits/v1/test_command.py b/tests/devices/traits/v1/test_command.py index 972f06153..4c10edd3d 100644 --- a/tests/devices/traits/v1/test_command.py +++ b/tests/devices/traits/v1/test_command.py @@ -4,6 +4,7 @@ import pytest +from roborock.devices.device import RoborockDevice from roborock.devices.traits.v1.command import CommandTrait from roborock.exceptions import RoborockException from roborock.roborock_typing import RoborockCommand @@ -59,3 +60,14 @@ async def test_send_command_propagates_exception(command_trait: CommandTrait) -> # Verify the exception is propagated with pytest.raises(RoborockException, match="Communication error"): await command_trait.send(RoborockCommand.APP_START) + + +async def test_clean_segments(device: RoborockDevice, mock_rpc_channel: AsyncMock) -> None: + """Test starting a segment clean.""" + assert device.v1_properties + + await device.v1_properties.command.clean_segments([17, 19]) + + mock_rpc_channel.send_command.assert_called_once_with( + RoborockCommand.APP_SEGMENT_CLEAN, params=[{"segments": [17, 19]}] + ) From 195448b10e64e9236bd71650a71ea75058e4e8e1 Mon Sep 17 00:00:00 2001 From: Harry Coureau <183213654+hCoureau@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:22:40 +0000 Subject: [PATCH 2/2] refactor: move clean_segments to RoomsTrait CommandTrait is meant to only expose the low-level send command. Co-Authored-By: Claude Opus 5.5 --- roborock/devices/traits/v1/command.py | 7 ------- roborock/devices/traits/v1/rooms.py | 7 +++++++ tests/devices/traits/v1/test_command.py | 12 ------------ tests/devices/traits/v1/test_rooms.py | 9 +++++++++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/roborock/devices/traits/v1/command.py b/roborock/devices/traits/v1/command.py index c5f4dc60b..047383540 100644 --- a/roborock/devices/traits/v1/command.py +++ b/roborock/devices/traits/v1/command.py @@ -25,13 +25,6 @@ def __post_init__(self) -> None: """ self._rpc_channel = None - async def clean_segments(self, segment_ids: list[int]) -> None: - """Start cleaning the given segments (rooms) of the current map. - - Segment ids are the `segment_id` values reported by the `rooms` trait. - """ - await self.send(RoborockCommand.APP_SEGMENT_CLEAN, params=[{"segments": segment_ids}]) - async def send(self, command: RoborockCommand | str, params: ParamsType = None) -> Any: """Send a command to the device. diff --git a/roborock/devices/traits/v1/rooms.py b/roborock/devices/traits/v1/rooms.py index 021373dce..c699d6f14 100644 --- a/roborock/devices/traits/v1/rooms.py +++ b/roborock/devices/traits/v1/rooms.py @@ -135,6 +135,13 @@ async def refresh(self) -> None: rooms = rooms.with_room_names(self._room_name_map) common.merge_trait_values(self, rooms) + async def clean_segments(self, segment_ids: list[int]) -> None: + """Start cleaning the given segments (rooms) of the current map. + + Segment ids are the `segment_id` values in `rooms`. + """ + await self.rpc_channel.send_command(RoborockCommand.APP_SEGMENT_CLEAN, params=[{"segments": segment_ids}]) + async def _refresh_rooms(self) -> list[HomeDataRoom]: """Fetch the latest rooms from the web API.""" try: diff --git a/tests/devices/traits/v1/test_command.py b/tests/devices/traits/v1/test_command.py index 4c10edd3d..972f06153 100644 --- a/tests/devices/traits/v1/test_command.py +++ b/tests/devices/traits/v1/test_command.py @@ -4,7 +4,6 @@ import pytest -from roborock.devices.device import RoborockDevice from roborock.devices.traits.v1.command import CommandTrait from roborock.exceptions import RoborockException from roborock.roborock_typing import RoborockCommand @@ -60,14 +59,3 @@ async def test_send_command_propagates_exception(command_trait: CommandTrait) -> # Verify the exception is propagated with pytest.raises(RoborockException, match="Communication error"): await command_trait.send(RoborockCommand.APP_START) - - -async def test_clean_segments(device: RoborockDevice, mock_rpc_channel: AsyncMock) -> None: - """Test starting a segment clean.""" - assert device.v1_properties - - await device.v1_properties.command.clean_segments([17, 19]) - - mock_rpc_channel.send_command.assert_called_once_with( - RoborockCommand.APP_SEGMENT_CLEAN, params=[{"segments": [17, 19]}] - ) diff --git a/tests/devices/traits/v1/test_rooms.py b/tests/devices/traits/v1/test_rooms.py index 9e6d720fa..f0e4442ca 100644 --- a/tests/devices/traits/v1/test_rooms.py +++ b/tests/devices/traits/v1/test_rooms.py @@ -234,3 +234,12 @@ async def test_refresh_shared_room_names_use_shared_device_rooms( ] web_api_client.get_shared_device_rooms.assert_called_once_with(rooms_trait._device_uid) web_api_client.get_rooms.assert_not_called() + + +async def test_clean_segments(rooms_trait: RoomsTrait, mock_rpc_channel: AsyncMock) -> None: + """Test starting a segment clean.""" + await rooms_trait.clean_segments([17, 19]) + + mock_rpc_channel.send_command.assert_called_once_with( + RoborockCommand.APP_SEGMENT_CLEAN, params=[{"segments": [17, 19]}] + )