Skip to content
Merged
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 kasa/smart/modules/dustbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Mode(IntEnum):
Balanced = 2
Max = 3

Off = -1_000


class Dustbin(SmartModule):
"""Implementation of vacuum dustbin."""
Expand Down Expand Up @@ -91,6 +93,8 @@ def _settings(self) -> dict:
@property
def mode(self) -> str:
"""Return auto-emptying mode."""
if self.auto_collection is False:
return Mode.Off.name
return Mode(self._settings["dust_collection_mode"]).name

async def set_mode(self, mode: str) -> dict:
Expand All @@ -101,8 +105,14 @@ async def set_mode(self, mode: str) -> dict:
"Invalid auto/emptying mode speed %s, available %s", mode, name_to_value
)

if mode == Mode.Off.name:
return await self.set_auto_collection(False)

# Make a copy just in case, even when we are overriding both settings
settings = self._settings.copy()
settings["auto_dust_collection"] = True
settings["dust_collection_mode"] = name_to_value[mode]

return await self.call("setDustCollectionInfo", settings)

@property
Expand Down
19 changes: 19 additions & 0 deletions tests/smart/modules/test_dustbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ async def test_dustbin_mode(dev: SmartDevice, mocker: MockerFixture):
await dustbin.set_mode("invalid")


@dustbin
async def test_dustbin_mode_off(dev: SmartDevice, mocker: MockerFixture):
"""Test dustbin_mode == Off."""
dustbin = next(get_parent_and_child_modules(dev, Module.Dustbin))
call = mocker.spy(dustbin, "call")

auto_collection = dustbin._device.features["dustbin_mode"]
await auto_collection.set_value(Mode.Off.name)

params = dustbin._settings.copy()
params["auto_dust_collection"] = False

call.assert_called_with("setDustCollectionInfo", params)

await dev.update()
assert dustbin.auto_collection is False
assert dustbin.mode is Mode.Off.name


@dustbin
async def test_autocollection(dev: SmartDevice, mocker: MockerFixture):
"""Test autocollection switch."""
Expand Down
Loading