@@ -98,7 +98,7 @@ class DahuaDataUpdateCoordinator(DataUpdateCoordinator):
98
98
def __init__ (self , hass : HomeAssistant , dahua_client : DahuaClient , events : list ) -> None :
99
99
"""Initialize."""
100
100
self .client : DahuaClient = dahua_client
101
- self .dahua_event : DahuaEventThread = None
101
+ self .dahua_event : DahuaEventThread
102
102
self .platforms = []
103
103
self .initialized = False
104
104
self .model = ""
@@ -107,16 +107,18 @@ def __init__(self, hass: HomeAssistant, dahua_client: DahuaClient, events: list)
107
107
self .channels = {"1" : "1" }
108
108
self .events : list = events
109
109
self .motion_timestamp_seconds = 0
110
+ self .cross_line_detection_timestamp_seconds = 0
110
111
self .motion_listener : CALLBACK_TYPE
112
+ self .cross_line_detection_listener : CALLBACK_TYPE
111
113
self ._supports_coaxial_control = False
112
114
self ._supports_disarming_linkage = False
115
+ self .dahua_event = DahuaEventThread (hass , dahua_client , self .on_receive , events )
113
116
114
117
super ().__init__ (hass , _LOGGER , name = DOMAIN , update_interval = SCAN_INTERVAL_SECONDS )
115
118
116
119
async def async_start_event_listener (self ):
117
120
""" setup """
118
121
if self .events is not None :
119
- self .dahua_event = DahuaEventThread (self .hass , self .machine_name , self .client , self .on_receive , self .events )
120
122
self .dahua_event .start ()
121
123
122
124
async def async_stop (self , event : Any ):
@@ -224,6 +226,7 @@ def on_receive(self, data_bytes: bytes):
224
226
225
227
# When there's a motion start event we'll set a flag to the current timestmap in seconds.
226
228
# We'll reset it when the motion stops. We'll use this elsewhere to know how long to trigger a motion sensor
229
+ # TODO: Generalize events so we don't create a block for each one
227
230
if event ["Code" ] == "VideoMotion" :
228
231
action = event ["action" ]
229
232
if action == "Start" :
@@ -234,13 +237,27 @@ def on_receive(self, data_bytes: bytes):
234
237
self .motion_timestamp_seconds = 0
235
238
if self .motion_listener :
236
239
self .motion_listener ()
240
+ if event ["Code" ] == "CrossLineDetection" :
241
+ action = event ["action" ]
242
+ if action == "Start" :
243
+ self .cross_line_detection_timestamp_seconds = int (time .time ())
244
+ if self .cross_line_detection_listener :
245
+ self .cross_line_detection_listener ()
246
+ elif action == "Stop" :
247
+ self .cross_line_detection_timestamp_seconds = 0
248
+ if self .cross_line_detection_listener :
249
+ self .cross_line_detection_listener ()
237
250
238
251
self .hass .bus .fire ("dahua_event_received" , event )
239
252
240
253
def add_motion_listener (self , listener : CALLBACK_TYPE ):
241
254
""" Adds the motion listener. This callback will be called on motion events """
242
255
self .motion_listener = listener
243
256
257
+ def add_cross_line_detection_listener (self , listener : CALLBACK_TYPE ):
258
+ """ Adds the CrossLineDetection listener. This callback will be called on CrossLineDetection events """
259
+ self .cross_line_detection_listener = listener
260
+
244
261
def supports_siren (self ) -> bool :
245
262
"""
246
263
Returns true if this camera has a siren. For example, the IPC-HDW3849HP-AS-PV does
0 commit comments