mirror of
https://github.com/ep1cman/unifi-protect-backup.git
synced 2025-12-05 23:53:30 +00:00
Adding support for SMART_DETECT_LINE events
This commit is contained in:
committed by
Sebastian Goscik
parent
80ad55d0d0
commit
1bb8496b30
@@ -10,7 +10,7 @@ from unifi_protect_backup import __version__
|
||||
from unifi_protect_backup.unifi_protect_backup_core import UnifiProtectBackup
|
||||
from unifi_protect_backup.utils import human_readable_to_float
|
||||
|
||||
DETECTION_TYPES = ["motion", "person", "vehicle", "ring"]
|
||||
DETECTION_TYPES = ["motion", "person", "vehicle", "ring", "line"]
|
||||
|
||||
|
||||
def _parse_detection_types(ctx, param, value):
|
||||
|
||||
@@ -42,7 +42,9 @@ class EventListener:
|
||||
async def start(self):
|
||||
"""Main Loop."""
|
||||
logger.debug("Subscribed to websocket")
|
||||
self._unsub_websocket_state = self._protect.subscribe_websocket_state(self._websocket_state_callback)
|
||||
self._unsub_websocket_state = self._protect.subscribe_websocket_state(
|
||||
self._websocket_state_callback
|
||||
)
|
||||
self._unsub = self._protect.subscribe_websocket(self._websocket_callback)
|
||||
|
||||
def _websocket_callback(self, msg: WSSubscriptionMessage) -> None:
|
||||
@@ -66,14 +68,24 @@ class EventListener:
|
||||
EventType.MOTION,
|
||||
EventType.SMART_DETECT,
|
||||
EventType.RING,
|
||||
EventType.SMART_DETECT_LINE,
|
||||
]:
|
||||
return
|
||||
if msg.new_obj.type is EventType.MOTION and "motion" not in self.detection_types:
|
||||
if (
|
||||
msg.new_obj.type is EventType.MOTION
|
||||
and "motion" not in self.detection_types
|
||||
):
|
||||
logger.extra_debug(f"Skipping unwanted motion detection event: {msg.new_obj.id}") # type: ignore
|
||||
return
|
||||
if msg.new_obj.type is EventType.RING and "ring" not in self.detection_types:
|
||||
logger.extra_debug(f"Skipping unwanted ring event: {msg.new_obj.id}") # type: ignore
|
||||
return
|
||||
if (
|
||||
msg.new_obj.type is EventType.SMART_DETECT_LINE
|
||||
and "line" not in self.detection_types
|
||||
):
|
||||
logger.extra_debug(f"Skipping unwanted line event: {msg.new_obj.id}") # type: ignore
|
||||
return
|
||||
elif msg.new_obj.type is EventType.SMART_DETECT:
|
||||
for event_smart_detection_type in msg.new_obj.smart_detect_types:
|
||||
if event_smart_detection_type not in self.detection_types:
|
||||
@@ -95,7 +107,9 @@ class EventListener:
|
||||
if "-" in msg.new_obj.id:
|
||||
msg.new_obj.id = msg.new_obj.id.split("-")[0]
|
||||
|
||||
logger.debug(f"Adding event {msg.new_obj.id} to queue (Current download queue={self._event_queue.qsize()})")
|
||||
logger.debug(
|
||||
f"Adding event {msg.new_obj.id} to queue (Current download queue={self._event_queue.qsize()})"
|
||||
)
|
||||
|
||||
def _websocket_state_callback(self, state: WebsocketState) -> None:
|
||||
"""Callback for websocket state messages.
|
||||
|
||||
@@ -65,7 +65,7 @@ class MissingEventChecker:
|
||||
events_chunk = await self._protect.get_events(
|
||||
start=start_time,
|
||||
end=end_time,
|
||||
types=[EventType.MOTION, EventType.SMART_DETECT, EventType.RING],
|
||||
types=[EventType.MOTION, EventType.SMART_DETECT, EventType.RING, EventType.SMART_DETECT_LINE],
|
||||
limit=chunk_size,
|
||||
)
|
||||
|
||||
@@ -107,6 +107,8 @@ class MissingEventChecker:
|
||||
return False
|
||||
if event.type is EventType.RING and "ring" not in self.detection_types:
|
||||
return False
|
||||
if event.type is EventType.SMART_DETECT_LINE and "line" not in self.detection_types:
|
||||
return False
|
||||
elif event.type is EventType.SMART_DETECT:
|
||||
for event_smart_detection_type in event.smart_detect_types:
|
||||
if event_smart_detection_type not in self.detection_types:
|
||||
|
||||
@@ -197,7 +197,7 @@ class UnifiProtectBackup:
|
||||
# Start the uiprotect connection by calling `update`
|
||||
logger.info("Connecting to Unifi Protect...")
|
||||
|
||||
delay = 5 # Start with a 5 second delay
|
||||
delay = 5 # Start with a 5 second delay
|
||||
max_delay = 3600 # 1 hour in seconds
|
||||
|
||||
for attempts in range(20):
|
||||
@@ -214,7 +214,6 @@ class UnifiProtectBackup:
|
||||
else:
|
||||
raise ConnectionError("Failed to connect to UniFi Protect after 20 attempts")
|
||||
|
||||
|
||||
# Add a lock to the protect client that can be used to prevent code accessing the client when it has
|
||||
# lost connection
|
||||
self._protect.connect_event = asyncio.Event()
|
||||
|
||||
Reference in New Issue
Block a user