diff --git a/kasa/smart/modules/dustbin.py b/kasa/smart/modules/dustbin.py index 33aecd8f7..b2b4d1ef4 100644 --- a/kasa/smart/modules/dustbin.py +++ b/kasa/smart/modules/dustbin.py @@ -19,6 +19,8 @@ class Mode(IntEnum): Balanced = 2 Max = 3 + Off = -1_000 + class Dustbin(SmartModule): """Implementation of vacuum dustbin.""" @@ -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: @@ -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 diff --git a/tests/smart/modules/test_dustbin.py b/tests/smart/modules/test_dustbin.py index d30d2459b..ecc68b6b2 100644 --- a/tests/smart/modules/test_dustbin.py +++ b/tests/smart/modules/test_dustbin.py @@ -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."""