mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Implement vacuum dustbin module (dust_bucket) (#1423)
Initial implementation for dustbin auto-emptying. New features: - `dustbin_empty` action to empty the dustbin immediately - `dustbin_autocollection_enabled` to toggle the auto collection - `dustbin_mode` to choose how often the auto collection is performed
This commit is contained in:
@@ -163,6 +163,7 @@ class Module(ABC):
|
||||
|
||||
# Vacuum modules
|
||||
Clean: Final[ModuleName[smart.Clean]] = ModuleName("Clean")
|
||||
Dustbin: Final[ModuleName[smart.Dustbin]] = ModuleName("Dustbin")
|
||||
|
||||
def __init__(self, device: Device, module: str) -> None:
|
||||
self._device = device
|
||||
|
@@ -13,6 +13,7 @@ from .color import Color
|
||||
from .colortemperature import ColorTemperature
|
||||
from .contactsensor import ContactSensor
|
||||
from .devicemodule import DeviceModule
|
||||
from .dustbin import Dustbin
|
||||
from .energy import Energy
|
||||
from .fan import Fan
|
||||
from .firmware import Firmware
|
||||
@@ -72,4 +73,5 @@ __all__ = [
|
||||
"OverheatProtection",
|
||||
"HomeKit",
|
||||
"Matter",
|
||||
"Dustbin",
|
||||
]
|
||||
|
117
kasa/smart/modules/dustbin.py
Normal file
117
kasa/smart/modules/dustbin.py
Normal file
@@ -0,0 +1,117 @@
|
||||
"""Implementation of vacuum dustbin."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from enum import IntEnum
|
||||
|
||||
from ...feature import Feature
|
||||
from ..smartmodule import SmartModule
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Mode(IntEnum):
|
||||
"""Dust collection modes."""
|
||||
|
||||
Smart = 0
|
||||
Light = 1
|
||||
Balanced = 2
|
||||
Max = 3
|
||||
|
||||
|
||||
class Dustbin(SmartModule):
|
||||
"""Implementation of vacuum dustbin."""
|
||||
|
||||
REQUIRED_COMPONENT = "dust_bucket"
|
||||
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features."""
|
||||
self._add_feature(
|
||||
Feature(
|
||||
self._device,
|
||||
id="dustbin_empty",
|
||||
name="Empty dustbin",
|
||||
container=self,
|
||||
attribute_setter="start_emptying",
|
||||
category=Feature.Category.Primary,
|
||||
type=Feature.Action,
|
||||
)
|
||||
)
|
||||
|
||||
self._add_feature(
|
||||
Feature(
|
||||
self._device,
|
||||
id="dustbin_autocollection_enabled",
|
||||
name="Automatic emptying enabled",
|
||||
container=self,
|
||||
attribute_getter="auto_collection",
|
||||
attribute_setter="set_auto_collection",
|
||||
category=Feature.Category.Config,
|
||||
type=Feature.Switch,
|
||||
)
|
||||
)
|
||||
|
||||
self._add_feature(
|
||||
Feature(
|
||||
self._device,
|
||||
id="dustbin_mode",
|
||||
name="Automatic emptying mode",
|
||||
container=self,
|
||||
attribute_getter="mode",
|
||||
attribute_setter="set_mode",
|
||||
icon="mdi:fan",
|
||||
choices_getter=lambda: list(Mode.__members__),
|
||||
category=Feature.Category.Config,
|
||||
type=Feature.Type.Choice,
|
||||
)
|
||||
)
|
||||
|
||||
def query(self) -> dict:
|
||||
"""Query to execute during the update cycle."""
|
||||
return {
|
||||
"getAutoDustCollection": {},
|
||||
"getDustCollectionInfo": {},
|
||||
}
|
||||
|
||||
async def start_emptying(self) -> dict:
|
||||
"""Start emptying the bin."""
|
||||
return await self.call(
|
||||
"setSwitchDustCollection",
|
||||
{
|
||||
"switch_dust_collection": True,
|
||||
},
|
||||
)
|
||||
|
||||
@property
|
||||
def _settings(self) -> dict:
|
||||
"""Return auto-empty settings."""
|
||||
return self.data["getDustCollectionInfo"]
|
||||
|
||||
@property
|
||||
def mode(self) -> str:
|
||||
"""Return auto-emptying mode."""
|
||||
return Mode(self._settings["dust_collection_mode"]).name
|
||||
|
||||
async def set_mode(self, mode: str) -> dict:
|
||||
"""Set auto-emptying mode."""
|
||||
name_to_value = {x.name: x.value for x in Mode}
|
||||
if mode not in name_to_value:
|
||||
raise ValueError(
|
||||
"Invalid auto/emptying mode speed %s, available %s", mode, name_to_value
|
||||
)
|
||||
|
||||
settings = self._settings.copy()
|
||||
settings["dust_collection_mode"] = name_to_value[mode]
|
||||
return await self.call("setDustCollectionInfo", settings)
|
||||
|
||||
@property
|
||||
def auto_collection(self) -> dict:
|
||||
"""Return auto-emptying config."""
|
||||
return self._settings["auto_dust_collection"]
|
||||
|
||||
async def set_auto_collection(self, on: bool) -> dict:
|
||||
"""Toggle auto-emptying."""
|
||||
settings = self._settings.copy()
|
||||
settings["auto_dust_collection"] = on
|
||||
return await self.call("setDustCollectionInfo", settings)
|
Reference in New Issue
Block a user