Skip to content

Commit 9299567

Browse files
committed
refactor: back MopDryerTrait with the dryer setting instead of device status
Model the trait on APP_GET_DRYER_SETTING with a MopDryerSetting dataclass so it fulfils the V1TraitMixin contract (command, converter, dataclass fields) rather than borrowing state from StatusTrait. The switch now controls the auto mop-drying setting: is_on reflects `status`, and enable/disable send APP_SET_DRYER_SETTING with a partial `{"status": N}`, which the device accepts and merges without touching the `on`/`off` profiles. Starting and stopping a drying cycle directly moves to start_dry/stop_dry via APP_SET_DRYER_STATUS. Whether a cycle is running remains reported by `dry_status` on the device status. The trait no longer takes constructor arguments, so it is created by the generic discovery loop and the special-case block in discover_features is removed. Tests assert only on the commands sent and the trait's own state; the refresh test uses a payload captured from a real dock.
1 parent 4c4e914 commit 9299567

4 files changed

Lines changed: 117 additions & 59 deletions

File tree

‎roborock/data/v1/v1_containers.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,28 @@ class SmartWashParams(RoborockBase):
459459
wash_interval: int | None = None
460460

461461

462+
@dataclass
463+
class MopDryerProfile(RoborockBase):
464+
"""Dryer parameters for one state of the auto mop-drying setting."""
465+
466+
cliff_on: int | None = None
467+
cliff_off: int | None = None
468+
count: int | None = None
469+
dry_time: int | None = None
470+
"""Drying duration in seconds. Only present in the ``on`` profile."""
471+
dry_heating_film_time: int | None = None
472+
"""Heating element run time in seconds. Only present in the ``on`` profile."""
473+
474+
475+
@dataclass
476+
class MopDryerSetting(RoborockBase):
477+
"""Auto mop-drying setting, as returned by APP_GET_DRYER_SETTING."""
478+
479+
status: int | None = None
480+
on: MopDryerProfile | None = None
481+
off: MopDryerProfile | None = None
482+
483+
462484
@dataclass
463485
class DustCollectionMode(RoborockBase):
464486
mode: RoborockDockDustCollectionModeCode | None = None

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ async def discover_features(self) -> None:
289289
obstacle_photos._rpc_channel = self._get_rpc_channel(obstacle_photos)
290290
self.obstacle_photos = obstacle_photos
291291

292-
if self.mop_dryer is None and self._is_supported(MopDryerTrait, "mop_dryer", dock_features):
293-
mop_dryer = MopDryerTrait(self.status)
294-
mop_dryer._rpc_channel = self._get_rpc_channel(mop_dryer)
295-
self.mop_dryer = mop_dryer
296-
297292
# Dynamically create any traits that need to be populated
298293
for item in fields(self):
299294
if (trait := getattr(self, item.name, None)) is not None:
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Trait for the dock mop dryer."""
22

3+
from roborock.data import MopDryerSetting
34
from roborock.device_features import RoborockDockFeatures
45
from roborock.devices.traits.v1 import common
5-
from roborock.devices.traits.v1.status import StatusTrait
66
from roborock.roborock_typing import RoborockCommand
77

88
_STATUS_PARAM = "status"
@@ -12,37 +12,40 @@ def _supports_mop_dryer(dock_features: RoborockDockFeatures) -> bool:
1212
return dock_features.is_dryable
1313

1414

15-
class MopDryerTrait(common.V1TraitMixin, common.RoborockSwitchBase):
16-
"""Trait for controlling the dock mop dryer.
15+
class MopDryerTrait(MopDryerSetting, common.V1TraitMixin, common.RoborockSwitchBase):
16+
"""Trait for the dock mop dryer.
1717
18-
The dryer has no dedicated query command. Whether a drying cycle is running
19-
is reported as ``dry_status`` on the device status, so this trait reads its
20-
state from the status trait and refreshes through it.
18+
The switch controls the auto mop-drying setting, i.e. whether the dock
19+
dries the mop after washing. ``start_dry`` and ``stop_dry`` control a
20+
drying cycle directly. Whether a cycle is currently running is reported
21+
as ``dry_status`` on the device status.
2122
"""
2223

24+
command = RoborockCommand.APP_GET_DRYER_SETTING
25+
converter = common.DefaultConverter(MopDryerSetting)
2326
requires_dock_features = _supports_mop_dryer
2427

