|
37 | 37 | DAHUA_SERIAL_NUMBER
|
38 | 38 | ]
|
39 | 39 |
|
40 |
| -ENDPOINT_ACCESS_CONTROL = "accessControl.cgi?action=openDoor&UserID=101&Type=Remote&channel=" |
41 |
| - |
42 | 40 |
|
43 | 41 | class DahuaVTOClient(asyncio.Protocol):
|
44 | 42 | requestId: int
|
@@ -76,11 +74,10 @@ def __init__(self, host: str, username: str, password: str, is_ssl: bool, on_rec
|
76 | 74 |
|
77 | 75 | # This is the hook back into HA
|
78 | 76 | self.on_receive_vto_event = on_receive_vto_event
|
79 |
| - |
80 | 77 | self._loop = asyncio.get_event_loop()
|
81 | 78 |
|
82 | 79 | def connection_made(self, transport):
|
83 |
| - _LOGGER.debug("Connection established") |
| 80 | + _LOGGER.debug("VTO connection established") |
84 | 81 |
|
85 | 82 | try:
|
86 | 83 | self.transport = transport
|
@@ -266,6 +263,15 @@ def handle_access_control(message):
|
266 | 263 |
|
267 | 264 | self.send(DAHUA_CONFIG_MANAGER_GETCONFIG, handle_access_control, request_data)
|
268 | 265 |
|
| 266 | + async def cancel_call(self): |
| 267 | + _LOGGER.info("Cancelling call on VTO") |
| 268 | + |
| 269 | + def cancel(message): |
| 270 | + _LOGGER.info(f"Got cancel call response: {message}") |
| 271 | + |
| 272 | + self.send("console.runCmd", cancel, {"command": "hc"}) |
| 273 | + return True |
| 274 | + |
269 | 275 | def load_version(self):
|
270 | 276 | _LOGGER.info("Get version")
|
271 | 277 |
|
@@ -326,52 +332,6 @@ def handle_keep_alive(message):
|
326 | 332 |
|
327 | 333 | self.send(DAHUA_GLOBAL_KEEPALIVE, handle_keep_alive, request_data)
|
328 | 334 |
|
329 |
| - def access_control_open_door(self, door_id: int = 1): |
330 |
| - is_locked = self.lock_status.get(door_id, False) |
331 |
| - should_unlock = False |
332 |
| - |
333 |
| - try: |
334 |
| - if is_locked: |
335 |
| - _LOGGER.info(f"Access Control - Door #{door_id} is already unlocked, ignoring request") |
336 |
| - |
337 |
| - else: |
338 |
| - is_locked = True |
339 |
| - should_unlock = True |
340 |
| - |
341 |
| - self.lock_status[door_id] = is_locked |
342 |
| - self.publish_lock_state(door_id, False) |
343 |
| - |
344 |
| - url = f"{self.base_url}{ENDPOINT_ACCESS_CONTROL}{door_id}" |
345 |
| - |
346 |
| - response = requests.get(url, verify=False, auth=self.auth) |
347 |
| - |
348 |
| - response.raise_for_status() |
349 |
| - |
350 |
| - except Exception as ex: |
351 |
| - exc_type, exc_obj, exc_tb = sys.exc_info() |
352 |
| - |
353 |
| - _LOGGER.error(f"Failed to open door, error: {ex}, Line: {exc_tb.tb_lineno}") |
354 |
| - |
355 |
| - if should_unlock and is_locked: |
356 |
| - Timer(float(self.hold_time), self.magnetic_unlock, (self, door_id)).start() |
357 |
| - |
358 |
| - @staticmethod |
359 |
| - def magnetic_unlock(self, door_id): |
360 |
| - self.lock_status[door_id] = False |
361 |
| - self.publish_lock_state(door_id, True) |
362 |
| - |
363 |
| - def publish_lock_state(self, door_id: int, is_locked: bool): |
364 |
| - state = "Locked" if is_locked else "Unlocked" |
365 |
| - |
366 |
| - _LOGGER.info(f"Access Control - {state} magnetic lock #{door_id}") |
367 |
| - |
368 |
| - message = { |
369 |
| - "door": door_id, |
370 |
| - "isLocked": is_locked |
371 |
| - } |
372 |
| - |
373 |
| - _LOGGER.info("locked %s", json.dumps(message, indent=4)) |
374 |
| - |
375 | 335 | @staticmethod
|
376 | 336 | def parse_response(response):
|
377 | 337 | result = []
|
|
0 commit comments