From 83237537408ad58cec28e13489950698561ee0da Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Thu, 5 Dec 2024 15:22:22 +0100 Subject: [PATCH] Expose alarm_duration, fix play setter signature --- kasa/smart/modules/alarm.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/kasa/smart/modules/alarm.py b/kasa/smart/modules/alarm.py index 9373d1dd..b6f03435 100644 --- a/kasa/smart/modules/alarm.py +++ b/kasa/smart/modules/alarm.py @@ -21,10 +21,7 @@ class Alarm(SmartModule): } def _initialize_features(self) -> None: - """Initialize features. - - This is implemented as some features depend on device responses. - """ + """Initialize features.""" device = self._device self._add_feature( Feature( @@ -74,6 +71,20 @@ class Alarm(SmartModule): choices_getter=lambda: ["low", "normal", "high"], ) ) + self._add_feature( + Feature( + device, + id="alarm_duration", + name="Alarm duration", + container=self, + attribute_getter="alarm_duration", + attribute_setter="set_alarm_duration", + category=Feature.Category.Config, + type=Feature.Type.Number, + # TODO: needs testing the duration limits. + range_getter=lambda: (1, 60), + ) + ) self._add_feature( Feature( device, @@ -125,6 +136,17 @@ class Alarm(SmartModule): payload["volume"] = volume return await self.call("set_alarm_configure", payload) + @property + def alarm_duration(self) -> int: + """Return alarm duration.""" + return self.data["get_alarm_configure"]["duration"] + + async def set_alarm_duration(self, duration: int) -> dict: + """Set alarm duration.""" + payload = self.data["get_alarm_configure"].copy() + payload["duration"] = duration + return await self.call("set_alarm_configure", payload) + @property def active(self) -> bool: """Return true if alarm is active.""" @@ -140,7 +162,7 @@ class Alarm(SmartModule): self, *, duration: int | None = None, - volume: Literal["low", "normal", "high"] | None, + volume: Literal["low", "normal", "high"] | None = None, sound: str | None = None, ) -> dict: """Play alarm.