diff --git a/docs/V1_DEVICE_FEATURES.md b/docs/V1_DEVICE_FEATURES.md index 2e3576409..d682fb815 100644 --- a/docs/V1_DEVICE_FEATURES.md +++ b/docs/V1_DEVICE_FEATURES.md @@ -1482,6 +1482,11 @@ Other capabilities depend only on the code: **Docks:** Pearl, Couple, Hera, Shell (except Shell 4R), K1 and F-series docks; none of the O-series docks. **Description:** The dock has a carousel (wash tray strainer) that the app shows as a consumable. +### is_strainer_supported +**Also enabled by:** `is_clean_carousel_supported`, `is_only_x_series` +**Docks:** Carousel docks and O-series docks; not Shell 4R. +**Description:** The dock has a wash tray strainer. It gates `Consumable.strainer_work_times`. + ### is_special_support_wash_temp **Docks:** Shell 2E Lite **Description:** Dock part of the app's check of the same name. The app also checks the product: it is true for every diff --git a/roborock/data/v1/v1_containers.py b/roborock/data/v1/v1_containers.py index 91dc98f0b..6be9f909c 100644 --- a/roborock/data/v1/v1_containers.py +++ b/roborock/data/v1/v1_containers.py @@ -356,13 +356,15 @@ class ConsumableField(FieldNameBase): to understand if a feature is supported by the device using `is_field_supported`. The enum values are names of fields in the `Consumable` class. Each field is - annotated with `dps` metadata to map the field to a `RoborockDataProtocol` - value used to check support against the product schema. + annotated with `dps` metadata (checked against the product schema) or + `dock_feature` metadata (checked against `RoborockDockFeatures`). """ MAIN_BRUSH_WORK_TIME = "main_brush_work_time" SIDE_BRUSH_WORK_TIME = "side_brush_work_time" FILTER_WORK_TIME = "filter_work_time" + STRAINER_WORK_TIME = "strainer_work_times" + CLEANING_BRUSH_WORK_TIME = "cleaning_brush_work_times" @dataclass @@ -372,9 +374,11 @@ class Consumable(RoborockBase): filter_work_time: int | None = field(default=None, metadata={"dps": RoborockDataProtocol.FILTER_WORK_TIME}) filter_element_work_time: int | None = None sensor_dirty_time: int | None = None - strainer_work_times: int | None = None + strainer_work_times: int | None = field(default=None, metadata={"dock_feature": "is_strainer_supported"}) dust_collection_work_times: int | None = None - cleaning_brush_work_times: int | None = None + cleaning_brush_work_times: int | None = field( + default=None, metadata={"dock_feature": "is_cleaning_brush_supported"} + ) moproller_work_time: int | None = None @property diff --git a/roborock/device_features.py b/roborock/device_features.py index aa907ed6a..37cfdd87d 100644 --- a/roborock/device_features.py +++ b/roborock/device_features.py @@ -1019,6 +1019,11 @@ def is_only_x_series(self) -> bool: def is_cleaning_brush_supported(self) -> bool: return self.is_only_x_series + @property + def is_strainer_supported(self) -> bool: + """Whether the dock has a wash tray strainer: a carousel dock or an O-series dock.""" + return self.is_clean_carousel_supported or self.is_only_x_series + @property def is_clean_fluid_auto_delivery_supported(self) -> bool: return self.dock_type in _CLEAN_FLUID_AUTO_DELIVERY_DOCK_TYPES or self._matches_am_variant( diff --git a/roborock/devices/traits/v1/consumeable.py b/roborock/devices/traits/v1/consumeable.py index 70d0a7429..9599668ee 100644 --- a/roborock/devices/traits/v1/consumeable.py +++ b/roborock/devices/traits/v1/consumeable.py @@ -45,8 +45,8 @@ def from_str(cls, value: str) -> Self: class ConsumableTrait(Consumable, common.V1TraitMixin, TraitUpdateListener): """Trait for managing consumable attributes on Roborock devices. - After the first refresh, you can tell what consumables are supported by - checking which attributes are not None. + Use `DeviceFeaturesTrait.is_field_supported` to check whether the device + supports a consumable listed in `ConsumableField`. """ command = RoborockCommand.GET_CONSUMABLE diff --git a/tests/devices/traits/v1/__snapshots__/test_device_features.ambr b/tests/devices/traits/v1/__snapshots__/test_device_features.ambr index 59c4208f6..f46d89fbf 100644 --- a/tests/devices/traits/v1/__snapshots__/test_device_features.ambr +++ b/tests/devices/traits/v1/__snapshots__/test_device_features.ambr @@ -181,64 +181,82 @@ # --- # name: test_is_consumable_field_supported[home_data_device_p30_pro.json] dict({ + 'cleaning_brush_work_times': False, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- # name: test_is_consumable_field_supported[home_data_device_pearls.json] dict({ + 'cleaning_brush_work_times': False, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- # name: test_is_consumable_field_supported[home_data_device_q5_max.json] dict({ + 'cleaning_brush_work_times': False, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': False, }) # --- # name: test_is_consumable_field_supported[home_data_device_q_revo.json] dict({ + 'cleaning_brush_work_times': False, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- # name: test_is_consumable_field_supported[home_data_device_qrevo_2_pro.json] dict({ + 'cleaning_brush_work_times': False, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- # name: test_is_consumable_field_supported[home_data_device_s5e.json] dict({ + 'cleaning_brush_work_times': False, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': False, }) # --- # name: test_is_consumable_field_supported[home_data_device_s7_maxv.json] dict({ + 'cleaning_brush_work_times': True, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- # name: test_is_consumable_field_supported[home_data_device_saros.json] dict({ + 'cleaning_brush_work_times': True, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- # name: test_is_consumable_field_supported[home_data_device_saros_10r.json] dict({ + 'cleaning_brush_work_times': True, 'filter_work_time': True, 'main_brush_work_time': True, 'side_brush_work_time': True, + 'strainer_work_times': True, }) # --- diff --git a/tests/devices/traits/v1/test_device_features.py b/tests/devices/traits/v1/test_device_features.py index 18bfc0f2a..36e88f88e 100644 --- a/tests/devices/traits/v1/test_device_features.py +++ b/tests/devices/traits/v1/test_device_features.py @@ -5,7 +5,7 @@ import pytest from syrupy import SnapshotAssertion -from roborock.data import HomeDataDevice +from roborock.data import HomeDataDevice, RoborockDockTypeCode from roborock.data.v1.v1_containers import ConsumableField, StatusField from roborock.devices.cache import DeviceCache from roborock.devices.device import RoborockDevice @@ -63,6 +63,29 @@ async def test_is_consumable_field_supported( assert is_v1_supported == snapshot +@pytest.mark.parametrize( + ("dock_type_code", "field", "expected"), + [ + (RoborockDockTypeCode.shell_4r_dock, ConsumableField.STRAINER_WORK_TIME, False), + (RoborockDockTypeCode.shell_4s_dock, ConsumableField.STRAINER_WORK_TIME, True), + (RoborockDockTypeCode.o4_dock, ConsumableField.STRAINER_WORK_TIME, True), + (RoborockDockTypeCode.o1_dock, ConsumableField.STRAINER_WORK_TIME, False), + (RoborockDockTypeCode.o4_dock, ConsumableField.CLEANING_BRUSH_WORK_TIME, True), + (RoborockDockTypeCode.shell_4r_dock, ConsumableField.CLEANING_BRUSH_WORK_TIME, False), + ], +) +async def test_is_dock_consumable_field_supported( + device: RoborockDevice, + discover_features_fixture: None, + dock_type_code: RoborockDockTypeCode, + field: ConsumableField, + expected: bool, +) -> None: + """Test dock consumable support follows the dock type.""" + assert device.v1_properties is not None + assert device.v1_properties.device_features.is_field_supported(ConsumableTrait, field) is expected + + @pytest.mark.parametrize("payload", [[], ["ok"]], ids=["empty", "non-dict"]) async def test_refresh_unexpected_list_keeps_state( device: RoborockDevice,