From d2530aa27b42cb37a51aa7137e83f871553d4edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Sun, 21 Jul 2024 10:58:51 +0200 Subject: [PATCH] Fix #635: Siren duration on C520WS --- custom_components/tapo_control/number.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/custom_components/tapo_control/number.py b/custom_components/tapo_control/number.py index 877ebff..cf90747 100644 --- a/custom_components/tapo_control/number.py +++ b/custom_components/tapo_control/number.py @@ -388,11 +388,21 @@ async def async_set_native_value(self, value: float) -> None: self._controller.setHubSirenConfig, int(value) ) else: - result = await self._hass.async_add_executor_job( - self._controller.executeFunction, - "setAlarmConfig", - {"msg_alarm": {self.value_key: int(value)}}, - ) + if self.typeOfAlarm == "getAlarm": + result = await self._hass.async_add_executor_job( + self._controller.setAlarm, + self.alarm_enabled == "on", + "sound" in self.alarm_mode, + "siren" in self.alarm_mode or "light" in self.alarm_mode, + None, + int(value), + ) + elif self.typeOfAlarm == "getAlarmConfig": + result = await self._hass.async_add_executor_job( + self._controller.executeFunction, + "setAlarmConfig", + {"msg_alarm": {self.value_key: int(value)}}, + ) if "error_code" not in result or result["error_code"] == 0: self._attr_state = value self.async_write_ha_state() @@ -403,3 +413,5 @@ def updateTapo(self, camData): self._attr_state = STATE_UNAVAILABLE else: self._attr_state = camData["alarm_config"][self.value_key] + self.alarm_enabled = camData["alarm_config"]["automatic"] == "on" + self.alarm_mode = camData["alarm_config"]["mode"]