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 @@ -279,10 +279,28 @@ def __repr__(self) -> str:
return _attr_repr(self)


@dataclass
class DnDTimerActions(RoborockBase):
"""Optional actions applied while DND is active, as reported by `get_dnd_timer`."""

resume: bool | None = None
"""True when the disable auto top up option is enabled for DND."""
vol: bool | None = None
"""True when the quieten voice alerts option is enabled for DND."""
led: bool | None = None
"""True when the dim indicator lights option is enabled for DND."""
dust: bool | None = None
"""True when the disable auto emptying option is enabled for DND."""
dry: bool | None = None
"""True when the disable auto drying option is enabled for DND."""


@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 @@ -534,7 +534,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
49 changes: 48 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,46 @@ def sample_dnd_timer() -> DnDTimer:
end_hour=8,
end_minute=0,
enabled=1,
actions=DnDTimerActions(resume=True, vol=True, led=True, dust=True, dry=True),
)


@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=True, vol=True, led=False, dust=False, dry=False),
),
(
{**DND_TIMER_RESPONSE, "actions": {"resume": 0, "dust": 1, "led": 1, "vol": 1, "dry": 0}},
DnDTimerActions(resume=False, vol=True, led=True, dust=True, dry=False),
),
(
{**DND_TIMER_RESPONSE, "actions": {"resume": 1, "dust": 0, "led": 1, "vol": 0, "dry": 0}},
DnDTimerActions(resume=True, vol=False, led=True, dust=False, dry=False),
),
(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
# True == 1 in Python, so also check the wire ints were decoded to real booleans.
if dnd_trait.actions is not None:
assert {type(value) for value in vars(dnd_trait.actions).values()} == {bool}


async def test_get_dnd_timer_success(
dnd_trait: DoNotDisturbTrait, mock_rpc_channel: AsyncMock, sample_dnd_timer: DnDTimer
) -> None:
Expand All @@ -48,6 +94,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