Skip to content

Commit 6bb585e

Browse files
committed
feat(v1): expose DND action flags from get_dnd_timer
get_dnd_timer replies can include an actions object (resume, vol, led, dust, dry) that DnDTimer dropped. Keep it as DnDTimerActions with the reported integer values; the timer setters are unchanged.
1 parent c4609a3 commit 6bb585e

3 files changed

Lines changed: 64 additions & 2 deletions

File tree

‎roborock/data/v1/v1_containers.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,28 @@ def __repr__(self) -> str:
278278
return _attr_repr(self)
279279

280280

281+
@dataclass
282+
class DnDTimerActions(RoborockBase):
283+
"""Action flags reported with the DND timer, kept as the raw integers."""
284+
285+
resume: int | None = None
286+
"""1 when the disable auto top up option is enabled for DND, 0 when disabled."""
287+
vol: int | None = None
288+
"""1 when the quieten voice alerts option is enabled for DND, 0 when disabled."""
289+
led: int | None = None
290+
"""1 when the dim indicator lights option is enabled for DND, 0 when disabled."""
291+
dust: int | None = None
292+
"""1 when the disable auto emptying option is enabled for DND, 0 when disabled."""
293+
dry: int | None = None
294+
"""1 when the disable auto drying option is enabled for DND, 0 when disabled."""
295+
296+
281297
@dataclass
282298
class DnDTimer(RoborockBaseTimer):
283299
"""DnDTimer"""
284300

301+
actions: DnDTimerActions | None = None
302+
285303

286304
@dataclass
287305
class ValleyElectricityTimer(RoborockBaseTimer):

‎tests/devices/__snapshots__/test_v1_device.ambr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@
489489
})
490490
# ---
491491
# name: test_device_trait_command_parsing[dnd]
492-
DoNotDisturbTrait(start_hour=22, start_minute=0, end_hour=8, end_minute=0, enabled=1)
492+
DoNotDisturbTrait(start_hour=22, start_minute=0, end_hour=8, end_minute=0, enabled=1, actions=None)
493493
# ---
494494
# name: test_device_trait_command_parsing[dnd].1
495495
dict({

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44

55
import pytest
66

7-
from roborock.data import DnDTimer
7+
from roborock.data import DnDTimer, DnDTimerActions
88
from roborock.devices.device import RoborockDevice
99
from roborock.devices.traits.v1.do_not_disturb import DoNotDisturbTrait
1010
from roborock.exceptions import RoborockException
1111
from roborock.roborock_typing import RoborockCommand
1212

13+
# Timer fields captured from a Qrevo 2 Pro (roborock.vacuum.a294) with get_dnd_timer.
14+
DND_TIMER_RESPONSE = {
15+
"start_hour": 22,
16+
"start_minute": 0,
17+
"end_hour": 8,
18+
"end_minute": 0,
19+
"enabled": 1,
20+
}
21+
1322

1423
@pytest.fixture
1524
async def dnd_trait(device: RoborockDevice) -> DoNotDisturbTrait:
@@ -28,9 +37,43 @@ def sample_dnd_timer() -> DnDTimer:
2837
end_hour=8,
2938
end_minute=0,
3039
enabled=1,
40+
actions=DnDTimerActions(resume=1, vol=1, led=1, dust=1, dry=1),
3141
)
3242

3343

44+
@pytest.mark.parametrize(
45+
("response", "expected_actions"),
46+
[
47+
# Action flags read from the same device with different DND options turned on.
48+
(
49+
{**DND_TIMER_RESPONSE, "actions": {"resume": 1, "dust": 0, "led": 0, "vol": 1, "dry": 0}},
50+
DnDTimerActions(resume=1, vol=1, led=0, dust=0, dry=0),
51+
),
52+
(
53+
{**DND_TIMER_RESPONSE, "actions": {"resume": 0, "dust": 1, "led": 1, "vol": 1, "dry": 0}},
54+
DnDTimerActions(resume=0, vol=1, led=1, dust=1, dry=0),
55+
),
56+
(
57+
{**DND_TIMER_RESPONSE, "actions": {"resume": 1, "dust": 0, "led": 1, "vol": 0, "dry": 0}},
58+
DnDTimerActions(resume=1, vol=0, led=1, dust=0, dry=0),
59+
),
60+
(DND_TIMER_RESPONSE, None),
61+
],
62+
)
63+
async def test_get_dnd_timer_actions(
64+
dnd_trait: DoNotDisturbTrait,
65+
mock_rpc_channel: AsyncMock,
66+
response: dict,
67+
expected_actions: DnDTimerActions | None,
68+
) -> None:
69+
"""Test reading the action flags reported with the DND timer."""
70+
mock_rpc_channel.send_command.return_value = [response]
71+
72+
await dnd_trait.refresh()
73+
74+
assert dnd_trait.actions == expected_actions
75+
76+
3477
async def test_get_dnd_timer_success(
3578
dnd_trait: DoNotDisturbTrait, mock_rpc_channel: AsyncMock, sample_dnd_timer: DnDTimer
3679
) -> None:
@@ -48,6 +91,7 @@ async def test_get_dnd_timer_success(
4891
assert dnd_trait.end_minute == 0
4992
assert dnd_trait.enabled == 1
5093
assert dnd_trait.is_on
94+
assert dnd_trait.actions == sample_dnd_timer.actions
5195

5296
# Verify the RPC call was made correctly
5397
mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_DND_TIMER)

0 commit comments

Comments
 (0)