Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/V1_DEVICE_FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions roborock/data/v1/v1_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions roborock/device_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions roborock/devices/traits/v1/consumeable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/devices/traits/v1/__snapshots__/test_device_features.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
# ---
25 changes: 24 additions & 1 deletion tests/devices/traits/v1/test_device_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Loading