Extend smartcam detection support (#1552)

New detection added with tests:

- bark detection
- glass detection
- line crossing detection
- meow detection
- vehicle detection
This commit is contained in:
Gabriele Pongelli
2025-08-25 15:20:33 +02:00
committed by GitHub
parent e21ab90e96
commit 0cd0434160
23 changed files with 1549 additions and 379 deletions

View File

@@ -4,14 +4,12 @@ from __future__ import annotations
import logging
from ...feature import Feature
from ...smart.smartmodule import allow_update_after
from ..smartcammodule import SmartCamModule
from kasa.smartcam.detectionmodule import DetectionModule
_LOGGER = logging.getLogger(__name__)
class TamperDetection(SmartCamModule):
class TamperDetection(DetectionModule):
"""Implementation of tamper detection module."""
REQUIRED_COMPONENT = "tamperDetection"
@@ -20,30 +18,7 @@ class TamperDetection(SmartCamModule):
QUERY_MODULE_NAME = "tamper_detection"
QUERY_SECTION_NAMES = "tamper_det"
def _initialize_features(self) -> None:
"""Initialize features after the initial update."""
self._add_feature(
Feature(
self._device,
id="tamper_detection",
name="Tamper detection",
container=self,
attribute_getter="enabled",
attribute_setter="set_enabled",
type=Feature.Type.Switch,
category=Feature.Category.Config,
)
)
@property
def enabled(self) -> bool:
"""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"}
return await self._device._query_setter_helper(
"setTamperDetectionConfig", self.QUERY_MODULE_NAME, "tamper_det", params
)
DETECTION_FEATURE_ID = "tamper_detection"
DETECTION_FEATURE_NAME = "Tamper detection"
QUERY_SETTER_NAME = "setTamperDetectionConfig"
QUERY_SET_SECTION_NAME = "tamper_det"