diff --git a/roborock/devices/traits/b01/q7/__init__.py b/roborock/devices/traits/b01/q7/__init__.py index 35a29144..88ee18a7 100644 --- a/roborock/devices/traits/b01/q7/__init__.py +++ b/roborock/devices/traits/b01/q7/__init__.py @@ -117,6 +117,16 @@ async def set_child_lock(self, enabled: bool) -> None: """Enable or disable the child lock.""" await self.set_prop(RoborockB01Props.CHILD_LOCK, int(enabled)) + async def set_dust_collection(self, enabled: bool) -> None: + """Enable or disable automatic dust collection at the dock.""" + await self.set_prop(RoborockB01Props.DUST_AUTO_STATE, int(enabled)) + + async def set_dust_collection_frequency(self, frequency: int) -> None: + """Set how often the dock auto-empties, in cleans per emptying (1 = every clean).""" + if frequency < 1: + raise ValueError(f"frequency must be a positive number of cleans, got {frequency}") + await self.set_prop(RoborockB01Props.DUST_FREQUENCY, frequency) + async def set_do_not_disturb(self, enabled: bool, begin_time: int, end_time: int) -> None: """Configure do-not-disturb. diff --git a/tests/devices/traits/b01/q7/test_init.py b/tests/devices/traits/b01/q7/test_init.py index c273d2d4..7707bbe6 100644 --- a/tests/devices/traits/b01/q7/test_init.py +++ b/tests/devices/traits/b01/q7/test_init.py @@ -133,6 +133,56 @@ async def test_q7_api_set_child_lock( assert params == {RoborockB01Props.CHILD_LOCK: expected_code} +@pytest.mark.parametrize( + ("enabled", "expected_code"), + [(True, 1), (False, 0)], +) +async def test_q7_api_set_dust_collection( + enabled: bool, + expected_code: int, + q7_api: Q7PropertiesApi, + fake_channel: FakeQ7Channel, +): + """Test toggling automatic dust collection.""" + fake_channel.response_queue.append({"result": "ok"}) + await q7_api.set_dust_collection(enabled) + + assert len(fake_channel.published_commands) == 1 + command, params = fake_channel.published_commands[0] + assert command == RoborockB01Q7Methods.SET_PROP + assert params == {RoborockB01Props.DUST_AUTO_STATE: expected_code} + + +@pytest.mark.parametrize("frequency", [1, 2, 3]) +async def test_q7_api_set_dust_collection_frequency( + frequency: int, + q7_api: Q7PropertiesApi, + fake_channel: FakeQ7Channel, +): + """Test setting the automatic dust-collection frequency.""" + fake_channel.response_queue.append({"result": "ok"}) + await q7_api.set_dust_collection_frequency(frequency) + + assert len(fake_channel.published_commands) == 1 + command, params = fake_channel.published_commands[0] + assert command == RoborockB01Q7Methods.SET_PROP + assert params == {RoborockB01Props.DUST_FREQUENCY: frequency} + + +@pytest.mark.parametrize("frequency", [0, -1]) +async def test_q7_api_set_dust_collection_frequency_invalid( + frequency: int, + q7_api: Q7PropertiesApi, + fake_channel: FakeQ7Channel, +): + """Test invalid dust-collection frequencies raise without publishing.""" + fake_channel.response_queue.append({"result": "ok"}) + with pytest.raises(ValueError, match="positive number of cleans"): + await q7_api.set_dust_collection_frequency(frequency) + + assert len(fake_channel.published_commands) == 0 + + @pytest.mark.parametrize("enabled, expected_is_open", [(True, 1), (False, 0)]) async def test_q7_api_set_do_not_disturb( enabled: bool,