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,
|
# Skip update on specific commands, or if device factory,
|
||||||
# that performs an update was used for the device.
|
# that performs an update was used for the device.
|
||||||
if ctx.invoked_subcommand not in SKIP_UPDATE_COMMANDS and not device_updated:
|
if ctx.invoked_subcommand not in SKIP_UPDATE_COMMANDS and not device_updated:
|
||||||
await dev.update()
|
await dev.update(update_children=True)
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def async_wrapped_device(device: Device):
|
async def async_wrapped_device(device: Device):
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from typing import Literal, TypeAlias
|
||||||
|
|
||||||
from ...feature import Feature
|
from ...feature import Feature
|
||||||
from ..smartmodule import SmartModule
|
from ..smartmodule import SmartModule
|
||||||
@ -16,10 +17,15 @@ class WaterleakStatus(Enum):
|
|||||||
Drying = "water_dry"
|
Drying = "water_dry"
|
||||||
|
|
||||||
|
|
||||||
|
Volume: TypeAlias = Literal["low", "normal", "high", "mute"]
|
||||||
|
ALLOWED_VOLUMES = ["low", "normal", "high", "mute"]
|
||||||
|
|
||||||
|
|
||||||
class WaterleakSensor(SmartModule):
|
class WaterleakSensor(SmartModule):
|
||||||
"""Implementation of waterleak module."""
|
"""Implementation of waterleak module."""
|
||||||
|
|
||||||
REQUIRED_COMPONENT = "sensor_alarm"
|
REQUIRED_COMPONENT = "sensor_alarm"
|
||||||
|
QUERY_GETTER_NAME = "get_alarm_config"
|
||||||
|
|
||||||
def _initialize_features(self):
|
def _initialize_features(self):
|
||||||
"""Initialize features after the initial update."""
|
"""Initialize features after the initial update."""
|
||||||
@ -47,11 +53,18 @@ class WaterleakSensor(SmartModule):
|
|||||||
type=Feature.Type.BinarySensor,
|
type=Feature.Type.BinarySensor,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self._add_feature(
|
||||||
def query(self) -> dict:
|
Feature(
|
||||||
"""Query to execute during the update cycle."""
|
self._device,
|
||||||
# Water leak information is contained in the main device info response.
|
id="water_alert_volume",
|
||||||
return {}
|
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
|
@property
|
||||||
def status(self) -> WaterleakStatus:
|
def status(self) -> WaterleakStatus:
|
||||||
@ -62,3 +75,12 @@ class WaterleakSensor(SmartModule):
|
|||||||
def alert(self) -> bool:
|
def alert(self) -> bool:
|
||||||
"""Return true if alarm is active."""
|
"""Return true if alarm is active."""
|
||||||
return self._device.sys_info["in_alarm"]
|
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_alert", "alert", int),
|
||||||
("water_leak", "status", Enum),
|
("water_leak", "status", Enum),
|
||||||
|
("water_alert_volume", "alert_volume", str),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_waterleak_properties(dev, feature, prop_name, type):
|
async def test_waterleak_properties(dev, feature, prop_name, type):
|
||||||
|
Loading…
Reference in New Issue
Block a user