mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-11-04 14:42:09 +00:00
Expose alarm_duration, fix play setter signature
This commit is contained in:
@@ -21,10 +21,7 @@ class Alarm(SmartModule):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _initialize_features(self) -> None:
|
def _initialize_features(self) -> None:
|
||||||
"""Initialize features.
|
"""Initialize features."""
|
||||||
|
|
||||||
This is implemented as some features depend on device responses.
|
|
||||||
"""
|
|
||||||
device = self._device
|
device = self._device
|
||||||
self._add_feature(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
@@ -74,6 +71,20 @@ class Alarm(SmartModule):
|
|||||||
choices_getter=lambda: ["low", "normal", "high"],
|
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(
|
self._add_feature(
|
||||||
Feature(
|
Feature(
|
||||||
device,
|
device,
|
||||||
@@ -125,6 +136,17 @@ class Alarm(SmartModule):
|
|||||||
payload["volume"] = volume
|
payload["volume"] = volume
|
||||||
return await self.call("set_alarm_configure", payload)
|
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
|
@property
|
||||||
def active(self) -> bool:
|
def active(self) -> bool:
|
||||||
"""Return true if alarm is active."""
|
"""Return true if alarm is active."""
|
||||||
@@ -140,7 +162,7 @@ class Alarm(SmartModule):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
duration: int | None = None,
|
duration: int | None = None,
|
||||||
volume: Literal["low", "normal", "high"] | None,
|
volume: Literal["low", "normal", "high"] | None = None,
|
||||||
sound: str | None = None,
|
sound: str | None = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""Play alarm.
|
"""Play alarm.
|
||||||
|
|||||||
Reference in New Issue
Block a user