From e2eb7858daf040333ad2e6ffb4cedfe4f6787e5a Mon Sep 17 00:00:00 2001 From: Sebastian Goscik Date: Fri, 18 Mar 2022 20:53:02 +0000 Subject: [PATCH] Added support for doorbell ring events --- README.md | 4 ++-- unifi_protect_backup/cli.py | 2 +- unifi_protect_backup/unifi_protect_backup.py | 11 +++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e4b6640..ce4c556 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,8 @@ Options: be to set a bandwidth limit, for example. --detection-types TEXT A comma separated list of which types of detections to backup. Valid options are: - `motion`, `person`, `vehicle` [default: - motion,person,vehicle] + `motion`, `person`, `vehicle`, `ring` + [default: motion,person,vehicle,ring] --ignore-camera TEXT IDs of cameras for which events should not be backed up. Use multiple times to ignore multiple IDs. If being set as an environment diff --git a/unifi_protect_backup/cli.py b/unifi_protect_backup/cli.py index 8c671a1..32c9690 100644 --- a/unifi_protect_backup/cli.py +++ b/unifi_protect_backup/cli.py @@ -6,7 +6,7 @@ import click 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): diff --git a/unifi_protect_backup/unifi_protect_backup.py b/unifi_protect_backup/unifi_protect_backup.py index 08e3437..03182ef 100644 --- a/unifi_protect_backup/unifi_protect_backup.py +++ b/unifi_protect_backup/unifi_protect_backup.py @@ -424,11 +424,12 @@ class UnifiProtectBackup: return if msg.new_obj.end is None: 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: logger.extra_debug(f"Skipping unwanted motion detection event: {msg.new_obj.id}") 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: for event_smart_detection_type in msg.new_obj.smart_detect_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.debug(f"Remaining Queue: {self._download_queue.qsize()}") logger.debug(f" Camera: {await self._get_camera_name(event.camera_id)}") - if event.type == EventType.MOTION: - logger.debug(f" Type: {event.type}") - elif event.type == EventType.SMART_DETECT: + if event.type == EventType.SMART_DETECT: logger.debug(f" Type: {event.type} ({', '.join(event.smart_detect_types)})") 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" End: {event.end.strftime('%Y-%m-%dT%H-%M-%S')} ({event.end.timestamp()})") duration = (event.end - event.start).total_seconds()