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
10 changes: 10 additions & 0 deletions roborock/devices/traits/b01/q7/__init__.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.

Expand Down
50 changes: 50 additions & 0 deletions tests/devices/traits/b01/q7/test_init.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Expand Down