mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-13 02:48:07 +00:00
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:

committed by
GitHub

parent
e21ab90e96
commit
0cd0434160
58
kasa/smartcam/detectionmodule.py
Normal file
58
kasa/smartcam/detectionmodule.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""SmartCamModule base class for all detections."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from kasa.feature import Feature
|
||||
from kasa.smart.smartmodule import allow_update_after
|
||||
from kasa.smartcam.smartcammodule import SmartCamModule
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DetectionModule(SmartCamModule):
|
||||
"""SmartCamModule base class for all detections."""
|
||||
|
||||
#: Feature ID, filled by inheriting class
|
||||
DETECTION_FEATURE_ID: str = ""
|
||||
|
||||
#: User-friendly short description, filled by inheriting class
|
||||
DETECTION_FEATURE_NAME: str = ""
|
||||
|
||||
#: Feature setter method name, filled by inheriting class
|
||||
QUERY_SETTER_NAME: str = ""
|
||||
|
||||
#: Feature section name, filled by inheriting class
|
||||
QUERY_SET_SECTION_NAME: str = ""
|
||||
|
||||
def _initialize_features(self) -> None:
|
||||
"""Initialize features after the initial update."""
|
||||
self._add_feature(
|
||||
Feature(
|
||||
self._device,
|
||||
id=self.DETECTION_FEATURE_ID,
|
||||
name=self.DETECTION_FEATURE_NAME,
|
||||
container=self,
|
||||
attribute_getter="enabled",
|
||||
attribute_setter="set_enabled",
|
||||
type=Feature.Type.Switch,
|
||||
category=Feature.Category.Config,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def enabled(self) -> bool:
|
||||
"""Return the detection enabled state."""
|
||||
return self.data[self.QUERY_SECTION_NAMES]["enabled"] == "on"
|
||||
|
||||
@allow_update_after
|
||||
async def set_enabled(self, enable: bool) -> dict:
|
||||
"""Set the detection enabled state."""
|
||||
params = {"enabled": "on" if enable else "off"}
|
||||
return await self._device._query_setter_helper(
|
||||
self.QUERY_SETTER_NAME,
|
||||
self.QUERY_MODULE_NAME,
|
||||
self.QUERY_SET_SECTION_NAME,
|
||||
params,
|
||||
)
|
Reference in New Issue
Block a user