FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add alert volume setting to water leak sensor by rytilahti · Pull Request #1163 · python-kasa/python-kasa · GitHub

Repository navigation

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion kasa/cli/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL