diff --git a/roborock/data/v1/v1_containers.py b/roborock/data/v1/v1_containers.py index 91dc98f0b..61a8135b5 100644 --- a/roborock/data/v1/v1_containers.py +++ b/roborock/data/v1/v1_containers.py @@ -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 + """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): diff --git a/tests/devices/__snapshots__/test_v1_device.ambr b/tests/devices/__snapshots__/test_v1_device.ambr index 11eb4fc21..ab47279c2 100644 --- a/tests/devices/__snapshots__/test_v1_device.ambr +++ b/tests/devices/__snapshots__/test_v1_device.ambr @@ -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({ diff --git a/tests/devices/traits/v1/test_dnd.py b/tests/devices/traits/v1/test_dnd.py index 7c0d49332..533b99878 100644 --- a/tests/devices/traits/v1/test_dnd.py +++ b/tests/devices/traits/v1/test_dnd.py @@ -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: @@ -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: @@ -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)