25-
def __init__(self, status_trait: StatusTrait) -> None:
26-
super().__init__()
27-
self._status_trait = status_trait
28-
29-
async def refresh(self) -> None:
30-
"""Refresh the dryer state, which is reported through the device status."""
31-
await self._status_trait.refresh()
32-
3328
@property
3429
def is_on(self) -> bool:
35-
"""Return whether a drying cycle is currently running."""
36-
return bool(self._status_trait.dry_status)
30+
"""Return whether auto mop drying is enabled."""
31+
return self.status == 1
3732

3833
async def enable(self) -> None:
39-
"""Start drying the mop."""
40-
await self.rpc_channel.send_command(RoborockCommand.APP_SET_DRYER_STATUS, params={_STATUS_PARAM: 1})
34+
"""Enable auto mop drying."""
35+
await self.rpc_channel.send_command(RoborockCommand.APP_SET_DRYER_SETTING, params={_STATUS_PARAM: 1})
4136
# Optimistic update to avoid an extra refresh
42-
self._status_trait.dry_status = 1
37+
self.status = 1
4338

4439
async def disable(self) -> None:
45-
"""Stop drying the mop."""
46-
await self.rpc_channel.send_command(RoborockCommand.APP_SET_DRYER_STATUS, params={_STATUS_PARAM: 0})
40+
"""Disable auto mop drying."""
41+
await self.rpc_channel.send_command(RoborockCommand.APP_SET_DRYER_SETTING, params={_STATUS_PARAM: 0})
4742
# Optimistic update to avoid an extra refresh
48-
self._status_trait.dry_status = 0
43+
self.status = 0
44+
45+
async def start_dry(self) -> None:
46+
"""Start a mop drying cycle."""
47+
await self.rpc_channel.send_command(RoborockCommand.APP_SET_DRYER_STATUS, params={_STATUS_PARAM: 1})
48+
49+
async def stop_dry(self) -> None:
50+
"""Stop the running mop drying cycle."""
51+
await self.rpc_channel.send_command(RoborockCommand.APP_SET_DRYER_STATUS, params={_STATUS_PARAM: 0})

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

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@
88
from roborock.devices.device import RoborockDevice
99
from roborock.devices.traits.v1.mop_dryer import MopDryerTrait
1010
from roborock.roborock_typing import RoborockCommand
11-
from tests import mock_data
1211
from tests.devices.traits.v1.helpers import dock_types_with_capability
1312

1413
DRYABLE_DOCK = RoborockDockTypeCode.o4_dock
1514

15+
# Captured from a real dock via APP_GET_DRYER_SETTING.
16+
MOP_DRYER_SETTING_DATA = {
17+
"status": 1,
18+
"on": {
19+
"cliff_on": 1000,
20+
"cliff_off": 1000,
21+
"count": 10,
22+
"dry_time": 7200,
23+
"dry_heating_film_time": 3600,
24+
},
25+
"off": {"cliff_on": 500, "cliff_off": 500, "count": 10},
26+
}
27+
1628

