Add motion module to smartcam

This commit is contained in:
Steven B 2024-12-18 13:39:23 +00:00
parent 47934dbf96
commit 56261e649d
No known key found for this signature in database
GPG Key ID: 6D5B46B3679F2A43
2 changed files with 49 additions and 0 deletions

View File

@ -8,6 +8,7 @@ from .homekit import HomeKit
from .led import Led from .led import Led
from .lensmask import LensMask from .lensmask import LensMask
from .matter import Matter from .matter import Matter
from .motion import Motion
from .pantilt import PanTilt from .pantilt import PanTilt
from .time import Time from .time import Time
@ -21,5 +22,6 @@ __all__ = [
"Time", "Time",
"HomeKit", "HomeKit",
"Matter", "Matter",
"Motion",
"LensMask", "LensMask",
] ]

View File

@ -0,0 +1,47 @@
"""Implementation of motion detection module."""
from __future__ import annotations
import logging
from ...feature import Feature
from ..smartcammodule import SmartCamModule
_LOGGER = logging.getLogger(__name__)
class Motion(SmartCamModule):
"""Implementation of lens mask module."""
REQUIRED_COMPONENT = "detection"
QUERY_GETTER_NAME = "getDetectionConfig"
QUERY_MODULE_NAME = "motion_detection"
QUERY_SECTION_NAMES = "motion_det"
def _initialize_features(self) -> None:
"""Initialize features after the initial update."""
self._add_feature(
Feature(
self._device,
id="motion_detection_enabled",
name="Motion detection enabled",
container=self,
attribute_getter="enabled",
attribute_setter="set_enabled",
type=Feature.Type.Switch,
category=Feature.Category.Primary,
)
)
@property
def enabled(self) -> bool:
"""Return the lens mask state."""
return self.data["motion_det"]["enabled"] == "on"
async def set_enabled(self, state: bool) -> dict:
"""Set the lens mask state."""
params = {"enabled": "on" if state else "off"}
return await self._device._query_setter_helper(
"setLensMaskConfig", self.QUERY_MODULE_NAME, "motion_det", params
)