Skip to content

Commit be749e4

Browse files
committed
feat: add V1 wash water temperature trait
1 parent 4f7f77c commit be749e4

7 files changed

Lines changed: 460 additions & 3 deletions

File tree

‎docs/V1_API_COMMANDS.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Commands can have multiple parameters that can change from one model to another.
5252
* [get_turn_server](#get_turn_server)
5353
* [get_valley_electricity_timer](#get_valley_electricity_timer)
5454
* [get_wash_towel_mode](#get_wash_towel_mode)
55+
* [get_wash_water_temperature](#get_wash_water_temperature)
5556
* [load_multi_map](#load_multi_map)
5657
* [name_segment](#name_segment)
5758
* [reset_consumable](#reset_consumable)
@@ -80,6 +81,7 @@ Commands can have multiple parameters that can change from one model to another.
8081
* [set_timezone](#set_timezone)
8182
* [set_valley_electricity_timer](#set_valley_electricity_timer)
8283
* [set_wash_towel_mode](#set_wash_towel_mode)
84+
* [set_wash_water_temperature](#set_wash_water_temperature)
8385
* [set_water_box_custom_mode](#set_water_box_custom_mode)
8486
* [start_camera_preview](#start_camera_preview)
8587
* [start_edit_map](#start_edit_map)
@@ -1328,6 +1330,53 @@ Source: S8 Pro Ultra
13281330
* Roborock S7 MaxV Ultra: ✅
13291331
* Roborock S8 Pro Ultra: ✅
13301332

1333+
### get_wash_water_temperature
1334+
1335+
Description: Get the water temperature the dock uses to wash the mop (app: water temperature). Available on
1336+
washing docks of devices with the hot wash towel feature (`is_hot_wash_towel_supported`). Not available on the
1337+
PearlE Pro (a169/a170) unless the dock is a Shell2E Lite.
1338+
1339+
Parameters: None
1340+
1341+
Returns:
1342+
1343+
wash_water_temperature: 0 room temperature, 1 warm, 2 hot, 3 steam, 4 pet steam.
1344+
Docks offer 0 and 2; 1 only on docks with neither high temperature water nor steam; 3 only on steam docks.
1345+
1346+
Return example:
1347+
1348+
```json
1349+
{'wash_water_temperature': 2}
1350+
```
1351+
1352+
Source: Roborock Saros 10R
1353+
1354+
**Supported devices:**
1355+
1356+
* Roborock Saros 10R: ✅
1357+
1358+
### set_wash_water_temperature
1359+
1360+
Description: Set the water temperature the dock uses to wash the mop.
1361+
1362+
Parameters:
1363+
1364+
values: 0 room temperature, 1 warm, 2 hot, 3 steam, 4 pet steam.
1365+
The key differs from the one `get_wash_water_temperature` returns; `{'wash_water_temperature': 2}` is
1366+
rejected with -10007 invalid params.
1367+
1368+
Example:
1369+
1370+
```json
1371+
{'values': 2}
1372+
```
1373+
1374+
Source: Roborock Saros 10R
1375+
1376+
**Supported devices:**
1377+
1378+
* Roborock Saros 10R: ✅
1379+
13311380
### get_collision_avoid_status
13321381

13331382
Description:

‎roborock/data/v1/v1_code_mappings.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,17 @@ class RoborockDockDustCollectionFrequencyCode(RoborockEnum):
418418
high = 2
419419

420420

421+
class RoborockDockWashWaterTemperatureCode(RoborockEnum):
422+
"""Describes the water temperature the dock uses to wash the mop (app: water temperature)."""
423+
424+
unknown = -1
425+
room_temperature = 0
426+
warm = 1
427+
hot = 2
428+
steam = 3
429+
pet_steam = 4
430+
431+
421432
class RoborockStateCode(RoborockEnum):
422433
unknown = 0
423434
starting = 1

‎roborock/data/v1/v1_containers.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
RoborockDockErrorCode,
3333
RoborockDockState,
3434
RoborockDockTypeCode,
35+
RoborockDockWashWaterTemperatureCode,
3536
RoborockErrorCode,
3637
RoborockFinishReason,
3738
RoborockInCleaning,
@@ -484,6 +485,13 @@ class SmartWashParams(RoborockBase):
484485
wash_interval: int | None = None
485486

486487

488+
@dataclass
489+
class WashWaterTemperature(RoborockBase):
490+
"""Mop wash water temperature, as returned by GET_WASH_WATER_TEMPERATURE."""
491+
492+
wash_water_temperature: RoborockDockWashWaterTemperatureCode | None = None
493+
494+
487495
@dataclass
488496
class MopDryerProfile(RoborockBase):
489497
"""Dryer parameters for one state of the auto mop-drying setting."""

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
valley_electricity_timer,
100100
volume,
101101
wash_towel_mode,
102+
wash_water_temperature,
102103
)
103104
from .child_lock import ChildLockTrait
104105
from .clean_summary import CleanSummaryTrait
@@ -125,6 +126,7 @@
125126
from .valley_electricity_timer import ValleyElectricityTimerTrait
126127
from .volume import SoundVolumeTrait
127128
from .wash_towel_mode import WashTowelModeTrait
129+
from .wash_water_temperature import WashWaterTemperatureTrait, is_wash_water_temperature_offered
128130

129131
_LOGGER = logging.getLogger(__name__)
130132

@@ -155,6 +157,7 @@
155157
"valley_electricity_timer",
156158
"volume",
157159
"wash_towel_mode",
160+
"wash_water_temperature",
158161
]
159162

160163

@@ -189,6 +192,7 @@ class PropertiesApi(Trait):
189192
dust_collection: DustCollectionTrait | None = None
190193
wash_towel_mode: WashTowelModeTrait | None = None
191194
smart_wash_params: SmartWashParamsTrait | None = None
195+
wash_water_temperature: WashWaterTemperatureTrait | None = None
192196
obstacle_photos: ObstaclePhotoTrait | None = None
193197
mop_dryer: MopDryerTrait | None = None
194198
customize_clean_mode: CustomizeCleanModeTrait | None = None
@@ -210,6 +214,7 @@ def __init__(
210214
) -> None:
211215
"""Initialize the V1TraitProps."""
212216
self._device_uid = device_uid
217+
self._product = product
213218
self._rpc_channel = rpc_channel
214219
self._mqtt_rpc_channel = mqtt_rpc_channel
215220
self._map_rpc_channel = map_rpc_channel
@@ -297,6 +302,18 @@ async def discover_features(self) -> None:
297302
wash_towel_mode._rpc_channel = self._get_rpc_channel(wash_towel_mode) # type: ignore[assignment]
298303
self.wash_towel_mode = wash_towel_mode
299304

305+
# The wash water temperature needs a washing dock, a device that can heat wash water,
306+
# and a product and dock for which the app shows it.
307+
if (
308+
self.wash_water_temperature is None
309+
and self.device_features.is_hot_wash_towel_supported
310+
and is_wash_water_temperature_offered(self._product.product_nickname, dock_features)
311+
and self._is_supported(WashWaterTemperatureTrait, "wash_water_temperature", dock_features)
312+
):
313+
wash_water_temperature = WashWaterTemperatureTrait(self.device_features)
314+
wash_water_temperature._rpc_channel = self._get_rpc_channel(wash_water_temperature) # type: ignore[assignment]
315+
self.wash_water_temperature = wash_water_temperature
316+
300317
# The dust collection mode needs both device and dock features
301318
if self.dust_collection_mode is None and supports_dust_collection_mode(self.device_features, dock_features):
302319
dust_collection_mode = DustCollectionModeTrait()
@@ -332,7 +349,7 @@ async def discover_features(self) -> None:
332349
# Union args may not be in declared order
333350
item_type = union_args[0] if union_args[1] is type(None) else union_args[1]
334351
# Created above with constructor arguments or extra gating
335-
if item_type in (ObstaclePhotoTrait, DustCollectionModeTrait):
352+
if item_type in (ObstaclePhotoTrait, DustCollectionModeTrait, WashWaterTemperatureTrait):
336353
continue
337354
if not self._is_supported(item_type, item.name, dock_features):
338355
_LOGGER.debug("Trait '%s' not supported, skipping", item.name)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Trait for the mop wash water temperature."""
2+
3+
from roborock.data import (
4+
RoborockDockTypeCode,
5+
RoborockDockWashWaterTemperatureCode,
6+
RoborockProductNickname,
7+
WashWaterTemperature,
8+
)
9+
from roborock.device_features import RoborockDockFeatures
10+
from roborock.devices.traits.v1 import common
11+
from roborock.devices.traits.v1.device_features import DeviceFeaturesTrait
12+
from roborock.exceptions import RoborockUnsupportedFeature
13+
from roborock.roborock_typing import RoborockCommand
14+
15+
16+
def get_wash_water_temperatures(dock_features: RoborockDockFeatures) -> list[RoborockDockWashWaterTemperatureCode]:
17+
"""Return the wash water temperatures the app offers for a dock, in app order.
18+
19+
Warm is offered only by docks with neither high temperature water nor steam; steam
20+
only by steam docks. Pet steam is never offered. Known exception: the app for the UltronSV
21+
(a97) also shows warm on its high temperature docks; that needs plugin family detection.
22+
"""
23+
options = [RoborockDockWashWaterTemperatureCode.room_temperature]
24+
if not dock_features.is_high_tmp_water_supported and not dock_features.is_steam_wash_supported:
25+
options.append(RoborockDockWashWaterTemperatureCode.warm)
26+
options.append(RoborockDockWashWaterTemperatureCode.hot)
27+
if dock_features.is_steam_wash_supported:
28+
options.append(RoborockDockWashWaterTemperatureCode.steam)
29+
return options
30+
31+
32+
def is_wash_water_temperature_offered(
33+
product_nickname: RoborockProductNickname, dock_features: RoborockDockFeatures
34+
) -> bool:
35+
"""Return whether the app shows the wash water temperature for this product and dock.
36+
37+
The app hides it on the PearlE Pro (``PEARLELITE``) unless the dock is a Shell2E Lite.
38+
"""
39+
return (
40+
product_nickname != RoborockProductNickname.PEARLELITE
41+
or dock_features.dock_type == RoborockDockTypeCode.shell_2e_lite_dock
42+
)
43+
44+
45+
def _supports_wash_water_temperature(dock_features: RoborockDockFeatures) -> bool:
46+
return dock_features.is_washable
47+
48+
49+
class WashWaterTemperatureTrait(WashWaterTemperature, common.V1TraitMixin):
50+
"""Water temperature the dock uses to wash the mop (app: water temperature).
51+
52+
Created only for washing docks on devices with ``is_hot_wash_towel_supported``, and
53+
when ``is_wash_water_temperature_offered`` allows it.
54+
"""
55+
56+
command = RoborockCommand.GET_WASH_WATER_TEMPERATURE
57+
converter = common.DefaultConverter(WashWaterTemperature)
58+
requires_dock_features = _supports_wash_water_temperature
59+
60+
def __init__(self, device_feature_trait: DeviceFeaturesTrait) -> None:
61+
super().__init__()
62+
self.device_feature_trait = device_feature_trait
63+
64+
@property
65+
def wash_water_temperature_options(self) -> list[RoborockDockWashWaterTemperatureCode]:
66+
"""Return the wash water temperatures offered by the dock."""
67+
return get_wash_water_temperatures(self.device_feature_trait.dock_features)
68+
69+
async def set_wash_water_temperature(self, temperature: RoborockDockWashWaterTemperatureCode) -> None:
70+
"""Set the mop wash water temperature."""
71+
if temperature not in self.wash_water_temperature_options:
72+
raise RoborockUnsupportedFeature(f"Wash water temperature {temperature.name} is not supported")
73+
# The device reads back "wash_water_temperature" but expects the new value under "values".
74+
await self.rpc_channel.send_command(
75+
RoborockCommand.SET_WASH_WATER_TEMPERATURE, params={"values": temperature.value}
76+
)
77+
# Optimistic update to avoid an extra refresh
78+
self.wash_water_temperature = temperature

‎tests/devices/traits/v1/fixtures.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Fixtures for V1 trait tests."""
22

33
from copy import deepcopy
4+
from dataclasses import replace
45
from unittest.mock import AsyncMock, Mock
56

67
import pytest
@@ -76,10 +77,25 @@ def device_info_fixture(trait_home_data: HomeData) -> HomeDataDevice:
7677
return trait_home_data.get_all_devices()[0]
7778

7879

80+
@pytest.fixture(name="product_model")
81+
def product_model_fixture() -> str | None:
82+
"""Model of the test device's product, e.g. "roborock.vacuum.a144".
83+
84+
None keeps the fixture's model: the S7 MaxV (a27, TopazSV), which the app treats as an older product.
85+
"""
86+
return None
87+
88+
7989
@pytest.fixture(name="products")
80-
def products_fixture() -> list[HomeDataProduct]:
90+
def products_fixture(device_info: HomeDataDevice, product_model: str | None) -> list[HomeDataProduct]:
8191
"""Fixture to provide a Product instance for tests."""
82-
return [HomeDataProduct.from_dict(product) for product in mock_data.PRODUCTS.values()]
92+
products = [HomeDataProduct.from_dict(product) for product in mock_data.PRODUCTS.values()]
93+
if product_model is None:
94+
return products
95+
return [
96+
replace(product, model=product_model) if product.id == device_info.product_id else product
97+
for product in products
98+
]
8399

84100

85101
@pytest.fixture(autouse=True, name="device")

0 commit comments

Comments
 (0)