1729
@pytest.fixture(name="mop_dryer")
1830
def mop_dryer_trait(
@@ -46,26 +58,51 @@ async def test_unsupported_mop_dryer(mop_dryer: MopDryerTrait | None, dock_type_
4658
("dock_type_code"),
4759
[(DRYABLE_DOCK)],
4860
)
61+
async def test_refresh(
62+
mop_dryer: MopDryerTrait,
63+
mock_rpc_channel: AsyncMock,
64+
dock_type_code: RoborockDockTypeCode,
65+
) -> None:
66+
"""Test refreshing the mop dryer setting from the device."""
67+
assert mop_dryer is not None
68+
69+
mock_rpc_channel.send_command.side_effect = [
70+
MOP_DRYER_SETTING_DATA,
71+
]
72+
73+
await mop_dryer.refresh()
74+
75+
mock_rpc_channel.send_command.assert_has_calls([call(RoborockCommand.APP_GET_DRYER_SETTING)])
76+
assert mop_dryer.is_on is True
77+
assert mop_dryer.on is not None
78+
assert mop_dryer.on.dry_time == 7200
79+
assert mop_dryer.on.dry_heating_film_time == 3600
80+
assert mop_dryer.off is not None
81+
assert mop_dryer.off.dry_time is None
82+
83+
4984
@pytest.mark.parametrize(
50-
("dry_status", "expected_is_on"),
85+
("dock_type_code"),
86+
[(DRYABLE_DOCK)],
87+
)
88+
@pytest.mark.parametrize(
89+
("status", "expected_is_on"),
5190
[
5291
pytest.param(None, False, id="not_reported"),
53-
pytest.param(0, False, id="idle"),
54-
pytest.param(1, True, id="drying"),
92+
pytest.param(0, False, id="disabled"),
93+
pytest.param(1, True, id="enabled"),
5594
],
5695
)
57-
async def test_is_on_reads_status(
96+
async def test_is_on(
5897
mop_dryer: MopDryerTrait,
59-
device: RoborockDevice,
6098
dock_type_code: RoborockDockTypeCode,
61-
dry_status: int | None,
99+
status: int | None,
62100
expected_is_on: bool,
63101
) -> None:
64-
"""Test that the mop dryer state is read from the device status."""
102+
"""Test that is_on reflects the auto mop-drying setting."""
65103
assert mop_dryer is not None
66-
assert device.v1_properties
67104

68-
device.v1_properties.status.dry_status = dry_status
105+
mop_dryer.status = status
69106

70107
assert mop_dryer.is_on is expected_is_on
71108

@@ -75,54 +112,55 @@ async def test_is_on_reads_status(
75112
[(DRYABLE_DOCK)],
76113
)
77114
@pytest.mark.parametrize(
78-
("method_name", "expected_status"),
115+
("method_name", "expected_status", "expected_is_on"),
79116
[
80-
pytest.param("enable", 1, id="enable"),
81-
pytest.param("disable", 0, id="disable"),
117+
pytest.param("enable", 1, True, id="enable"),
118+
pytest.param("disable", 0, False, id="disable"),
82119
],
83120
)
84-
async def test_set_mop_dryer_status(
121+
async def test_set_auto_dry(
85122
mop_dryer: MopDryerTrait,
86-
device: RoborockDevice,
87123
mock_rpc_channel: AsyncMock,
88124
dock_type_code: RoborockDockTypeCode,
89125
method_name: str,
90126
expected_status: int,
127+
expected_is_on: bool,
91128
) -> None:
92-
"""Test starting and stopping the mop dryer sends the right command."""
129+
"""Test enabling and disabling auto mop drying."""
93130
assert mop_dryer is not None
94-
assert device.v1_properties
95131

96132
await getattr(mop_dryer, method_name)()
97133

98134
mock_rpc_channel.send_command.assert_called_with(
99-
RoborockCommand.APP_SET_DRYER_STATUS, params={"status": expected_status}
135+
RoborockCommand.APP_SET_DRYER_SETTING, params={"status": expected_status}
100136
)
101137
# The command result is applied optimistically to avoid an extra refresh
102-
assert device.v1_properties.status.dry_status == expected_status
103-
assert mop_dryer.is_on is bool(expected_status)
138+
assert mop_dryer.is_on is expected_is_on
104139

105140

106141
@pytest.mark.parametrize(
107142
("dock_type_code"),
108143
[(DRYABLE_DOCK)],
109144
)
110-
async def test_refresh_delegates_to_status(
145+
@pytest.mark.parametrize(
146+
("method_name", "expected_status"),
147+
[
148+
pytest.param("start_dry", 1, id="start"),
149+
pytest.param("stop_dry", 0, id="stop"),
150+
],
151+
)
152+
async def test_dry_cycle(
111153
mop_dryer: MopDryerTrait,
112-
device: RoborockDevice,
113154
mock_rpc_channel: AsyncMock,
114155
dock_type_code: RoborockDockTypeCode,
156+
method_name: str,
157+
expected_status: int,
115158
) -> None:
116-
"""Test refreshing the mop dryer refreshes the status it reads from."""
159+
"""Test starting and stopping a mop drying cycle."""
117160
assert mop_dryer is not None
118-
assert device.v1_properties
119-
120-
mock_rpc_channel.send_command.side_effect = [
121-
{**mock_data.STATUS, "dry_status": 1},
122-
]
123161

124-
await mop_dryer.refresh()
162+
await getattr(mop_dryer, method_name)()
125163

126-
mock_rpc_channel.send_command.assert_has_calls([call(RoborockCommand.GET_STATUS)])
127-
assert device.v1_properties.status.dry_status == 1
128-
assert mop_dryer.is_on is True
164+
mock_rpc_channel.send_command.assert_called_with(
165+
RoborockCommand.APP_SET_DRYER_STATUS, params={"status": expected_status}
166+
)

0 commit comments

Comments
 (0)