Added support for doorbell ring events

This commit is contained in:
Sebastian Goscik
2022-03-18 20:53:02 +00:00
parent 453fed6c57
commit e2eb7858da
3 changed files with 8 additions and 9 deletions

View File

@@ -74,8 +74,8 @@ Options:
be to set a bandwidth limit, for example. be to set a bandwidth limit, for example.
--detection-types TEXT A comma separated list of which types of --detection-types TEXT A comma separated list of which types of
detections to backup. Valid options are: detections to backup. Valid options are:
`motion`, `person`, `vehicle` [default: `motion`, `person`, `vehicle`, `ring`
motion,person,vehicle] [default: motion,person,vehicle,ring]
--ignore-camera TEXT IDs of cameras for which events should not --ignore-camera TEXT IDs of cameras for which events should not
be backed up. Use multiple times to ignore be backed up. Use multiple times to ignore
multiple IDs. If being set as an environment multiple IDs. If being set as an environment

View File

@@ -6,7 +6,7 @@ import click
from unifi_protect_backup import UnifiProtectBackup, __version__ from unifi_protect_backup import UnifiProtectBackup, __version__
DETECTION_TYPES = ["motion", "person", "vehicle"] DETECTION_TYPES = ["motion", "person", "vehicle", "ring"]
def _parse_detection_types(ctx, param, value): def _parse_detection_types(ctx, param, value):

View File

@@ -424,11 +424,12 @@ class UnifiProtectBackup:
return return
if msg.new_obj.end is None: if msg.new_obj.end is None:
return return
if msg.new_obj.type not in {EventType.MOTION, EventType.SMART_DETECT}:
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}") logger.extra_debug(f"Skipping unwanted motion detection event: {msg.new_obj.id}")
return 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}")
return
elif msg.new_obj.type is EventType.SMART_DETECT: elif msg.new_obj.type is EventType.SMART_DETECT:
for event_smart_detection_type in msg.new_obj.smart_detect_types: for event_smart_detection_type in msg.new_obj.smart_detect_types:
if event_smart_detection_type not in self.detection_types: if event_smart_detection_type not in self.detection_types:
@@ -458,12 +459,10 @@ class UnifiProtectBackup:
logger.info(f"Backing up event: {event.id}") logger.info(f"Backing up event: {event.id}")
logger.debug(f"Remaining Queue: {self._download_queue.qsize()}") logger.debug(f"Remaining Queue: {self._download_queue.qsize()}")
logger.debug(f" Camera: {await self._get_camera_name(event.camera_id)}") logger.debug(f" Camera: {await self._get_camera_name(event.camera_id)}")
if event.type == EventType.MOTION: if event.type == EventType.SMART_DETECT:
logger.debug(f" Type: {event.type}")
elif event.type == EventType.SMART_DETECT:
logger.debug(f" Type: {event.type} ({', '.join(event.smart_detect_types)})") logger.debug(f" Type: {event.type} ({', '.join(event.smart_detect_types)})")
else: else:
ValueError(f"Unexpected event type: `{event.type}") logger.debug(f" Type: {event.type}")
logger.debug(f" Start: {event.start.strftime('%Y-%m-%dT%H-%M-%S')} ({event.start.timestamp()})") logger.debug(f" Start: {event.start.strftime('%Y-%m-%dT%H-%M-%S')} ({event.start.timestamp()})")
logger.debug(f" End: {event.end.strftime('%Y-%m-%dT%H-%M-%S')} ({event.end.timestamp()})") logger.debug(f" End: {event.end.strftime('%Y-%m-%dT%H-%M-%S')} ({event.end.timestamp()})")
duration = (event.end - event.start).total_seconds() duration = (event.end - event.start).total_seconds()