1313from . import TuyaConfigEntry
1414from .const import TUYA_DISCOVERY_NEW , DeviceCategory , DPCode
1515from .entity import TuyaEntity
16+ from .models import DPCodeBooleanWrapper
1617
1718CAMERAS : tuple [DeviceCategory , ...] = (
1819 DeviceCategory .DGHSXJ ,
@@ -35,7 +36,18 @@ def async_discover_device(device_ids: list[str]) -> None:
3536 for device_id in device_ids :
3637 device = manager .device_map [device_id ]
3738 if device .category in CAMERAS :
38- entities .append (TuyaCameraEntity (device , manager ))
39+ entities .append (
40+ TuyaCameraEntity (
41+ device ,
42+ manager ,
43+ motion_detection_switch = DPCodeBooleanWrapper .find_dpcode (
44+ device , DPCode .MOTION_SWITCH , prefer_function = True
45+ ),
46+ recording_status = DPCodeBooleanWrapper .find_dpcode (
47+ device , DPCode .RECORD_SWITCH
48+ ),
49+ )
50+ )
3951
4052 async_add_entities (entities )
4153
@@ -57,21 +69,30 @@ def __init__(
5769 self ,
5870 device : CustomerDevice ,
5971 device_manager : Manager ,
72+ * ,
73+ motion_detection_switch : DPCodeBooleanWrapper | None = None ,
74+ recording_status : DPCodeBooleanWrapper | None = None ,
6075 ) -> None :
6176 """Init Tuya Camera."""
6277 super ().__init__ (device , device_manager )
6378 CameraEntity .__init__ (self )
6479 self ._attr_model = device .product_name
80+ self ._motion_detection_switch = motion_detection_switch
81+ self ._recording_status = recording_status
6582
6683 @property
6784 def is_recording (self ) -> bool :
6885 """Return true if the device is recording."""
69- return self .device .status .get (DPCode .RECORD_SWITCH , False )
86+ if (status := self ._read_wrapper (self ._recording_status )) is not None :
87+ return status
88+ return False
7089
7190 @property
7291 def motion_detection_enabled (self ) -> bool :
7392 """Return the camera motion detection status."""
74- return self .device .status .get (DPCode .MOTION_SWITCH , False )
93+ if (status := self ._read_wrapper (self ._motion_detection_switch )) is not None :
94+ return status
95+ return False
7596
7697 async def stream_source (self ) -> str | None :
7798 """Return the source of the stream."""
@@ -95,10 +116,10 @@ async def async_camera_image(
95116 height = height ,
96117 )
97118
98- def enable_motion_detection (self ) -> None :
119+ async def async_enable_motion_detection (self ) -> None :
99120 """Enable motion detection in the camera."""
100- self ._send_command ([{ "code" : DPCode . MOTION_SWITCH , "value" : True }] )
121+ await self ._async_send_dpcode_update ( self . _motion_detection_switch , True )
101122
102- def disable_motion_detection (self ) -> None :
123+ async def async_disable_motion_detection (self ) -> None :
103124 """Disable motion detection in camera."""
104- self ._send_command ([{ "code" : DPCode . MOTION_SWITCH , "value" : False }] )
125+ await self ._async_send_dpcode_update ( self . _motion_detection_switch , False )
0 commit comments