Skip to content
Open
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
18 changes: 18 additions & 0 deletions roborock/data/v1/v1_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,28 @@ def __repr__(self) -> str:
return _attr_repr(self)


@dataclass
class DnDTimerActions(RoborockBase):
"""Action flags reported with the DND timer, kept as the raw integers."""

resume: int | None = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expose these as booleans?

"""1 when the disable auto top up option is enabled for DND, 0 when disabled."""
vol: int | None = None
"""1 when the quieten voice alerts option is enabled for DND, 0 when disabled."""
led: int | None = None
"""1 when the dim indicator lights option is enabled for DND, 0 when disabled."""
dust: int | None = None
"""1 when the disable auto emptying option is enabled for DND, 0 when disabled."""
dry: int | None = None
"""1 when the disable auto drying option is enabled for DND, 0 when disabled."""


@dataclass
class DnDTimer(RoborockBaseTimer):
"""DnDTimer"""

actions: DnDTimerActions | None = None


@dataclass
class ValleyElectricityTimer(RoborockBaseTimer):
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/__snapshots__/test_v1_device.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
})
# ---
# name: test_device_trait_command_parsing[dnd]
DoNotDisturbTrait(start_hour=22, start_minute=0, end_hour=8, end_minute=0, enabled=1)
DoNotDisturbTrait(start_hour=22, start_minute=0, end_hour=8, end_minute=0, enabled=1, actions=None)
# ---
# name: test_device_trait_command_parsing[dnd].1
dict({
Expand Down
46 changes: 45 additions & 1 deletion tests/devices/traits/v1/test_dnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

import pytest

from roborock.data import DnDTimer
from roborock.data import DnDTimer, DnDTimerActions
from roborock.devices.device import RoborockDevice
from roborock.devices.traits.v1.do_not_disturb import DoNotDisturbTrait
from roborock.exceptions import RoborockException
from roborock.roborock_typing import RoborockCommand

# Timer fields captured from a Qrevo 2 Pro (roborock.vacuum.a294) with get_dnd_timer.
DND_TIMER_RESPONSE = {
"start_hour": 22,
"start_minute": 0,
"end_hour": 8,
"end_minute": 0,
"enabled": 1,
}


@pytest.fixture
async def dnd_trait(device: RoborockDevice) -> DoNotDisturbTrait:
Expand All @@ -28,9 +37,43 @@ def sample_dnd_timer() -> DnDTimer:
end_hour=8,
end_minute=0,
enabled=1,
actions=DnDTimerActions(resume=1, vol=1, led=1, dust=1, dry=1),
)


@pytest.mark.parametrize(
("response", "expected_actions"),
[
# Action flags read from the same device with different DND options turned on.
(
{**DND_TIMER_RESPONSE, "actions": {"resume": 1, "dust": 0, "led": 0, "vol": 1, "dry": 0}},
DnDTimerActions(resume=1, vol=1, led=0, dust=0, dry=0),
),
(
{**DND_TIMER_RESPONSE, "actions": {"resume": 0, "dust": 1, "led": 1, "vol": 1, "dry": 0}},
DnDTimerActions(resume=0, vol=1, led=1, dust=1, dry=0),
),
(
{**DND_TIMER_RESPONSE, "actions": {"resume": 1, "dust": 0, "led": 1, "vol": 0, "dry": 0}},
DnDTimerActions(resume=1, vol=0, led=1, dust=0, dry=0),
),
(DND_TIMER_RESPONSE, None),
],
)
async def test_get_dnd_timer_actions(
dnd_trait: DoNotDisturbTrait,
mock_rpc_channel: AsyncMock,
response: dict,
expected_actions: DnDTimerActions | None,
) -> None:
"""Test reading the action flags reported with the DND timer."""
mock_rpc_channel.send_command.return_value = [response]

await dnd_trait.refresh()

assert dnd_trait.actions == expected_actions


async def test_get_dnd_timer_success(
dnd_trait: DoNotDisturbTrait, mock_rpc_channel: AsyncMock, sample_dnd_timer: DnDTimer
) -> None:
Expand All @@ -48,6 +91,7 @@ async def test_get_dnd_timer_success(
assert dnd_trait.end_minute == 0
assert dnd_trait.enabled == 1
assert dnd_trait.is_on
assert dnd_trait.actions == sample_dnd_timer.actions

# Verify the RPC call was made correctly
mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_DND_TIMER)
Expand Down
Loading