From 68f50aa763cb7199a31d942c96a7e0d95b3687d4 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:11:12 +0000 Subject: [PATCH] Allow update of camera modules after setting values (#1450) --- kasa/smartcam/modules/alarm.py | 4 ++++ kasa/smartcam/modules/babycrydetection.py | 2 ++ kasa/smartcam/modules/camera.py | 6 ++++++ kasa/smartcam/modules/led.py | 2 ++ kasa/smartcam/modules/lensmask.py | 2 ++ kasa/smartcam/modules/motiondetection.py | 2 ++ kasa/smartcam/modules/persondetection.py | 2 ++ kasa/smartcam/modules/tamperdetection.py | 2 ++ kasa/smartcam/modules/time.py | 2 ++ 9 files changed, 24 insertions(+) diff --git a/kasa/smartcam/modules/alarm.py b/kasa/smartcam/modules/alarm.py index 12d43464..5330f309 100644 --- a/kasa/smartcam/modules/alarm.py +++ b/kasa/smartcam/modules/alarm.py @@ -3,6 +3,7 @@ from __future__ import annotations from ...feature import Feature +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule DURATION_MIN = 0 @@ -110,6 +111,7 @@ class Alarm(SmartCamModule): """Return current alarm sound.""" return self.data["getSirenConfig"]["siren_type"] + @allow_update_after async def set_alarm_sound(self, sound: str) -> dict: """Set alarm sound. @@ -134,6 +136,7 @@ class Alarm(SmartCamModule): """ return int(self.data["getSirenConfig"]["volume"]) + @allow_update_after async def set_alarm_volume(self, volume: int) -> dict: """Set alarm volume.""" if volume < VOLUME_MIN or volume > VOLUME_MAX: @@ -145,6 +148,7 @@ class Alarm(SmartCamModule): """Return alarm duration.""" return self.data["getSirenConfig"]["duration"] + @allow_update_after async def set_alarm_duration(self, duration: int) -> dict: """Set alarm volume.""" if duration < DURATION_MIN or duration > DURATION_MAX: diff --git a/kasa/smartcam/modules/babycrydetection.py b/kasa/smartcam/modules/babycrydetection.py index ecad1e83..75399885 100644 --- a/kasa/smartcam/modules/babycrydetection.py +++ b/kasa/smartcam/modules/babycrydetection.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging from ...feature import Feature +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) @@ -39,6 +40,7 @@ class BabyCryDetection(SmartCamModule): """Return the baby cry detection enabled state.""" return self.data["bcd"]["enabled"] == "on" + @allow_update_after async def set_enabled(self, enable: bool) -> dict: """Set the baby cry detection enabled state.""" params = {"enabled": "on" if enable else "off"} diff --git a/kasa/smartcam/modules/camera.py b/kasa/smartcam/modules/camera.py index f1eda0f9..9a339120 100644 --- a/kasa/smartcam/modules/camera.py +++ b/kasa/smartcam/modules/camera.py @@ -99,6 +99,9 @@ class Camera(SmartCamModule): :return: rtsp url with escaped credentials or None if no credentials or camera is off. """ + if self._device._is_hub_child: + return None + streams = { StreamResolution.HD: "stream1", StreamResolution.SD: "stream2", @@ -119,6 +122,9 @@ class Camera(SmartCamModule): def onvif_url(self) -> str | None: """Return the onvif url.""" + if self._device._is_hub_child: + return None + return f"http://{self._device.host}:{ONVIF_PORT}/onvif/device_service" async def _check_supported(self) -> bool: diff --git a/kasa/smartcam/modules/led.py b/kasa/smartcam/modules/led.py index fb62c52d..5b0912e7 100644 --- a/kasa/smartcam/modules/led.py +++ b/kasa/smartcam/modules/led.py @@ -3,6 +3,7 @@ from __future__ import annotations from ...interfaces.led import Led as LedInterface +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule @@ -19,6 +20,7 @@ class Led(SmartCamModule, LedInterface): """Return current led status.""" return self.data["config"]["enabled"] == "on" + @allow_update_after async def set_led(self, enable: bool) -> dict: """Set led. diff --git a/kasa/smartcam/modules/lensmask.py b/kasa/smartcam/modules/lensmask.py index 9257b306..22ae0ab3 100644 --- a/kasa/smartcam/modules/lensmask.py +++ b/kasa/smartcam/modules/lensmask.py @@ -4,6 +4,7 @@ from __future__ import annotations import logging +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) @@ -23,6 +24,7 @@ class LensMask(SmartCamModule): """Return the lens mask state.""" return self.data["lens_mask_info"]["enabled"] == "on" + @allow_update_after async def set_enabled(self, enable: bool) -> dict: """Set the lens mask state.""" params = {"enabled": "on" if enable else "off"} diff --git a/kasa/smartcam/modules/motiondetection.py b/kasa/smartcam/modules/motiondetection.py index a30448f8..dd3c168e 100644 --- a/kasa/smartcam/modules/motiondetection.py +++ b/kasa/smartcam/modules/motiondetection.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging from ...feature import Feature +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) @@ -39,6 +40,7 @@ class MotionDetection(SmartCamModule): """Return the motion detection enabled state.""" return self.data["motion_det"]["enabled"] == "on" + @allow_update_after async def set_enabled(self, enable: bool) -> dict: """Set the motion detection enabled state.""" params = {"enabled": "on" if enable else "off"} diff --git a/kasa/smartcam/modules/persondetection.py b/kasa/smartcam/modules/persondetection.py index 5d40ce51..96b31dc4 100644 --- a/kasa/smartcam/modules/persondetection.py +++ b/kasa/smartcam/modules/persondetection.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging from ...feature import Feature +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) @@ -39,6 +40,7 @@ class PersonDetection(SmartCamModule): """Return the person detection enabled state.""" return self.data["detection"]["enabled"] == "on" + @allow_update_after async def set_enabled(self, enable: bool) -> dict: """Set the person detection enabled state.""" params = {"enabled": "on" if enable else "off"} diff --git a/kasa/smartcam/modules/tamperdetection.py b/kasa/smartcam/modules/tamperdetection.py index 4705d36c..f572ded6 100644 --- a/kasa/smartcam/modules/tamperdetection.py +++ b/kasa/smartcam/modules/tamperdetection.py @@ -5,6 +5,7 @@ from __future__ import annotations import logging from ...feature import Feature +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule _LOGGER = logging.getLogger(__name__) @@ -39,6 +40,7 @@ class TamperDetection(SmartCamModule): """Return the tamper detection enabled state.""" return self.data["tamper_det"]["enabled"] == "on" + @allow_update_after async def set_enabled(self, enable: bool) -> dict: """Set the tamper detection enabled state.""" params = {"enabled": "on" if enable else "off"} diff --git a/kasa/smartcam/modules/time.py b/kasa/smartcam/modules/time.py index 4e5cb8df..54ee30e5 100644 --- a/kasa/smartcam/modules/time.py +++ b/kasa/smartcam/modules/time.py @@ -9,6 +9,7 @@ from zoneinfo import ZoneInfo, ZoneInfoNotFoundError from ...cachedzoneinfo import CachedZoneInfo from ...feature import Feature from ...interfaces import Time as TimeInterface +from ...smart.smartmodule import allow_update_after from ..smartcammodule import SmartCamModule @@ -73,6 +74,7 @@ class Time(SmartCamModule, TimeInterface): """Return device's current datetime.""" return self._time + @allow_update_after async def set_time(self, dt: datetime) -> dict: """Set device time.""" if not dt.tzinfo: