8000 Add alert volume setting to water leak sensor by rytilahti · Pull Request #1163 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add alert volume setting to water leak sensor #1163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion kasa/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
32 changes: 27 additions & 5 deletions kasa/smart/modules/waterleaksensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -47,11 +53,18 @@ def _initialize_features(self):
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:
Expand All @@ -62,3 +75,12 @@ def status(self) -> WaterleakStatus:
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})
1 change: 1 addition & 0 deletions kasa/tests/smart/modules/test_waterleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[
("water_alert", "alert", int),
("water_leak", "status", Enum),
("water_alert_volume", "alert_volume", str),
],
)
async def test_waterleak_properties(dev, feature, prop_name, type):
Expand Down
Loading
0