FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Extend smartcam detection support (#1552) · pillarsdotnet/python-kasa@cc22f72 · GitHub

Repository navigation

Commit cc22f72

Browse files
authored
Extend smartcam detection support (python-kasa#1552)
New detection added with tests: - bark detection - glass detection - line crossing detection - meow detection - vehicle detection
1 parent 81d3731 commit cc22f72

23 files changed

Lines changed: 1549 additions & 379 deletions

‎SUPPORTED.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ All Tapo devices require authentication.<br>Hub-Connected Devices may work acros
293293
- Hardware: 2.0 (EU) / Firmware: 1.4.3
294294
- **C220**
295295
- Hardware: 1.0 (EU) / Firmware: 1.2.2
296+
- Hardware: 1.0 (EU) / Firmware: 1.2.5
296297
- **C225**
297298
- Hardware: 2.0 (US) / Firmware: 1.0.11
298299
- **C325WB**

‎devtools/helpers/smartcamrequests.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
{"getWhitelampConfig": {"image": {"name": "switch"}}},
4545
{"getMsgPushConfig": {"msg_push": {"name": ["chn1_msg_push_info"]}}},
4646
{"getSdCardStatus": {"harddisk_manage": {"table": ["hd_info"]}}},
47+
{
48+
"getLinecrossingDetectionConfig": {
49+
"linecrossing_detection": {"name": ["detection", "arming_schedule"]}
50+
}
51+
},
4752
{"getCircularRecordingConfig": {"harddisk_manage": {"name": "harddisk"}}},
4853
{"getRecordPlan": {"record_plan": {"name": ["chn1_channel"]}}},
4954
{"getAudioConfig": {"audio_config": {"name": ["speaker", "microphone"]}}},

‎kasa/smartcam/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Package for supporting tapo-branded cameras."""
22

3+
from .detectionmodule import DetectionModule
34
from .smartcamchild import SmartCamChild
45
from .smartcamdevice import SmartCamDevice
56

6-
__all__ = ["SmartCamDevice", "SmartCamChild"]
7+
__all__ = ["SmartCamDevice", "SmartCamChild", "DetectionModule"]

‎kasa/smartcam/detectionmodule.py‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""SmartCamModule base class for all detections."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
7+
from kasa.feature import Feature
8+
from kasa.smart.smartmodule import allow_update_after
9+
from kasa.smartcam.smartcammodule import SmartCamModule
10+
11+
_LOGGER = logging.getLogger(__name__)
12+
13+
14+
class DetectionModule(SmartCamModule):
15+
"""SmartCamModule base class for all detections."""
16+
17+
#: Feature ID, filled by inheriting class
18+
DETECTION_FEATURE_ID: str = ""
19+
20+
#: User-friendly short description, filled by inheriting class
21+
DETECTION_FEATURE_NAME: str = ""
22+
23+
#: Feature setter method name, filled by inheriting class
24+
QUERY_SETTER_NAME: str = ""
25+
26+
#: Feature section name, filled by inheriting class
27+
QUERY_SET_SECTION_NAME: str = ""
28+
29+
def _initialize_features(self) -> None:
30+
"""Initialize features after the initial update."""
31+
self._add_feature(
32+
Feature(
33+
self._device,
34+
id=self.DETECTION_FEATURE_ID,
35+
name=self.DETECTION_FEATURE_NAME,
36+
container=self,
37+
attribute_getter="enabled",
38+
attribute_setter="set_enabled",
39+
type=Feature.Type.Switch,
40+
category=Feature.Category.Config,
41+
)
42+
)
43+
44+
@property
45+
def enabled(self) -> bool:
46+
"""Return the detection enabled state."""
47+
return self.data[self.QUERY_SECTION_NAMES]["enabled"] == "on"
48+
49+
@allow_update_after
50+
async def set_enabled(self, enable: bool) -> dict:
51+
"""Set the detection enabled state."""
52+
params = {"enabled": "on" if enable else "off"}
53+
return await self._device._query_setter_helper(
54+
self.QUERY_SETTER_NAME,
55+
self.QUERY_MODULE_NAME,
56+
self.QUERY_SET_SECTION_NAME,
57+
params,
58+
)

‎kasa/smartcam/modules/__init__.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@
22

33
from .alarm import Alarm
44
from .babycrydetection import BabyCryDetection
5+
from .barkdetection import BarkDetection
56
from .battery import Battery
67
from .camera import Camera
78
from .childdevice import ChildDevice
89
from .childsetup import ChildSetup
910
from .device import DeviceModule
11+
from .glassdetection import GlassDetection
1012
from .homekit import HomeKit
1113
from .led import Led
1214
from .lensmask import LensMask
15+
from .linecrossingdetection import LineCrossingDetection
1316
from .matter import Matter
17+
from .meowdetection import MeowDetection
1418
from .motiondetection import MotionDetection
1519
from .pantilt import PanTilt
1620
from .persondetection import PersonDetection
1721
from .petdetection import PetDetection
1822
from .tamperdetection import TamperDetection
1923
from .time import Time
24+
from .vehicledetection import VehicleDetection
2025

2126
__all__ = [
2227
"Alarm",
2328
"BabyCryDetection",
29+
"BarkDetection",
2430
"Battery",
2531
"Camera",
2632
"ChildDevice",
2733
"ChildSetup",
2834
"DeviceModule",
35+
"GlassDetection",
2936
"Led",
37+
"LineCrossingDetection",
38+
"MeowDetection",
3039
"PanTilt",
3140
"PersonDetection",
3241
"PetDetection",
@@ -36,4 +45,5 @@
3645
"MotionDetection",
3746
"LensMask",
3847
"TamperDetection",
48+
"VehicleDetection",
3949
]

‎kasa/smartcam/modules/babycrydetection.py‎

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
import logging
66

7-
from ...feature import Feature
8-
from ...smart.smartmodule import allow_update_after
9-
from ..smartcammodule import SmartCamModule
7+
from kasa.smartcam.detectionmodule import DetectionModule
108

119
_LOGGER = logging.getLogger(__name__)
1210

1311

14-
class BabyCryDetection(SmartCamModule):
12+
class BabyCryDetection(DetectionModule):
1513
"""Implementation of baby cry detection module."""
1614

1715
REQUIRED_COMPONENT = "babyCryDetection"
@@ -20,30 +18,7 @@ class BabyCryDetection(SmartCamModule):
2018
QUERY_MODULE_NAME = "sound_detection"
2119
QUERY_SECTION_NAMES = "bcd"
2220

23-
def _initialize_features(self) -> None:
24-
"""Initialize features after the initial update."""
25-
self._add_feature(
26-
Feature(
27-
self._device,
28-
id="baby_cry_detection",
29-
name="Baby cry detection",
30-
container=self,
31-
attribute_getter="enabled",
32-
attribute_setter="set_enabled",
33-
type=Feature.Type.Switch,
34-
category=Feature.Category.Config,
35-
)
36-
)
37-
38-
@property
39-
def enabled(self) -> bool:
40-
"""Return the baby cry detection enabled state."""
41-
return self.data["bcd"]["enabled"] == "on"
42-
43-
@allow_update_after
44-
async def set_enabled(self, enable: bool) -> dict:
45-
"""Set the baby cry detection enabled state."""
46-
params = {"enabled": "on" if enable else "off"}
47-
return await self._device._query_setter_helper(
48-
"setBCDConfig", self.QUERY_MODULE_NAME, "bcd", params
49-
)
21+
DETECTION_FEATURE_ID = "baby_cry_detection"
22+
DETECTION_FEATURE_NAME = "Baby cry detection"
23+
QUERY_SETTER_NAME = "setBCDConfig"
24+
QUERY_SET_SECTION_NAME = "bcd"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Implementation of bark detection module."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
7+
from kasa.smartcam.detectionmodule import DetectionModule
8+
9+
_LOGGER = logging.getLogger(__name__)
10+
11+
12+
class BarkDetection(DetectionModule):
13+
"""Implementation of bark detection module."""
14+
15+
REQUIRED_COMPONENT = "barkDetection"
16+
17+
QUERY_GETTER_NAME = "getBarkDetectionConfig"
18+
QUERY_MODULE_NAME = "bark_detection"
19+
QUERY_SECTION_NAMES = "detection"
20+
21+
DETECTION_FEATURE_ID = "bark_detection"
22+
DETECTION_FEATURE_NAME = "Bark detection"
23+
QUERY_SETTER_NAME = "setBarkDetectionConfig"
24+
QUERY_SET_SECTION_NAME = "detection"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Implementation of glass detection module."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
7+
from kasa.smartcam.detectionmodule import DetectionModule
8+
9+
_LOGGER = logging.getLogger(__name__)
10+
11+
12+
class GlassDetection(DetectionModule):
13+
"""Implementation of glass detection module."""
14+
15+
REQUIRED_COMPONENT = "glassDetection"
16+
17+
QUERY_GETTER_NAME = "getGlassDetectionConfig"
18+
QUERY_MODULE_NAME = "glass_detection"
19+
QUERY_SECTION_NAMES = "detection"
20+
21+
DETECTION_FEATURE_ID = "glass_detection"
22+
DETECTION_FEATURE_NAME = "Glass detection"
23+
QUERY_SETTER_NAME = "setGlassDetectionConfig"
24+
QUERY_SET_SECTION_NAME = "detection"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Implementation of line crossing detection module."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
7+
from kasa.smartcam.detectionmodule import DetectionModule
8+
9+
_LOGGER = logging.getLogger(__name__)
10+
11+
12+
class LineCrossingDetection(DetectionModule):
13+
"""Implementation of line crossing detection module."""
14+
15+
REQUIRED_COMPONENT = "linecrossingDetection"
16+
17+
QUERY_GETTER_NAME = "getLinecrossingDetectionConfig"
18+
QUERY_MODULE_NAME = "linecrossing_detection"
19+
QUERY_SECTION_NAMES = "detection"
20+
21+
DETECTION_FEATURE_ID = "line_crossing_detection"
22+
DETECTION_FEATURE_NAME = "Line crossing detection"
23+
QUERY_SETTER_NAME = "setLinecrossingDetectionConfig"
24+
QUERY_SET_SECTION_NAME = "detection"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Implementation of meow detection module."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
7+
from kasa.smartcam.detectionmodule import DetectionModule
8+
9+
_LOGGER = logging.getLogger(__name__)
10+
11+
12+
class MeowDetection(DetectionModule):
13+
"""Implementation of meow detection module."""
14+
15+
REQUIRED_COMPONENT = "meowDetection"
16+
17+
QUERY_GETTER_NAME = "getMeowDetectionConfig"
18+
QUERY_MODULE_NAME = "meow_detection"
19+
QUERY_SECTION_NAMES = "detection"
20+
21+
DETECTION_FEATURE_ID = "meow_detection"
22+
DETECTION_FEATURE_NAME = "Meow detection"
23+
QUERY_SETTER_NAME = "setMeowDetectionConfig"
24+
QUERY_SET_SECTION_NAME = "detection"

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL