From 94c2ce7e8d24116653503e977f5308d1afc084d6 Mon Sep 17 00:00:00 2001 From: infy1995 Date: Thu, 12 Nov 2026 21:30:18 +0100 Subject: [PATCH 1/4] feat: add V1 wash water temperature trait Expose the temperature the dock washes the mop with, so consumers can read and set it. Add RoborockDockWashWaterTemperatureCode and WashWaterTemperatureTrait; writes use the "values" key because the device rejects "wash_water_temperature". The trait is created only for washing docks on robots that support hot mop washing, and not on Shell E docks or, without a Shell2E Lite dock, on the PearlE Pro, which cannot heat the water. --- docs/V1_API_COMMANDS.md | 50 +++ docs/V1_DEVICE_FEATURES.md | 2 +- roborock/data/v1/v1_code_mappings.py | 11 + roborock/data/v1/v1_containers.py | 8 + roborock/devices/traits/v1/__init__.py | 24 +- .../traits/v1/wash_water_temperature.py | 82 +++++ tests/devices/traits/v1/fixtures.py | 20 +- tests/devices/traits/v1/helpers.py | 17 +- .../traits/v1/test_wash_water_temperature.py | 297 ++++++++++++++++++ 9 files changed, 505 insertions(+), 6 deletions(-) create mode 100644 roborock/devices/traits/v1/wash_water_temperature.py create mode 100644 tests/devices/traits/v1/test_wash_water_temperature.py diff --git a/docs/V1_API_COMMANDS.md b/docs/V1_API_COMMANDS.md index d4d286d84..0f7fb1f94 100644 --- a/docs/V1_API_COMMANDS.md +++ b/docs/V1_API_COMMANDS.md @@ -56,6 +56,7 @@ Commands can have multiple parameters that can change from one model to another. * [get_turn_server](#get_turn_server) * [get_valley_electricity_timer](#get_valley_electricity_timer) * [get_wash_towel_mode](#get_wash_towel_mode) +* [get_wash_water_temperature](#get_wash_water_temperature) * [load_multi_map](#load_multi_map) * [manual_bak_map](#manual_bak_map) * [name_segment](#name_segment) @@ -88,6 +89,7 @@ Commands can have multiple parameters that can change from one model to another. * [set_timezone](#set_timezone) * [set_valley_electricity_timer](#set_valley_electricity_timer) * [set_wash_towel_mode](#set_wash_towel_mode) +* [set_wash_water_temperature](#set_wash_water_temperature) * [set_water_box_custom_mode](#set_water_box_custom_mode) * [start_camera_preview](#start_camera_preview) * [start_edit_map](#start_edit_map) @@ -1505,6 +1507,54 @@ Source: S8 Pro Ultra * Roborock S7 MaxV Ultra: ✅ * Roborock S8 Pro Ultra: ✅ +### get_wash_water_temperature + +Description: Get the water temperature the dock uses to wash the mop (app: water temperature). Available on +washing docks of devices with the hot wash towel feature (`is_hot_wash_towel_supported`). Not available on a +Shell E dock (dock type 21, also Shell EA), which cannot heat wash water, nor on the PearlE Pro (a169/a170) unless +the dock is a Shell2E Lite. + +Parameters: None + +Returns: + + wash_water_temperature: 0 room temperature, 1 warm, 2 hot, 3 steam, 4 pet steam. + Docks offer 0 and 2; 1 only on docks with neither high temperature water nor steam; 3 only on steam docks. + +Return example: + +```json + {'wash_water_temperature': 2} +``` + +Source: Roborock Saros 10R + +**Supported devices:** + +* Roborock Saros 10R: ✅ + +### set_wash_water_temperature + +Description: Set the water temperature the dock uses to wash the mop. + +Parameters: + + values: 0 room temperature, 1 warm, 2 hot, 3 steam, 4 pet steam. + The key differs from the one `get_wash_water_temperature` returns; `{'wash_water_temperature': 2}` is + rejected with -10007 invalid params. + +Example: + +```json + {'values': 2} +``` + +Source: Roborock Saros 10R + +**Supported devices:** + +* Roborock Saros 10R: ✅ + ### get_collision_avoid_status Description: diff --git a/docs/V1_DEVICE_FEATURES.md b/docs/V1_DEVICE_FEATURES.md index 9101d8221..b12db1441 100644 --- a/docs/V1_DEVICE_FEATURES.md +++ b/docs/V1_DEVICE_FEATURES.md @@ -684,7 +684,7 @@ These features are encoded as individual bits in the `new_feature_info_str` hex **Bit Index:** 41 **Feature:** Hot Water Mop Washing **Description:** Dock uses hot water to wash mop pads. The robot firmware reports this, so it does not account for the dock: a Shell E dock cannot wash with hot water. -**Impact:** Better mop cleaning and sanitization. +**Impact:** Better mop cleaning and sanitization. Required for `WashWaterTemperatureTrait`. --- diff --git a/roborock/data/v1/v1_code_mappings.py b/roborock/data/v1/v1_code_mappings.py index befc67a08..da2d3f7e9 100644 --- a/roborock/data/v1/v1_code_mappings.py +++ b/roborock/data/v1/v1_code_mappings.py @@ -444,6 +444,17 @@ class RoborockDockDustCollectionFrequencyCode(RoborockEnum): high = 2 +class RoborockDockWashWaterTemperatureCode(RoborockEnum): + """Describes the water temperature the dock uses to wash the mop (app: water temperature).""" + + unknown = -1 + room_temperature = 0 + warm = 1 + hot = 2 + steam = 3 + pet_steam = 4 + + class RoborockStateCode(RoborockEnum): unknown = 0 starting = 1 diff --git a/roborock/data/v1/v1_containers.py b/roborock/data/v1/v1_containers.py index 5a76a3676..16592625e 100644 --- a/roborock/data/v1/v1_containers.py +++ b/roborock/data/v1/v1_containers.py @@ -32,6 +32,7 @@ RoborockDockErrorCode, RoborockDockState, RoborockDockTypeCode, + RoborockDockWashWaterTemperatureCode, RoborockErrorCode, RoborockFinishReason, RoborockInCleaning, @@ -489,6 +490,13 @@ class SmartWashParams(RoborockBase): wash_interval: int | None = None +@dataclass +class WashWaterTemperature(RoborockBase): + """Mop wash water temperature, as returned by GET_WASH_WATER_TEMPERATURE.""" + + wash_water_temperature: RoborockDockWashWaterTemperatureCode | None = None + + @dataclass class MopDryerProfile(RoborockBase): """Dryer parameters for one state of the auto mop-drying setting.""" diff --git a/roborock/devices/traits/v1/__init__.py b/roborock/devices/traits/v1/__init__.py index d53db961c..4dae49860 100644 --- a/roborock/devices/traits/v1/__init__.py +++ b/roborock/devices/traits/v1/__init__.py @@ -102,6 +102,7 @@ valley_electricity_timer, volume, wash_towel_mode, + wash_water_temperature, ) from .camera import CameraTrait from .child_lock import ChildLockTrait @@ -130,6 +131,7 @@ from .valley_electricity_timer import ValleyElectricityTimerTrait from .volume import SoundVolumeTrait from .wash_towel_mode import WashTowelModeTrait +from .wash_water_temperature import WashWaterTemperatureTrait, is_wash_water_temperature_offered _LOGGER = logging.getLogger(__name__) @@ -162,6 +164,7 @@ "valley_electricity_timer", "volume", "wash_towel_mode", + "wash_water_temperature", ] @@ -199,6 +202,7 @@ class PropertiesApi(Trait): dust_collection: DustCollectionTrait | None = None wash_towel_mode: WashTowelModeTrait | None = None smart_wash_params: SmartWashParamsTrait | None = None + wash_water_temperature: WashWaterTemperatureTrait | None = None obstacle_photos: ObstaclePhotoTrait | None = None mop_dryer: MopDryerTrait | None = None customize_clean_mode: CustomizeCleanModeTrait | None = None @@ -220,6 +224,7 @@ def __init__( ) -> None: """Initialize the V1TraitProps.""" self._device_uid = device_uid + self._product = product self._rpc_channel = rpc_channel self._mqtt_rpc_channel = mqtt_rpc_channel self._map_rpc_channel = map_rpc_channel @@ -308,6 +313,18 @@ async def discover_features(self) -> None: wash_towel_mode._rpc_channel = self._get_rpc_channel(wash_towel_mode) # type: ignore[assignment] self.wash_towel_mode = wash_towel_mode + # The wash water temperature needs a washing dock, a device that can heat wash water, + # and a product and dock for which the app shows it. + if ( + self.wash_water_temperature is None + and self.device_features.is_hot_wash_towel_supported + and is_wash_water_temperature_offered(self._product.product_nickname, dock_features) + and self._is_supported(WashWaterTemperatureTrait, "wash_water_temperature", dock_features) + ): + wash_water_temperature = WashWaterTemperatureTrait(self.device_features) + wash_water_temperature._rpc_channel = self._get_rpc_channel(wash_water_temperature) # type: ignore[assignment] + self.wash_water_temperature = wash_water_temperature + # The dust collection mode needs both device and dock features if self.dust_collection_mode is None and supports_dust_collection_mode(self.device_features, dock_features): dust_collection_mode = DustCollectionModeTrait() @@ -353,7 +370,12 @@ async def discover_features(self) -> None: # Union args may not be in declared order item_type = union_args[0] if union_args[1] is type(None) else union_args[1] # Created above with constructor arguments or extra gating - if item_type in (ObstaclePhotoTrait, CollisionAvoidanceTrait, DustCollectionModeTrait): + if item_type in ( + ObstaclePhotoTrait, + CollisionAvoidanceTrait, + DustCollectionModeTrait, + WashWaterTemperatureTrait, + ): continue if not self._is_supported(item_type, item.name, dock_features): _LOGGER.debug("Trait '%s' not supported, skipping", item.name) diff --git a/roborock/devices/traits/v1/wash_water_temperature.py b/roborock/devices/traits/v1/wash_water_temperature.py new file mode 100644 index 000000000..2d5d0ca77 --- /dev/null +++ b/roborock/devices/traits/v1/wash_water_temperature.py @@ -0,0 +1,82 @@ +"""Trait for the mop wash water temperature.""" + +from roborock.data import ( + RoborockDockTypeCode, + RoborockDockWashWaterTemperatureCode, + RoborockProductNickname, + WashWaterTemperature, +) +from roborock.device_features import RoborockDockFeatures +from roborock.devices.traits.v1 import common +from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait +from roborock.exceptions import RoborockUnsupportedFeature +from roborock.roborock_typing import RoborockCommand + + +def get_wash_water_temperatures(dock_features: RoborockDockFeatures) -> list[RoborockDockWashWaterTemperatureCode]: + """Return the wash water temperatures the app offers for a dock, in app order. + + Warm is offered only by docks with neither high temperature water nor steam; steam + only by steam docks. Pet steam is never offered. Known exception: the app for the UltronSV + (a97) also shows warm on its high temperature docks; that needs plugin family detection. + """ + options = [RoborockDockWashWaterTemperatureCode.room_temperature] + if not dock_features.is_high_tmp_water_supported and not dock_features.is_steam_wash_supported: + options.append(RoborockDockWashWaterTemperatureCode.warm) + options.append(RoborockDockWashWaterTemperatureCode.hot) + if dock_features.is_steam_wash_supported: + options.append(RoborockDockWashWaterTemperatureCode.steam) + return options + + +def is_wash_water_temperature_offered( + product_nickname: RoborockProductNickname, dock_features: RoborockDockFeatures +) -> bool: + """Return whether the wash water temperature can be set for this product and dock. + + A Shell E dock (also the Shell EA variant) cannot heat wash water, even when the robot + reports hot wash support. The PearlE Pro (``PEARLELITE``) offers the temperature only + with a Shell2E Lite dock. + """ + if dock_features.dock_type == RoborockDockTypeCode.shell_e_dock: + return False + return ( + product_nickname != RoborockProductNickname.PEARLELITE + or dock_features.dock_type == RoborockDockTypeCode.shell_2e_lite_dock + ) + + +def _supports_wash_water_temperature(dock_features: RoborockDockFeatures) -> bool: + return dock_features.is_washable + + +class WashWaterTemperatureTrait(WashWaterTemperature, common.V1TraitMixin): + """Water temperature the dock uses to wash the mop (app: water temperature). + + Created only for washing docks on devices with ``is_hot_wash_towel_supported``, and + when ``is_wash_water_temperature_offered`` allows it. + """ + + command = RoborockCommand.GET_WASH_WATER_TEMPERATURE + converter = common.DefaultConverter(WashWaterTemperature) + requires_dock_features = _supports_wash_water_temperature + + def __init__(self, device_feature_trait: DeviceFeaturesTrait) -> None: + super().__init__() + self.device_feature_trait = device_feature_trait + + @property + def wash_water_temperature_options(self) -> list[RoborockDockWashWaterTemperatureCode]: + """Return the wash water temperatures offered by the dock.""" + return get_wash_water_temperatures(self.device_feature_trait.dock_features) + + async def set_wash_water_temperature(self, temperature: RoborockDockWashWaterTemperatureCode) -> None: + """Set the mop wash water temperature.""" + if temperature not in self.wash_water_temperature_options: + raise RoborockUnsupportedFeature(f"Wash water temperature {temperature.name} is not supported") + # The device reads back "wash_water_temperature" but expects the new value under "values". + await self.rpc_channel.send_command( + RoborockCommand.SET_WASH_WATER_TEMPERATURE, params={"values": temperature.value} + ) + # Optimistic update to avoid an extra refresh + self.wash_water_temperature = temperature diff --git a/tests/devices/traits/v1/fixtures.py b/tests/devices/traits/v1/fixtures.py index b760d2589..cacb168e8 100644 --- a/tests/devices/traits/v1/fixtures.py +++ b/tests/devices/traits/v1/fixtures.py @@ -1,6 +1,7 @@ """Fixtures for V1 trait tests.""" from copy import deepcopy +from dataclasses import replace from unittest.mock import AsyncMock, Mock import pytest @@ -76,10 +77,25 @@ def device_info_fixture(trait_home_data: HomeData) -> HomeDataDevice: return trait_home_data.get_all_devices()[0] +@pytest.fixture(name="product_model") +def product_model_fixture() -> str | None: + """Model of the test device's product, e.g. "roborock.vacuum.a144". + + None keeps the fixture's model: the S7 MaxV (a27, TopazSV), which the app treats as an older product. + """ + return None + + @pytest.fixture(name="products") -def products_fixture() -> list[HomeDataProduct]: +def products_fixture(device_info: HomeDataDevice, product_model: str | None) -> list[HomeDataProduct]: """Fixture to provide a Product instance for tests.""" - return [HomeDataProduct.from_dict(product) for product in mock_data.PRODUCTS.values()] + products = [HomeDataProduct.from_dict(product) for product in mock_data.PRODUCTS.values()] + if product_model is None: + return products + return [ + replace(product, model=product_model) if product.id == device_info.product_id else product + for product in products + ] @pytest.fixture(autouse=True, name="device") diff --git a/tests/devices/traits/v1/helpers.py b/tests/devices/traits/v1/helpers.py index 6493ce34c..e17b06a0f 100644 --- a/tests/devices/traits/v1/helpers.py +++ b/tests/devices/traits/v1/helpers.py @@ -1,7 +1,8 @@ """Shared helpers for V1 trait tests.""" -from roborock.data import RoborockDockTypeCode -from roborock.device_features import RoborockDockFeatures +from roborock.data import HomeData, RoborockDockTypeCode +from roborock.device_features import NewFeatureStrBit, RoborockDockFeatures +from tests import mock_data def dock_types_with_capability(capability: str, expected: bool = True) -> list[RoborockDockTypeCode]: @@ -11,3 +12,15 @@ def dock_types_with_capability(capability: str, expected: bool = True) -> list[R for dock_type in RoborockDockTypeCode if getattr(RoborockDockFeatures.from_dock_type(dock_type), capability) is expected ] + + +def home_data_with_feature_bit(bit: NewFeatureStrBit, supported: bool) -> HomeData: + """Return home data whose first device has a new feature bit set or cleared.""" + home_data = HomeData.from_dict(mock_data.HOME_DATA_RAW) + device = home_data.get_all_devices()[0] + assert device.new_feature_set is not None + bits = int(device.new_feature_set, 16) + mask = 1 << bit + bits = bits | mask if supported else bits & ~mask + device.new_feature_set = format(bits, "x").zfill(len(device.new_feature_set)) + return home_data diff --git a/tests/devices/traits/v1/test_wash_water_temperature.py b/tests/devices/traits/v1/test_wash_water_temperature.py new file mode 100644 index 000000000..73898d9a3 --- /dev/null +++ b/tests/devices/traits/v1/test_wash_water_temperature.py @@ -0,0 +1,297 @@ +"""Tests for the WashWaterTemperatureTrait class.""" + +from copy import deepcopy +from unittest.mock import AsyncMock + +import pytest + +from roborock.data import ( + HomeData, + RoborockDockTypeCode, + RoborockDockWashWaterTemperatureCode, + RoborockProductNickname, +) +from roborock.device_features import NewFeatureStrBit, RoborockDockFeatures +from roborock.devices.device import RoborockDevice +from roborock.devices.traits.v1.wash_water_temperature import ( + WashWaterTemperatureTrait, + get_wash_water_temperatures, + is_wash_water_temperature_offered, +) +from roborock.exceptions import RoborockException, RoborockUnsupportedFeature +from roborock.roborock_typing import RoborockCommand +from tests.devices.traits.v1.helpers import dock_types_with_capability, home_data_with_feature_bit + +SAROS_10R_DOCK = RoborockDockTypeCode.shell_3s_dock + + +@pytest.fixture(name="wash_water_temperature") +def wash_water_temperature_trait( + device: RoborockDevice, + discover_features_fixture: None, +) -> WashWaterTemperatureTrait | None: + """Create a WashWaterTemperatureTrait instance with mocked dependencies.""" + assert device.v1_properties + return device.v1_properties.wash_water_temperature + + +@pytest.mark.parametrize( + ("dock_type_code", "expected"), + [ + ( + # Saros 10R: neither high temperature nor steam + RoborockDockTypeCode.shell_3s_dock, + [ + RoborockDockWashWaterTemperatureCode.room_temperature, + RoborockDockWashWaterTemperatureCode.warm, + RoborockDockWashWaterTemperatureCode.hot, + ], + ), + ( + # Steam only + RoborockDockTypeCode.o7h_dock, + [ + RoborockDockWashWaterTemperatureCode.room_temperature, + RoborockDockWashWaterTemperatureCode.hot, + RoborockDockWashWaterTemperatureCode.steam, + ], + ), + ( + # High temperature only: the app hides warm + RoborockDockTypeCode.k1r_dock, + [ + RoborockDockWashWaterTemperatureCode.room_temperature, + RoborockDockWashWaterTemperatureCode.hot, + ], + ), + ], +) +def test_get_wash_water_temperatures( + dock_type_code: RoborockDockTypeCode, + expected: list[RoborockDockWashWaterTemperatureCode], +) -> None: + """Test the temperatures offered for each dock family.""" + assert get_wash_water_temperatures(RoborockDockFeatures.from_dock_type(dock_type_code)) == expected + + +@pytest.mark.parametrize( + ("product_nickname", "dock_type_code", "expected"), + [ + (RoborockProductNickname.CORALPRO, SAROS_10R_DOCK, True), + (RoborockProductNickname.TOPAZSV, RoborockDockTypeCode.shell_2e_lite_dock, True), + (RoborockProductNickname.PEARLELITE, SAROS_10R_DOCK, False), + (RoborockProductNickname.PEARLELITE, RoborockDockTypeCode.shell_e_dock, False), + (RoborockProductNickname.PEARLELITE, RoborockDockTypeCode.shell_2e_lite_dock, True), + # Shell E docks cannot heat wash water, on any product + (RoborockProductNickname.CORALPRO, RoborockDockTypeCode.shell_e_dock, False), + (RoborockProductNickname.TOPAZSV, RoborockDockTypeCode.shell_e_dock, False), + ], +) +def test_is_wash_water_temperature_offered( + product_nickname: RoborockProductNickname, + dock_type_code: RoborockDockTypeCode, + expected: bool, +) -> None: + """Test the product and dock rules for offering the wash water temperature.""" + dock_features = RoborockDockFeatures.from_dock_type(dock_type_code) + assert is_wash_water_temperature_offered(product_nickname, dock_features) is expected + + +def test_shell_ea_dock_has_no_wash_water_temperature() -> None: + """Test that the Shell EA variant (Shell E with auto-empty) is excluded too.""" + dock_features = RoborockDockFeatures.from_dock_type(RoborockDockTypeCode.shell_e_dock, has_am=True) + assert not is_wash_water_temperature_offered(RoborockProductNickname.CORALPRO, dock_features) + + +@pytest.mark.parametrize(("product_model"), ["roborock.vacuum.a170"]) # PearlE Pro +@pytest.mark.parametrize( + ("dock_type_code", "available"), + [ + (SAROS_10R_DOCK, False), + (RoborockDockTypeCode.shell_2e_lite_dock, True), + ], +) +async def test_pearl_e_pro_wash_water_temperature( + device: RoborockDevice, + wash_water_temperature: WashWaterTemperatureTrait | None, + product_model: str, + dock_type_code: RoborockDockTypeCode, + available: bool, +) -> None: + """Test that a PearlE Pro gets the temperature trait only on a Shell2E Lite dock.""" + assert device.is_connected + assert (wash_water_temperature is not None) is available + + +@pytest.mark.parametrize( + ("dock_type_code"), + [ + dock_type + for dock_type in dock_types_with_capability("is_washable") + if dock_type != RoborockDockTypeCode.shell_e_dock + ], +) +async def test_wash_water_temperature_available( + wash_water_temperature: WashWaterTemperatureTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the trait is available for washing docks that can heat wash water.""" + assert wash_water_temperature is not None + + +@pytest.mark.parametrize(("dock_type_code"), [RoborockDockTypeCode.shell_e_dock]) +async def test_shell_e_dock_has_no_wash_water_temperature( + device: RoborockDevice, + wash_water_temperature: WashWaterTemperatureTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a Shell E dock gets no temperature trait although the robot reports hot wash.""" + assert device.v1_properties + assert device.is_connected + assert device.v1_properties.device_features.is_hot_wash_towel_supported + assert wash_water_temperature is None + + +@pytest.mark.parametrize( + ("dock_type_code"), + dock_types_with_capability("is_washable", expected=False), +) +async def test_unsupported_wash_water_temperature( + wash_water_temperature: WashWaterTemperatureTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the trait is not available for docks without mop washing.""" + assert wash_water_temperature is None + + +def _home_data_with_hot_wash(supported: bool) -> HomeData: + """Return home data whose device has the hot wash towel feature bit set or cleared.""" + return home_data_with_feature_bit(NewFeatureStrBit.HOT_WASH_TOWEL, supported) + + +@pytest.fixture(name="trait_home_data") +def trait_home_data_fixture(request: pytest.FixtureRequest) -> HomeData: + """Default to a device that can heat wash water, as the Saros 10R.""" + return deepcopy(getattr(request, "param", _home_data_with_hot_wash(True))) + + +@pytest.mark.parametrize("trait_home_data", [_home_data_with_hot_wash(False)], indirect=True) +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +async def test_unsupported_without_hot_wash( + trait_home_data: HomeData, + device: RoborockDevice, + wash_water_temperature: WashWaterTemperatureTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a washing dock on a device that cannot heat wash water has no temperature trait.""" + assert device.v1_properties + assert device.is_connected + assert not device.v1_properties.device_features.is_hot_wash_towel_supported + assert wash_water_temperature is None + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("response", "expected"), + [ + ({"wash_water_temperature": 2}, RoborockDockWashWaterTemperatureCode.hot), # Saros 10R + ({"wash_water_temperature": 0}, RoborockDockWashWaterTemperatureCode.room_temperature), + ({"wash_water_temperature": 9}, RoborockDockWashWaterTemperatureCode.unknown), + ], +) +async def test_refresh_unknown_code( + wash_water_temperature: WashWaterTemperatureTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + response: dict[str, int], + expected: RoborockDockWashWaterTemperatureCode, +) -> None: + """Test that refresh decodes known codes and tolerates unknown ones.""" + assert wash_water_temperature is not None + mock_rpc_channel.send_command.side_effect = [response] + + await wash_water_temperature.refresh() + + mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_WASH_WATER_TEMPERATURE) + assert wash_water_temperature.wash_water_temperature == expected + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +async def test_options( + wash_water_temperature: WashWaterTemperatureTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the trait offers the temperatures of its dock.""" + assert wash_water_temperature is not None + assert wash_water_temperature.wash_water_temperature_options == [ + RoborockDockWashWaterTemperatureCode.room_temperature, + RoborockDockWashWaterTemperatureCode.warm, + RoborockDockWashWaterTemperatureCode.hot, + ] + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("temperature"), + [ + RoborockDockWashWaterTemperatureCode.room_temperature, + RoborockDockWashWaterTemperatureCode.warm, + RoborockDockWashWaterTemperatureCode.hot, + ], +) +async def test_set_wash_water_temperature( + wash_water_temperature: WashWaterTemperatureTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + temperature: RoborockDockWashWaterTemperatureCode, +) -> None: + """Test setting an offered wash water temperature.""" + assert wash_water_temperature is not None + + await wash_water_temperature.set_wash_water_temperature(temperature) + + mock_rpc_channel.send_command.assert_called_once_with( + RoborockCommand.SET_WASH_WATER_TEMPERATURE, params={"values": temperature.value} + ) + assert wash_water_temperature.wash_water_temperature == temperature + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("temperature"), + [ + RoborockDockWashWaterTemperatureCode.steam, + RoborockDockWashWaterTemperatureCode.pet_steam, + RoborockDockWashWaterTemperatureCode.unknown, + ], +) +async def test_set_rejects_unoffered( + wash_water_temperature: WashWaterTemperatureTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + temperature: RoborockDockWashWaterTemperatureCode, +) -> None: + """Test that a temperature the dock does not offer is rejected without sending.""" + assert wash_water_temperature is not None + + with pytest.raises(RoborockUnsupportedFeature): + await wash_water_temperature.set_wash_water_temperature(temperature) + + mock_rpc_channel.send_command.assert_not_called() + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +async def test_set_failure_keeps_state( + wash_water_temperature: WashWaterTemperatureTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a failed command leaves the temperature unchanged.""" + assert wash_water_temperature is not None + wash_water_temperature.wash_water_temperature = RoborockDockWashWaterTemperatureCode.hot + mock_rpc_channel.send_command.side_effect = RoborockException("boom") + + with pytest.raises(RoborockException): + await wash_water_temperature.set_wash_water_temperature(RoborockDockWashWaterTemperatureCode.warm) + + assert wash_water_temperature.wash_water_temperature == RoborockDockWashWaterTemperatureCode.hot From 6c2cc74c225c898a9c95e0dfc12680cef11cc36b Mon Sep 17 00:00:00 2001 From: infy1995 Date: Thu, 12 Nov 2026 21:31:49 +0100 Subject: [PATCH 2/4] feat: add V1 cleaning fluid auto-delivery trait Let consumers read and set how much cleaning fluid is added automatically. CleaningFluidTrait is created only when the robot reports a fluid container and either the robot or the dock delivers fluid, because other setups ignore the setting. Shell 4S docks, with several fluids, are left out. The large amount is offered only to robots with cleaning fluid delivery; others read it back as standard. --- docs/V1_API_COMMANDS.md | 47 ++++ docs/V1_DEVICE_FEATURES.md | 2 +- roborock/data/v1/v1_code_mappings.py | 9 + roborock/data/v1/v1_containers.py | 8 + roborock/devices/traits/v1/__init__.py | 16 ++ roborock/devices/traits/v1/cleaning_fluid.py | 59 ++++ tests/devices/traits/v1/fixtures.py | 9 + .../devices/traits/v1/test_cleaning_fluid.py | 265 ++++++++++++++++++ 8 files changed, 414 insertions(+), 1 deletion(-) create mode 100644 roborock/devices/traits/v1/cleaning_fluid.py create mode 100644 tests/devices/traits/v1/test_cleaning_fluid.py diff --git a/docs/V1_API_COMMANDS.md b/docs/V1_API_COMMANDS.md index 0f7fb1f94..9d459c401 100644 --- a/docs/V1_API_COMMANDS.md +++ b/docs/V1_API_COMMANDS.md @@ -30,6 +30,7 @@ Commands can have multiple parameters that can change from one model to another. * [del_server_timer](#del_server_timer) * [del_timer](#del_timer) * [dnld_install_sound](#dnld_install_sound) +* [get_auto_delivery_cleaning_fluid](#get_auto_delivery_cleaning_fluid) * [get_clean_sequence](#get_clean_sequence) * [get_consumable](#get_consumable) * [get_custom_mode](#get_custom_mode) @@ -68,6 +69,7 @@ Commands can have multiple parameters that can change from one model to another. * [save_map](#save_map) * [send_ice_to_robot](#send_ice_to_robot) * [send_sdp_to_robot](#send_sdp_to_robot) +* [set_auto_delivery_cleaning_fluid](#set_auto_delivery_cleaning_fluid) * [set_server_timer](#set_server_timer) * [set_clean_motor_mode](#set_clean_motor_mode) * [set_customize_clean_mode](#set_customize_clean_mode) @@ -1555,6 +1557,51 @@ Source: Roborock Saros 10R * Roborock Saros 10R: ✅ +### get_auto_delivery_cleaning_fluid + +Description: Get how much cleaning fluid the dock adds automatically (app: cleaning fluid auto-delivery). Available when +the robot reports a cleaning fluid container (`dss` bits 10-11 not 0) and either the robot supports cleaning fluid +delivery (`is_clean_fluid_delivery_supported`) or the dock does auto-delivery. Not available on Shell 4S docks. + +Parameters: None + +Returns: + + status: 0 off, 1 standard, 3 large. Code 2 is not used. Robots without `is_clean_fluid_delivery_supported` + only switch it on (1) or off (0); such a robot reads 3 back as 1. + +Return example: + +```json + {'status': 1} +``` + +Source: Roborock Saros 10R, Roborock app plugin + +**Supported devices:** + +* Roborock Saros 10R: ✅ + +### set_auto_delivery_cleaning_fluid + +Description: Set how much cleaning fluid the dock adds automatically. + +Parameters: + + status: 0 off, 1 standard, 3 large (3 only on robots with `is_clean_fluid_delivery_supported`; others accept 0 and 1). + +Example: + +```json + {'status': 1} +``` + +Source: Roborock Saros 10R, Roborock app plugin + +**Supported devices:** + +* Roborock Saros 10R: ✅ + ### get_collision_avoid_status Description: diff --git a/docs/V1_DEVICE_FEATURES.md b/docs/V1_DEVICE_FEATURES.md index b12db1441..ec3f58e78 100644 --- a/docs/V1_DEVICE_FEATURES.md +++ b/docs/V1_DEVICE_FEATURES.md @@ -1156,7 +1156,7 @@ These features are encoded as individual bits in the `new_feature_info_str` hex **Bit Index:** 112 **Feature:** Cleaning Fluid Delivery **Description:** Automatic delivery of cleaning solution/detergent. -**Impact:** Enhanced mopping with cleaning agents. +**Impact:** Enhanced mopping with cleaning agents. Enables `CleaningFluidTrait` on a robot reporting a fluid container, and adds its `large` amount. --- diff --git a/roborock/data/v1/v1_code_mappings.py b/roborock/data/v1/v1_code_mappings.py index da2d3f7e9..623ac6ef4 100644 --- a/roborock/data/v1/v1_code_mappings.py +++ b/roborock/data/v1/v1_code_mappings.py @@ -455,6 +455,15 @@ class RoborockDockWashWaterTemperatureCode(RoborockEnum): pet_steam = 4 +class RoborockDockCleaningFluidCode(RoborockEnum): + """Describes how much cleaning fluid the dock adds automatically (app: cleaning fluid auto-delivery).""" + + unknown = -1 + off = 0 + standard = 1 + large = 3 + + class RoborockStateCode(RoborockEnum): unknown = 0 starting = 1 diff --git a/roborock/data/v1/v1_containers.py b/roborock/data/v1/v1_containers.py index 16592625e..146e2651d 100644 --- a/roborock/data/v1/v1_containers.py +++ b/roborock/data/v1/v1_containers.py @@ -27,6 +27,7 @@ DustBagStatus, RoborockChargeStatus, RoborockCleanType, + RoborockDockCleaningFluidCode, RoborockDockDustCollectionFrequencyCode, RoborockDockDustCollectionModeCode, RoborockDockErrorCode, @@ -497,6 +498,13 @@ class WashWaterTemperature(RoborockBase): wash_water_temperature: RoborockDockWashWaterTemperatureCode | None = None +@dataclass +class CleaningFluidDelivery(RoborockBase): + """Cleaning fluid auto-delivery amount, as returned by GET_AUTO_DELIVERY_CLEANING_FLUID.""" + + status: RoborockDockCleaningFluidCode | None = None + + @dataclass class MopDryerProfile(RoborockBase): """Dryer parameters for one state of the auto mop-drying setting.""" diff --git a/roborock/devices/traits/v1/__init__.py b/roborock/devices/traits/v1/__init__.py index 4dae49860..1ae692192 100644 --- a/roborock/devices/traits/v1/__init__.py +++ b/roborock/devices/traits/v1/__init__.py @@ -78,6 +78,7 @@ camera, child_lock, clean_summary, + cleaning_fluid, collision_avoidance, command, common, @@ -107,6 +108,7 @@ from .camera import CameraTrait from .child_lock import ChildLockTrait from .clean_summary import CleanSummaryTrait +from .cleaning_fluid import CleaningFluidTrait, supports_cleaning_fluid from .collision_avoidance import CollisionAvoidanceModeTrait, CollisionAvoidanceTrait from .command import CommandTrait from .common import V1TraitMixin @@ -140,6 +142,7 @@ "camera", "child_lock", "clean_summary", + "cleaning_fluid", "collision_avoidance", "command", "common", @@ -203,6 +206,7 @@ class PropertiesApi(Trait): wash_towel_mode: WashTowelModeTrait | None = None smart_wash_params: SmartWashParamsTrait | None = None wash_water_temperature: WashWaterTemperatureTrait | None = None + cleaning_fluid: CleaningFluidTrait | None = None obstacle_photos: ObstaclePhotoTrait | None = None mop_dryer: MopDryerTrait | None = None customize_clean_mode: CustomizeCleanModeTrait | None = None @@ -325,6 +329,17 @@ async def discover_features(self) -> None: wash_water_temperature._rpc_channel = self._get_rpc_channel(wash_water_temperature) # type: ignore[assignment] self.wash_water_temperature = wash_water_temperature + # The cleaning fluid needs the robot's fluid container status as well as device and dock features. + # Discovery does not repeat on status updates: no container now means no trait until the next device setup. + if self.cleaning_fluid is None and supports_cleaning_fluid( + fluid_delivery_supported=self.device_features.is_clean_fluid_delivery_supported, + dock_features=dock_features, + fluid_status=self.status.clean_fluid_status, + ): + cleaning_fluid = CleaningFluidTrait(self.device_features) + cleaning_fluid._rpc_channel = self._get_rpc_channel(cleaning_fluid) # type: ignore[assignment] + self.cleaning_fluid = cleaning_fluid + # The dust collection mode needs both device and dock features if self.dust_collection_mode is None and supports_dust_collection_mode(self.device_features, dock_features): dust_collection_mode = DustCollectionModeTrait() @@ -375,6 +390,7 @@ async def discover_features(self) -> None: CollisionAvoidanceTrait, DustCollectionModeTrait, WashWaterTemperatureTrait, + CleaningFluidTrait, ): continue if not self._is_supported(item_type, item.name, dock_features): diff --git a/roborock/devices/traits/v1/cleaning_fluid.py b/roborock/devices/traits/v1/cleaning_fluid.py new file mode 100644 index 000000000..efd125665 --- /dev/null +++ b/roborock/devices/traits/v1/cleaning_fluid.py @@ -0,0 +1,59 @@ +"""Trait for the cleaning fluid auto-delivery of the dock.""" + +from roborock.data import CleanFluidStatus, CleaningFluidDelivery, RoborockDockCleaningFluidCode, RoborockDockTypeCode +from roborock.device_features import RoborockDockFeatures +from roborock.devices.traits.v1 import common +from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait +from roborock.exceptions import RoborockUnsupportedFeature +from roborock.roborock_typing import RoborockCommand + + +def supports_cleaning_fluid( + fluid_delivery_supported: bool, + dock_features: RoborockDockFeatures, + fluid_status: CleanFluidStatus | None, +) -> bool: + """Return whether the cleaning fluid setting is offered. + + The robot must report a cleaning fluid container, and either the robot supports cleaning + fluid delivery (``is_clean_fluid_delivery_supported``) or the dock does auto-delivery. + Shell 4S docks have several cleaning fluids and their own controls. + """ + if fluid_status is None: + return False + if dock_features.dock_type == RoborockDockTypeCode.shell_4s_dock: + return False + return fluid_delivery_supported or dock_features.is_clean_fluid_auto_delivery_supported + + +class CleaningFluidTrait(CleaningFluidDelivery, common.V1TraitMixin): + """Amount of cleaning fluid the dock adds automatically (app: cleaning fluid auto-delivery). + + Robots with cleaning fluid delivery offer off, standard and large (wire code 3); others + only switch it on (standard) or off. Wire code 2 is not used. + """ + + command = RoborockCommand.GET_AUTO_DELIVERY_CLEANING_FLUID + converter = common.DefaultConverter(CleaningFluidDelivery) + + def __init__(self, device_feature_trait: DeviceFeaturesTrait) -> None: + super().__init__() + self.device_feature_trait = device_feature_trait + + @property + def cleaning_fluid_options(self) -> list[RoborockDockCleaningFluidCode]: + """Return the cleaning fluid amounts the robot offers.""" + options = [RoborockDockCleaningFluidCode.off, RoborockDockCleaningFluidCode.standard] + if self.device_feature_trait.is_clean_fluid_delivery_supported: + options.append(RoborockDockCleaningFluidCode.large) + return options + + async def set_cleaning_fluid(self, mode: RoborockDockCleaningFluidCode) -> None: + """Set the cleaning fluid auto-delivery amount.""" + if mode not in self.cleaning_fluid_options: + raise RoborockUnsupportedFeature(f"Cleaning fluid amount {mode.name} is not supported") + await self.rpc_channel.send_command( + RoborockCommand.SET_AUTO_DELIVERY_CLEANING_FLUID, params={"status": mode.value} + ) + # Optimistic update to avoid an extra refresh + self.status = mode diff --git a/tests/devices/traits/v1/fixtures.py b/tests/devices/traits/v1/fixtures.py index cacb168e8..66eb62391 100644 --- a/tests/devices/traits/v1/fixtures.py +++ b/tests/devices/traits/v1/fixtures.py @@ -2,6 +2,7 @@ from copy import deepcopy from dataclasses import replace +from typing import Any from unittest.mock import AsyncMock, Mock import pytest @@ -139,12 +140,19 @@ def dock_type_code_fixture(device_info: HomeDataDevice) -> RoborockDockTypeCode return mock_data.PRODUCT_DOCK_TYPE_MAP.get(device_info.product_id, RoborockDockTypeCode.o3_plus_dock) +@pytest.fixture(name="status_overrides") +def status_overrides_fixture() -> dict[str, Any]: + """Status fields replacing the defaults in the status the device returns during discovery.""" + return {} + + @pytest.fixture(autouse=True) async def discover_features_fixture( device: RoborockDevice, mock_rpc_channel: AsyncMock, dock_type_code: RoborockDockTypeCode | None, device_info: HomeDataDevice, + status_overrides: dict[str, Any], ) -> None: """Fixture to handle device feature discovery.""" assert device.v1_properties @@ -164,6 +172,7 @@ async def discover_features_fixture( { **mock_data.STATUS, "dock_type": dock_type_code, + **status_overrides, }, ] # Connecting triggers device discovery diff --git a/tests/devices/traits/v1/test_cleaning_fluid.py b/tests/devices/traits/v1/test_cleaning_fluid.py new file mode 100644 index 000000000..e37895bcd --- /dev/null +++ b/tests/devices/traits/v1/test_cleaning_fluid.py @@ -0,0 +1,265 @@ +"""Tests for the CleaningFluidTrait class.""" + +from copy import deepcopy +from typing import Any +from unittest.mock import AsyncMock + +import pytest + +from roborock.data import CleanFluidStatus, HomeData, RoborockDockCleaningFluidCode, RoborockDockTypeCode +from roborock.device_features import NewFeatureStrBit, RoborockDockFeatures +from roborock.devices.device import RoborockDevice +from roborock.devices.traits.v1.cleaning_fluid import CleaningFluidTrait, supports_cleaning_fluid +from roborock.exceptions import RoborockException, RoborockUnsupportedFeature +from roborock.roborock_typing import RoborockCommand +from tests.devices.traits.v1.helpers import dock_types_with_capability, home_data_with_feature_bit + +SAROS_10R_DOCK = RoborockDockTypeCode.shell_3s_dock +PEARL_PLUS_DOCK = RoborockDockTypeCode.pearl_plus_dock +# dss with the cleaning fluid container bits (10-11) at 2: the fluid container is okay (Saros 10R) +DSS_FLUID_OK = 2212 +# dss without cleaning fluid container bits (Qrevo MaxV 2) +DSS_NO_FLUID = 165 + + +def _home_data_with_fluid_delivery(supported: bool) -> HomeData: + """Return home data whose device has the cleaning fluid delivery feature bit set or cleared.""" + return home_data_with_feature_bit(NewFeatureStrBit.CLEAN_FLUID_DELIVERY, supported) + + +@pytest.fixture(name="trait_home_data") +def trait_home_data_fixture(request: pytest.FixtureRequest) -> HomeData: + """Default to a robot with cleaning fluid delivery, as the Saros 10R.""" + return deepcopy(getattr(request, "param", _home_data_with_fluid_delivery(True))) + + +@pytest.fixture(name="status_overrides") +def status_overrides_fixture() -> dict[str, Any]: + """Default to a robot whose cleaning fluid container is okay.""" + return {"dss": DSS_FLUID_OK} + + +@pytest.fixture(name="cleaning_fluid") +def cleaning_fluid_trait( + device: RoborockDevice, + discover_features_fixture: None, +) -> CleaningFluidTrait | None: + """Create a CleaningFluidTrait instance with mocked dependencies.""" + assert device.v1_properties + return device.v1_properties.cleaning_fluid + + +@pytest.mark.parametrize( + ("fluid_delivery", "dock_type", "has_am", "fluid_status", "expected"), + [ + (True, SAROS_10R_DOCK, None, CleanFluidStatus.okay, True), # Saros 10R + (True, RoborockDockTypeCode.o0_dock, None, CleanFluidStatus.okay, True), # amount page, no dock flag + (False, PEARL_PLUS_DOCK, None, CleanFluidStatus.okay, True), # on/off switch + (False, PEARL_PLUS_DOCK, None, CleanFluidStatus.empty_not_installed, True), # empty tank still shows it + (True, PEARL_PLUS_DOCK, None, None, False), # no fluid container bits (Qrevo MaxV 2) + (False, RoborockDockTypeCode.o0_dock, None, CleanFluidStatus.okay, False), # neither robot nor dock deliver + (True, RoborockDockTypeCode.shell_4s_dock, None, CleanFluidStatus.okay, False), # multi fluid dock + (False, RoborockDockTypeCode.k1_dock, True, CleanFluidStatus.okay, True), # auto-empty variant of a dock + (False, RoborockDockTypeCode.k1_dock, None, CleanFluidStatus.okay, False), # variant without auto-empty + ], +) +def test_supports_cleaning_fluid( + fluid_delivery: bool, + dock_type: RoborockDockTypeCode, + has_am: bool | None, + fluid_status: CleanFluidStatus | None, + expected: bool, +) -> None: + """Test the rules for offering the cleaning fluid setting.""" + dock_features = RoborockDockFeatures.from_dock_type(dock_type, has_am=has_am) + + assert supports_cleaning_fluid(fluid_delivery, dock_features, fluid_status) is expected + + +@pytest.mark.parametrize( + ("dock_type_code"), + dock_types_with_capability("is_clean_fluid_auto_delivery_supported"), +) +async def test_cleaning_fluid_available( + cleaning_fluid: CleaningFluidTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the trait is available for docks with cleaning fluid auto-delivery.""" + assert cleaning_fluid is not None + + +@pytest.mark.parametrize("trait_home_data", [_home_data_with_fluid_delivery(False)], indirect=True) +@pytest.mark.parametrize( + ("dock_type_code"), + dock_types_with_capability("is_clean_fluid_auto_delivery_supported", expected=False), +) +async def test_unsupported_cleaning_fluid( + trait_home_data: HomeData, + device: RoborockDevice, + cleaning_fluid: CleaningFluidTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the trait is not available when neither the robot nor the dock deliver cleaning fluid.""" + assert device.is_connected + assert cleaning_fluid is None + + +@pytest.mark.parametrize(("dock_type_code"), [RoborockDockTypeCode.o3_plus_dock]) +async def test_available_from_robot_delivery_feature( + cleaning_fluid: CleaningFluidTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a robot with cleaning fluid delivery gets the trait on any dock.""" + assert cleaning_fluid is not None + assert cleaning_fluid.cleaning_fluid_options == [ + RoborockDockCleaningFluidCode.off, + RoborockDockCleaningFluidCode.standard, + RoborockDockCleaningFluidCode.large, + ] + + +@pytest.mark.parametrize("status_overrides", [{"dss": DSS_NO_FLUID}]) +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK, PEARL_PLUS_DOCK]) +async def test_unsupported_without_fluid_container_bits( + device: RoborockDevice, + cleaning_fluid: CleaningFluidTrait | None, + status_overrides: dict[str, Any], + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the trait is not created when the robot reports no cleaning fluid container.""" + assert device.is_connected + assert cleaning_fluid is None + + +@pytest.mark.parametrize(("dock_type_code"), [RoborockDockTypeCode.shell_4s_dock]) +async def test_unsupported_on_multi_fluid_dock( + device: RoborockDevice, + cleaning_fluid: CleaningFluidTrait | None, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a multi fluid dock gets no single cleaning fluid control.""" + assert device.is_connected + assert cleaning_fluid is None + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("response", "expected"), + [ + ({"status": 1}, RoborockDockCleaningFluidCode.standard), # Saros 10R + ({"status": 3}, RoborockDockCleaningFluidCode.large), + ({"status": 0}, RoborockDockCleaningFluidCode.off), + ({"status": 2}, RoborockDockCleaningFluidCode.unknown), + ], +) +async def test_refresh_unknown_code( + cleaning_fluid: CleaningFluidTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + response: dict[str, int], + expected: RoborockDockCleaningFluidCode, +) -> None: + """Test that refresh decodes known codes and tolerates unknown ones.""" + assert cleaning_fluid is not None + mock_rpc_channel.send_command.side_effect = [response] + + await cleaning_fluid.refresh() + + mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_AUTO_DELIVERY_CLEANING_FLUID) + assert cleaning_fluid.status == expected + + +@pytest.mark.parametrize( + ("trait_home_data", "expected"), + [ + ( + _home_data_with_fluid_delivery(True), # Saros 10R: amount page + [ + RoborockDockCleaningFluidCode.off, + RoborockDockCleaningFluidCode.standard, + RoborockDockCleaningFluidCode.large, + ], + ), + ( + _home_data_with_fluid_delivery(False), # on/off switch + [RoborockDockCleaningFluidCode.off, RoborockDockCleaningFluidCode.standard], + ), + ], + indirect=["trait_home_data"], +) +@pytest.mark.parametrize(("dock_type_code"), [PEARL_PLUS_DOCK]) +async def test_options( + trait_home_data: HomeData, + cleaning_fluid: CleaningFluidTrait | None, + dock_type_code: RoborockDockTypeCode, + expected: list[RoborockDockCleaningFluidCode], +) -> None: + """Test that the large amount is offered only by robots with cleaning fluid delivery.""" + assert cleaning_fluid is not None + assert cleaning_fluid.cleaning_fluid_options == expected + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("mode", "expected_code"), + [ + (RoborockDockCleaningFluidCode.off, 0), + (RoborockDockCleaningFluidCode.standard, 1), + (RoborockDockCleaningFluidCode.large, 3), + ], +) +async def test_set_cleaning_fluid( + cleaning_fluid: CleaningFluidTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + mode: RoborockDockCleaningFluidCode, + expected_code: int, +) -> None: + """Test setting an offered cleaning fluid amount sends its wire code.""" + assert cleaning_fluid is not None + + await cleaning_fluid.set_cleaning_fluid(mode) + + mock_rpc_channel.send_command.assert_called_once_with( + RoborockCommand.SET_AUTO_DELIVERY_CLEANING_FLUID, params={"status": expected_code} + ) + assert cleaning_fluid.status == mode + + +@pytest.mark.parametrize("trait_home_data", [_home_data_with_fluid_delivery(False)], indirect=True) +@pytest.mark.parametrize(("dock_type_code"), [PEARL_PLUS_DOCK]) +@pytest.mark.parametrize( + ("mode"), + [RoborockDockCleaningFluidCode.large, RoborockDockCleaningFluidCode.unknown], +) +async def test_set_rejects_unoffered( + trait_home_data: HomeData, + cleaning_fluid: CleaningFluidTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + mode: RoborockDockCleaningFluidCode, +) -> None: + """Test that an amount the robot does not offer is rejected without sending.""" + assert cleaning_fluid is not None + + with pytest.raises(RoborockUnsupportedFeature): + await cleaning_fluid.set_cleaning_fluid(mode) + + mock_rpc_channel.send_command.assert_not_called() + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +async def test_set_failure_keeps_state( + cleaning_fluid: CleaningFluidTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a failed command leaves the amount unchanged.""" + assert cleaning_fluid is not None + cleaning_fluid.status = RoborockDockCleaningFluidCode.standard + mock_rpc_channel.send_command.side_effect = RoborockException("boom") + + with pytest.raises(RoborockException): + await cleaning_fluid.set_cleaning_fluid(RoborockDockCleaningFluidCode.large) + + assert cleaning_fluid.status == RoborockDockCleaningFluidCode.standard From cb109fd8d8e6895d0a636ee28a648c7ffd5a462d Mon Sep 17 00:00:00 2001 From: infy1995 Date: Thu, 12 Nov 2026 21:33:19 +0100 Subject: [PATCH 3/4] feat: add V1 smart wash params setter Allow changing how often the dock washes the mop. Decode smart_wash into RoborockDockSmartWashModeCode, list the modes and intervals the product offers, and add set_smart_wash_params(), which rejects other values before sending. Older products accept intervals from 10 to 50 minutes. --- docs/V1_API_COMMANDS.md | 24 +-- docs/V1_DEVICE_FEATURES.md | 2 +- roborock/data/v1/v1_code_mappings.py | 9 + roborock/data/v1/v1_containers.py | 4 +- roborock/devices/traits/v1/__init__.py | 7 + .../devices/traits/v1/smart_wash_params.py | 57 +++++- .../traits/v1/test_smart_wash_params.py | 184 +++++++++++++++++- 7 files changed, 266 insertions(+), 21 deletions(-) diff --git a/docs/V1_API_COMMANDS.md b/docs/V1_API_COMMANDS.md index 9d459c401..9bdad0bd3 100644 --- a/docs/V1_API_COMMANDS.md +++ b/docs/V1_API_COMMANDS.md @@ -771,48 +771,48 @@ Parameters: ### get_smart_wash_params -Description: Returns the smartwash parameters +Description: Returns when the dock washes the mop during a clean (app: mop wash frequency) Parameters: None - - Returns: - smart_wash: 0 is off, 1 is on + smart_wash: 0 by time, 1 by room, 2 new smart (only on devices with is_back_wash_new_smart_supported) - wash_interval: The interval in seconds between washes + wash_interval: The interval in seconds between washes when washing by time (app offers 600, 900, 1200, 1500; 600 to 3000 in steps of 300 on TopazS, TopazSV, TopazSPlus, TopazSC, TopazSPower and UltronSPlus) Example: ```json -{'smart_wash': 0, 'wash_interval': 1200} +{'smart_wash': 1, 'wash_interval': 1200} ``` +Source: Roborock Saros 10R **Supported devices:** * Roborock S8 Pro Ultra: ✅ +* Roborock Saros 10R: ✅ ### set_smart_wash_params -Description: Sets the smartwash parameters +Description: Sets when the dock washes the mop during a clean Parameters: - smart_wash: 0 is off, 1 is on + smart_wash: 0 by time, 1 by room, 2 new smart (only on devices with is_back_wash_new_smart_supported) - wash_interval: The interval in seconds between washes + wash_interval: The interval in seconds between washes when washing by time: 600, 900, 1200 or 1500; 600 to 3000 in steps of 300 on TopazS, TopazSV, TopazSPlus, TopazSC, TopazSPower and UltronSPlus -`{'smart_wash': 0, 'wash_interval': 1200}` +`{'smart_wash': 1, 'wash_interval': 1200}` +Source: Roborock Saros 10R, Roborock app plugin **Supported devices:** * Roborock S8 Pro Ultra: ✅ +* Roborock Saros 10R: ✅ ## Cleaning history diff --git a/docs/V1_DEVICE_FEATURES.md b/docs/V1_DEVICE_FEATURES.md index ec3f58e78..ceddff560 100644 --- a/docs/V1_DEVICE_FEATURES.md +++ b/docs/V1_DEVICE_FEATURES.md @@ -1132,7 +1132,7 @@ These features are encoded as individual bits in the `new_feature_info_str` hex **Bit Index:** 109 **Feature:** Smart Back Wash **Description:** Intelligent mop back-washing with dirt detection. -**Impact:** Wash mop more when it's dirtier, less when cleaner. +**Impact:** Wash mop more when it's dirtier, less when cleaner. Adds the `new_smart` mode to `SmartWashParamsTrait`. --- diff --git a/roborock/data/v1/v1_code_mappings.py b/roborock/data/v1/v1_code_mappings.py index 623ac6ef4..551f69d28 100644 --- a/roborock/data/v1/v1_code_mappings.py +++ b/roborock/data/v1/v1_code_mappings.py @@ -464,6 +464,15 @@ class RoborockDockCleaningFluidCode(RoborockEnum): large = 3 +class RoborockDockSmartWashModeCode(RoborockEnum): + """Describes when the dock washes the mop during a clean (app: mop wash frequency).""" + + unknown = -1 + by_time = 0 + by_room = 1 + new_smart = 2 + + class RoborockStateCode(RoborockEnum): unknown = 0 starting = 1 diff --git a/roborock/data/v1/v1_containers.py b/roborock/data/v1/v1_containers.py index 146e2651d..755342584 100644 --- a/roborock/data/v1/v1_containers.py +++ b/roborock/data/v1/v1_containers.py @@ -31,6 +31,7 @@ RoborockDockDustCollectionFrequencyCode, RoborockDockDustCollectionModeCode, RoborockDockErrorCode, + RoborockDockSmartWashModeCode, RoborockDockState, RoborockDockTypeCode, RoborockDockWashWaterTemperatureCode, @@ -487,8 +488,9 @@ class MultiMapsList(RoborockBase): @dataclass class SmartWashParams(RoborockBase): - smart_wash: int | None = None + smart_wash: RoborockDockSmartWashModeCode | None = None wash_interval: int | None = None + """Seconds between mop washes when washing by time.""" @dataclass diff --git a/roborock/devices/traits/v1/__init__.py b/roborock/devices/traits/v1/__init__.py index 1ae692192..6e9c5aaf2 100644 --- a/roborock/devices/traits/v1/__init__.py +++ b/roborock/devices/traits/v1/__init__.py @@ -317,6 +317,13 @@ async def discover_features(self) -> None: wash_towel_mode._rpc_channel = self._get_rpc_channel(wash_towel_mode) # type: ignore[assignment] self.wash_towel_mode = wash_towel_mode + if self.smart_wash_params is None and self._is_supported( + SmartWashParamsTrait, "smart_wash_params", dock_features + ): + smart_wash_params = SmartWashParamsTrait(self.device_features, self._product.product_nickname) + smart_wash_params._rpc_channel = self._get_rpc_channel(smart_wash_params) # type: ignore[assignment] + self.smart_wash_params = smart_wash_params + # The wash water temperature needs a washing dock, a device that can heat wash water, # and a product and dock for which the app shows it. if ( diff --git a/roborock/devices/traits/v1/smart_wash_params.py b/roborock/devices/traits/v1/smart_wash_params.py index 78da74e20..0321e6e93 100644 --- a/roborock/devices/traits/v1/smart_wash_params.py +++ b/roborock/devices/traits/v1/smart_wash_params.py @@ -1,18 +1,71 @@ """Trait for smart wash parameters.""" -from roborock.data import SmartWashParams +from roborock.data import RoborockDockSmartWashModeCode, RoborockProductNickname, SmartWashParams from roborock.device_features import RoborockDockFeatures from roborock.devices.traits.v1 import common +from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait +from roborock.exceptions import RoborockUnsupportedFeature from roborock.roborock_typing import RoborockCommand +# Products the app gives a 10 to 50 minute slider instead of the four interval buttons +_OLD_WASH_FREQUENCY_PRODUCTS = { + RoborockProductNickname.TOPAZS, + RoborockProductNickname.TOPAZSV, + RoborockProductNickname.TOPAZSPLUS, + RoborockProductNickname.TOPAZSC, + RoborockProductNickname.TOPAZSPOWER, + RoborockProductNickname.ULTRONSPLUS, +} + + +def get_wash_interval_options(product_nickname: RoborockProductNickname) -> list[int]: + """Return the mop wash intervals in seconds the app offers for a product. + + Older products get 10 to 50 minutes in 5 minute steps; all others 10, 15, 20 and 25 minutes. + """ + if product_nickname in _OLD_WASH_FREQUENCY_PRODUCTS: + return list(range(600, 3001, 300)) + return [600, 900, 1200, 1500] + def _supports_smart_wash_params(dock_features: RoborockDockFeatures) -> bool: return dock_features.is_washable class SmartWashParamsTrait(SmartWashParams, common.V1TraitMixin): - """Trait for smart wash parameters.""" + """When the dock washes the mop during a clean (app: mop wash frequency).""" command = RoborockCommand.GET_SMART_WASH_PARAMS converter = common.DefaultConverter(SmartWashParams) requires_dock_features = _supports_smart_wash_params + + def __init__(self, device_feature_trait: DeviceFeaturesTrait, product_nickname: RoborockProductNickname) -> None: + super().__init__() + self.device_feature_trait = device_feature_trait + self.product_nickname = product_nickname + + @property + def smart_wash_mode_options(self) -> list[RoborockDockSmartWashModeCode]: + """Return the mop wash modes offered by the device.""" + options = [RoborockDockSmartWashModeCode.by_time, RoborockDockSmartWashModeCode.by_room] + if self.device_feature_trait.is_back_wash_new_smart_supported: + options.append(RoborockDockSmartWashModeCode.new_smart) + return options + + @property + def wash_interval_options(self) -> list[int]: + """Return the mop wash intervals in seconds offered by the app.""" + return get_wash_interval_options(self.product_nickname) + + async def set_smart_wash_params(self, mode: RoborockDockSmartWashModeCode, wash_interval: int) -> None: + """Set the mop wash mode and the interval in seconds used when washing by time.""" + if mode not in self.smart_wash_mode_options: + raise RoborockUnsupportedFeature(f"Smart wash mode {mode.name} is not supported") + if wash_interval not in self.wash_interval_options: + raise RoborockUnsupportedFeature(f"Wash interval {wash_interval} is not supported") + await self.rpc_channel.send_command( + RoborockCommand.SET_SMART_WASH_PARAMS, params={"smart_wash": mode.value, "wash_interval": wash_interval} + ) + # Optimistic update to avoid an extra refresh + self.smart_wash = mode + self.wash_interval = wash_interval diff --git a/tests/devices/traits/v1/test_smart_wash_params.py b/tests/devices/traits/v1/test_smart_wash_params.py index 328d5c649..e0d3b9e69 100644 --- a/tests/devices/traits/v1/test_smart_wash_params.py +++ b/tests/devices/traits/v1/test_smart_wash_params.py @@ -1,18 +1,69 @@ -"""Tests for the DockSummaryTrait class.""" +"""Tests for the SmartWashParamsTrait class.""" from unittest.mock import AsyncMock, call import pytest +from roborock.data import RoborockDockSmartWashModeCode, RoborockProductNickname from roborock.data.v1.v1_code_mappings import ( RoborockDockTypeCode, ) from roborock.devices.device import RoborockDevice -from roborock.devices.traits.v1.smart_wash_params import SmartWashParamsTrait +from roborock.devices.traits.v1.smart_wash_params import SmartWashParamsTrait, get_wash_interval_options +from roborock.exceptions import RoborockException, RoborockUnsupportedFeature from roborock.roborock_typing import RoborockCommand from tests.devices.traits.v1.helpers import dock_types_with_capability -SMART_WASH_DATA = [{"smart_wash": 5, "wash_interval": 6}] +# Saros 10R: wash the mop after every room, interval 1200 s kept for the time mode +SMART_WASH_DATA = [{"smart_wash": 1, "wash_interval": 1200}] +SAROS_10R_DOCK = RoborockDockTypeCode.shell_3s_dock +# 10 to 50 minutes in 5 minute steps +OLD_WASH_INTERVALS = [600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000] + + +@pytest.fixture(name="product_model") +def product_model_fixture() -> str: + """Default to the Saros 10R, which has the four interval buttons.""" + return "roborock.vacuum.a144" + + +@pytest.mark.parametrize( + ("product_nickname", "expected"), + [ + (RoborockProductNickname.CORALPRO, [600, 900, 1200, 1500]), # Saros 10R + (RoborockProductNickname.PEARLPLUS, [600, 900, 1200, 1500]), + (RoborockProductNickname.TOPAZS, OLD_WASH_INTERVALS), + (RoborockProductNickname.TOPAZSV, OLD_WASH_INTERVALS), + (RoborockProductNickname.TOPAZSPLUS, OLD_WASH_INTERVALS), + (RoborockProductNickname.TOPAZSC, OLD_WASH_INTERVALS), + (RoborockProductNickname.TOPAZSPOWER, OLD_WASH_INTERVALS), + (RoborockProductNickname.ULTRONSPLUS, OLD_WASH_INTERVALS), + ], +) +def test_get_wash_interval_options(product_nickname: RoborockProductNickname, expected: list[int]) -> None: + """Test the wash intervals offered for each product.""" + assert get_wash_interval_options(product_nickname) == expected + + +@pytest.mark.parametrize(("product_model"), ["roborock.vacuum.a27"]) # S7 MaxV (TopazSV) +@pytest.mark.parametrize(("dock_type_code"), [RoborockDockTypeCode.o6_dock]) +async def test_old_product_wash_intervals( + smart_wash_params: SmartWashParamsTrait | None, + mock_rpc_channel: AsyncMock, + product_model: str, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that an older product offers and accepts the longer wash intervals.""" + assert smart_wash_params is not None + assert smart_wash_params.wash_interval_options == OLD_WASH_INTERVALS + + await smart_wash_params.set_smart_wash_params(RoborockDockSmartWashModeCode.by_time, 3000) + + mock_rpc_channel.send_command.assert_called_once_with( + RoborockCommand.SET_SMART_WASH_PARAMS, params={"smart_wash": 0, "wash_interval": 3000} + ) + with pytest.raises(RoborockUnsupportedFeature): + await smart_wash_params.set_smart_wash_params(RoborockDockSmartWashModeCode.by_time, 3300) @pytest.fixture(name="smart_wash_params") @@ -53,8 +104,8 @@ async def test_smart_wash_available( ) # Verify the summary object contains the traits - assert smart_wash_params.smart_wash == 5 - assert smart_wash_params.wash_interval == 6 + assert smart_wash_params.smart_wash == RoborockDockSmartWashModeCode.by_room + assert smart_wash_params.wash_interval == 1200 @pytest.mark.parametrize( @@ -66,3 +117,126 @@ async def test_unsupported_smart_wash_params( ) -> None: """Test successfully refreshing the dock summary.""" assert smart_wash_params is None + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +async def test_refresh_unknown_code( + smart_wash_params: SmartWashParamsTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that refresh tolerates an unknown smart wash mode code.""" + assert smart_wash_params is not None + mock_rpc_channel.send_command.side_effect = [[{"smart_wash": 7, "wash_interval": 1200}]] + + await smart_wash_params.refresh() + + assert smart_wash_params.smart_wash == RoborockDockSmartWashModeCode.unknown + assert smart_wash_params.wash_interval == 1200 + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("new_smart_supported", "expected"), + [ + (False, [RoborockDockSmartWashModeCode.by_time, RoborockDockSmartWashModeCode.by_room]), + ( + True, + [ + RoborockDockSmartWashModeCode.by_time, + RoborockDockSmartWashModeCode.by_room, + RoborockDockSmartWashModeCode.new_smart, + ], + ), + ], +) +async def test_smart_wash_mode_options( + device: RoborockDevice, + smart_wash_params: SmartWashParamsTrait | None, + dock_type_code: RoborockDockTypeCode, + new_smart_supported: bool, + expected: list[RoborockDockSmartWashModeCode], +) -> None: + """Test that the new smart mode is offered only with its device feature.""" + assert device.v1_properties + assert smart_wash_params is not None + device.v1_properties.device_features.is_back_wash_new_smart_supported = new_smart_supported + + assert smart_wash_params.smart_wash_mode_options == expected + assert smart_wash_params.wash_interval_options == [600, 900, 1200, 1500] + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("mode", "wash_interval"), + [ + (RoborockDockSmartWashModeCode.by_room, 1200), + (RoborockDockSmartWashModeCode.by_time, 900), + (RoborockDockSmartWashModeCode.by_time, 600), + (RoborockDockSmartWashModeCode.by_time, 1500), + ], +) +async def test_set_smart_wash_params( + smart_wash_params: SmartWashParamsTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + mode: RoborockDockSmartWashModeCode, + wash_interval: int, +) -> None: + """Test setting an offered smart wash mode and interval.""" + assert smart_wash_params is not None + + await smart_wash_params.set_smart_wash_params(mode, wash_interval) + + mock_rpc_channel.send_command.assert_called_once_with( + RoborockCommand.SET_SMART_WASH_PARAMS, params={"smart_wash": mode.value, "wash_interval": wash_interval} + ) + assert smart_wash_params.smart_wash == mode + assert smart_wash_params.wash_interval == wash_interval + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +@pytest.mark.parametrize( + ("mode", "wash_interval"), + [ + (RoborockDockSmartWashModeCode.new_smart, 1200), + (RoborockDockSmartWashModeCode.unknown, 1200), + (RoborockDockSmartWashModeCode.by_time, 1000), + ], +) +async def test_set_rejects_unoffered( + device: RoborockDevice, + smart_wash_params: SmartWashParamsTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, + mode: RoborockDockSmartWashModeCode, + wash_interval: int, +) -> None: + """Test that a mode or interval the device does not offer is rejected without sending.""" + assert device.v1_properties + assert smart_wash_params is not None + device.v1_properties.device_features.is_back_wash_new_smart_supported = False + + with pytest.raises(RoborockUnsupportedFeature): + await smart_wash_params.set_smart_wash_params(mode, wash_interval) + + mock_rpc_channel.send_command.assert_not_called() + + +@pytest.mark.parametrize(("dock_type_code"), [SAROS_10R_DOCK]) +async def test_set_failure_keeps_state( + smart_wash_params: SmartWashParamsTrait | None, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a failed command leaves the smart wash params unchanged.""" + assert smart_wash_params is not None + smart_wash_params.smart_wash = RoborockDockSmartWashModeCode.by_room + smart_wash_params.wash_interval = 1200 + mock_rpc_channel.send_command.side_effect = RoborockException("boom") + + with pytest.raises(RoborockException): + await smart_wash_params.set_smart_wash_params(RoborockDockSmartWashModeCode.by_time, 900) + + assert smart_wash_params.smart_wash == RoborockDockSmartWashModeCode.by_room + assert smart_wash_params.wash_interval == 1200 From f09674d4a536fe2d21b5d98a2792d691878197ba Mon Sep 17 00:00:00 2001 From: infy1995 Date: Thu, 12 Nov 2026 21:34:43 +0100 Subject: [PATCH 4/4] feat: add V1 wash tray self-clean and wash mode validation Add self_clean_tray() so consumers can start the dock's tray self-clean, and reject wash towel modes the device does not offer instead of sending them. stop_wash() also stops a running self-clean. --- docs/V1_API_COMMANDS.md | 42 +++++++++---- roborock/devices/traits/v1/wash_towel_mode.py | 14 ++++- .../devices/traits/v1/test_wash_towel_mode.py | 59 +++++++++++++++++++ 3 files changed, 102 insertions(+), 13 deletions(-) diff --git a/docs/V1_API_COMMANDS.md b/docs/V1_API_COMMANDS.md index 9bdad0bd3..ad87a1422 100644 --- a/docs/V1_API_COMMANDS.md +++ b/docs/V1_API_COMMANDS.md @@ -6,6 +6,7 @@ Commands do not immediately make it to this page. You can find more commands [he Commands can have multiple parameters that can change from one model to another. +* [app_amethyst_self_check](#app_amethyst_self_check) * [app_charge](#app_charge) * [app_get_dryer_setting](#app_get_dryer_setting) * [app_get_init_status](#app_get_init_status) @@ -271,13 +272,15 @@ Parameters: None ### app_stop_wash -Description: This stops washing the mop whiloe docked +Description: This stops washing the mop whiloe docked. It also stops a running wash tray self-clean +([app_amethyst_self_check](#app_amethyst_self_check)). Parameters: None **Supported devices:** * Roborock S8 Pro Ultra: ✅ +* Roborock Saros 10R: ✅ ### app_goto_target @@ -1468,7 +1471,7 @@ Parameters: None Returns: - wash_mode: + wash_mode: 0 light, 1 balanced, 2 deep, 8 super deep, 10 smart Return example: @@ -1476,22 +1479,14 @@ Return example: {'wash_mode': 1} ``` -Source: Roborock S7 MaxV Ultra - - - unknown = -9999 - - light = 0 - - balanced = 1 - - deep = 2 +Source: Roborock S7 MaxV Ultra; smart (10) seen on the Roborock Saros 10R **Supported devices:** * Roborock S7 MaxV Ultra: ✅ * Roborock S8 Pro Ultra: ✅ +* Roborock Saros 10R: ✅ ### set_wash_towel_mode @@ -1500,6 +1495,9 @@ Description: Sets the wash wash_towel_mode Parameters: {'wash_mode': 2} + wash_mode: 0 light, 1 balanced, 2 deep, 8 super deep, 10 smart. Super deep and smart are offered only on + devices that support them. + Returns: ok or error Source: S8 Pro Ultra @@ -1508,6 +1506,26 @@ Source: S8 Pro Ultra * Roborock S7 MaxV Ultra: ✅ * Roborock S8 Pro Ultra: ✅ +* Roborock Saros 10R: ✅ (light, balanced and deep set and confirmed in the app) + +### app_amethyst_self_check + +Description: Start the self-clean of the dock's mop wash tray (app: tray self-cleaning). Offered on docks with a +self-cleaning wash carousel, such as the Saros 10R dock (dock type 16). + +Parameters: None + +Returns: ok or error + +While it runs, `get_status` reports `state` 23 (washing the mop) and `wash_phase` 11, the same as when the +self-clean is started from the app. The dock needs clean water (`dock_error_status` 38, water empty, otherwise). +It ends by itself after about a minute; `app_stop_wash` stops it early, like the stop button in the app. + +Source: Roborock Saros 10R, Roborock app plugin + +**Supported devices:** + +* Roborock Saros 10R: ✅ ### get_wash_water_temperature diff --git a/roborock/devices/traits/v1/wash_towel_mode.py b/roborock/devices/traits/v1/wash_towel_mode.py index a97ae6cb0..3cbf4719f 100644 --- a/roborock/devices/traits/v1/wash_towel_mode.py +++ b/roborock/devices/traits/v1/wash_towel_mode.py @@ -7,6 +7,7 @@ from roborock.device_features import RoborockDockFeatures from roborock.devices.traits.v1 import common from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait +from roborock.exceptions import RoborockUnsupportedFeature from roborock.roborock_typing import RoborockCommand @@ -42,6 +43,8 @@ def wash_towel_mode_options(self) -> list[WashTowelModes]: async def set_wash_towel_mode(self, mode: WashTowelModes) -> None: """Set the wash towel mode.""" + if mode not in self.wash_towel_mode_options: + raise RoborockUnsupportedFeature(f"Wash towel mode {mode.value} is not supported") await self.rpc_channel.send_command(RoborockCommand.SET_WASH_TOWEL_MODE, params={"wash_mode": mode.code}) # Optimistic update to avoid an extra refresh self.wash_mode = mode @@ -51,5 +54,14 @@ async def start_wash(self) -> None: await self.rpc_channel.send_command(RoborockCommand.APP_START_WASH) async def stop_wash(self) -> None: - """Stop washing the mop.""" + """Stop washing the mop. Also stops a running wash tray self-clean.""" await self.rpc_channel.send_command(RoborockCommand.APP_STOP_WASH) + + async def self_clean_tray(self) -> None: + """Start the self-clean of the dock's mop wash tray (app: tray self-cleaning). + + It runs for about a minute; `stop_wash()` stops it early, as the app's stop button does. + """ + if not self.device_feature_trait.dock_features.is_clean_carousel_self_clean_supported: + raise RoborockUnsupportedFeature("Wash tray self-clean is not supported by this dock") + await self.rpc_channel.send_command(RoborockCommand.APP_AMETHYST_SELF_CHECK) diff --git a/tests/devices/traits/v1/test_wash_towel_mode.py b/tests/devices/traits/v1/test_wash_towel_mode.py index 637992c66..1b6f2ff5b 100644 --- a/tests/devices/traits/v1/test_wash_towel_mode.py +++ b/tests/devices/traits/v1/test_wash_towel_mode.py @@ -10,6 +10,7 @@ ) from roborock.devices.device import RoborockDevice from roborock.devices.traits.v1.wash_towel_mode import WashTowelModeTrait +from roborock.exceptions import RoborockUnsupportedFeature from roborock.roborock_typing import RoborockCommand from tests.devices.traits.v1.helpers import dock_types_with_capability @@ -83,6 +84,8 @@ async def test_set_wash_towel_mode( ) -> None: """Test setting the wash towel mode.""" assert wash_towel_mode is not None + # Offer the smart mode, as on the Saros 10R + wash_towel_mode.device_feature_trait.is_dirty_replenish_clean_supported = True await wash_towel_mode.set_wash_towel_mode(wash_mode) @@ -190,3 +193,59 @@ async def test_wash_towel_mode_options( wash_towel_mode.device_feature_trait.is_dirty_replenish_clean_supported = is_dirty_replenish_clean_supported assert wash_towel_mode.wash_towel_mode_options == expected_modes + + +@pytest.mark.parametrize( + ("dock_type_code"), + [(RoborockDockTypeCode.o4_dock)], +) +async def test_set_wash_towel_mode_rejects_unoffered( + wash_towel_mode: WashTowelModeTrait, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that a wash mode the device does not offer is rejected without sending.""" + assert wash_towel_mode is not None + wash_towel_mode.device_feature_trait.is_super_deep_wash_supported = True + wash_towel_mode.device_feature_trait.is_dirty_replenish_clean_supported = True + assert WashTowelModes.SUPER_DEEP not in wash_towel_mode.wash_towel_mode_options + + with pytest.raises(RoborockUnsupportedFeature): + await wash_towel_mode.set_wash_towel_mode(WashTowelModes.SUPER_DEEP) + + mock_rpc_channel.send_command.assert_not_called() + + +@pytest.mark.parametrize( + ("dock_type_code"), + [(RoborockDockTypeCode.shell_3s_dock)], +) +async def test_self_clean_tray( + wash_towel_mode: WashTowelModeTrait, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test starting the wash tray self-clean on a dock with the carousel.""" + assert wash_towel_mode is not None + + await wash_towel_mode.self_clean_tray() + + mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.APP_AMETHYST_SELF_CHECK) + + +@pytest.mark.parametrize( + ("dock_type_code"), + [(RoborockDockTypeCode.o4_dock)], +) +async def test_self_clean_tray_unsupported( + wash_towel_mode: WashTowelModeTrait, + mock_rpc_channel: AsyncMock, + dock_type_code: RoborockDockTypeCode, +) -> None: + """Test that the tray self-clean is rejected without sending on a dock without the carousel.""" + assert wash_towel_mode is not None + + with pytest.raises(RoborockUnsupportedFeature): + await wash_towel_mode.self_clean_tray() + + mock_rpc_channel.send_command.assert_not_called()