mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
Add alert volume setting to water leak sensor
This commit is contained in:
parent
885a04d24f
commit
06f14bfc6d
@ -339,7 +339,7 @@ async def cli(
|
||||
# Skip update on specific commands, or if device factory,
|
||||
# that performs an update was used for the device.
|
||||
if ctx.invoked_subcommand not in SKIP_UPDATE_COMMANDS and not device_updated:
|
||||
await dev.update()
|
||||
await dev.update(update_children=True)
|
||||
|
||||
@asynccontextmanager
|
||||
async def async_wrapped_device(device: Device):
|
||||
|
@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Literal, TypeAlias
|
||||
|
||||
from ...feature import Feature
|
||||
from ..smartmodule import SmartModule
|
||||
@ -16,10 +17,15 @@ class WaterleakStatus(Enum):
|
||||
Drying = "water_dry"
|
||||
|
||||
|
||||
Volume: TypeAlias = Literal["low", "normal", "high", "mute"]
|
||||
ALLOWED_VOLUMES = ["low", "normal", "high", "mute"]
|
||||
|
||||
|
||||
class WaterleakSensor(SmartModule):
|
||||
"""Implementation of waterleak module."""
|
||||
|
||||
REQUIRED_COMPONENT = "sensor_alarm"
|
||||
QUERY_GETTER_NAME = "get_alarm_config"
|
||||
|
||||
def _initialize_features(self):
|
||||
"""Initialize features after the initial update."""
|
||||
@ -47,11 +53,18 @@ class WaterleakSensor(SmartModule):
|
||||
type=Feature.Type.BinarySensor,
|
||||
)
|
||||
)
|
||||
|
||||
def query(self) -> dict:
|
||||
"""Query to execute during the update cycle."""
|
||||
# Water leak information is contained in the main device info response.
|
||||
return {}
|
||||
self._add_feature(
|
||||
Feature(
|
||||
self._device,
|
||||
id="water_alert_volume",
|
||||
name="Water alert volume",
|
||||
container=self,
|
||||
attribute_getter="alert_volume",
|
||||
attribute_setter="set_alert_volume",
|
||||
type=Feature.Type.Choice,
|
||||
choices_getter=lambda: ALLOWED_VOLUMES,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def status(self) -> WaterleakStatus:
|
||||
@ -62,3 +75,12 @@ class WaterleakSensor(SmartModule):
|
||||
def alert(self) -> bool:
|
||||
"""Return true if alarm is active."""
|
||||
return self._device.sys_info["in_alarm"]
|
||||
|
||||
@property
|
||||
def alert_volume(self) -> Volume:
|
||||
"""Get water leak alert volume."""
|
||||
return self.data["volume"]
|
||||
|
||||
async def set_alert_volume(self, volume: Volume):
|
||||
"""Set water leak alert volume."""
|
||||
await self.call("set_alarm_config", {"volume": volume})
|
||||
|
@ -16,6 +16,7 @@ waterleak = parametrize(
|
||||
[
|
||||
("water_alert", "alert", int),
|
||||
("water_leak", "status", Enum),
|
||||
("water_alert_volume", "alert_volume", str),
|
||||
],
|
||||
)
|
||||
async def test_waterleak_properties(dev, feature, prop_name, type):
|
||||
|
Loading…
Reference in New Issue
Block a user