From 0f7e007663922759a15fe9d4a574a02a8dab33d5 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Wed, 4 Dec 2024 21:41:08 +0100 Subject: [PATCH] Allow passing alarm parameter overrides --- kasa/smart/modules/alarm.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/kasa/smart/modules/alarm.py b/kasa/smart/modules/alarm.py index f1bf7236..9373d1dd 100644 --- a/kasa/smart/modules/alarm.py +++ b/kasa/smart/modules/alarm.py @@ -136,9 +136,29 @@ class Alarm(SmartModule): src = self._device.sys_info["in_alarm_source"] return src if src else None - async def play(self) -> dict: - """Play alarm.""" - return await self.call("play_alarm") + async def play( + self, + *, + duration: int | None = None, + volume: Literal["low", "normal", "high"] | None, + sound: str | None = None, + ) -> dict: + """Play alarm. + + The optional *duration*, *volume*, and *sound* to override the device settings. + *volume* can be set to 'low', 'normal', or 'high'. + *duration* is in seconds. + See *alarm_sounds* for the list of sounds available for the device. + """ + params: dict[str, str | int] = {} + if duration is not None: + params["alarm_duration"] = duration + if volume is not None: + params["alarm_volume"] = volume + if sound is not None: + params["alarm_type"] = sound + + return await self.call("play_alarm", params) async def stop(self) -> dict: """Stop alarm."""