From ce1497cf86b4d15619e35cdf34cfad4f44721ba2 Mon Sep 17 00:00:00 2001 From: Ashish D'Souza Date: Tue, 5 Dec 2023 21:38:09 -0600 Subject: [PATCH] Fixed undesired sunset detection reset behavior #4 Squashed commit of the following: commit 733c4fb387649d58621a86ff483c3c42c787c58d Author: Ashish D'Souza Date: Tue Dec 5 21:37:21 2023 -0600 Fixed sunset detection reset behavior commit c581ea62d59bd21e4f024bf50578f75338aa91c5 Author: Ashish D'Souza Date: Tue Dec 5 21:35:10 2023 -0600 Updated config.yaml to reflect regular state --- conf/config.yaml | 2 +- webcontrol/src/detection.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 1a13df4..01fd27c 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -65,7 +65,7 @@ cameras: output_args: record: preset-record-generic-audio-aac # Record with aac audio detect: - enabled: true + enabled: false width: 1920 height: 1080 motion: diff --git a/webcontrol/src/detection.py b/webcontrol/src/detection.py index 9f14f12..daffb69 100644 --- a/webcontrol/src/detection.py +++ b/webcontrol/src/detection.py @@ -1,6 +1,7 @@ import os import sys import json +import traceback from time import sleep from threading import Thread from datetime import datetime, time, timedelta @@ -22,8 +23,8 @@ def get_sunset() -> datetime: astronomical_json = json.loads(ipgeolocation_api_response.content) sunset_time = datetime.strptime(astronomical_json['sunset'], '%H:%M').time() - except Exception as e: - print(e, file=sys.stderr) + except Exception: + traceback.print_exc() sunset_time = time(20, 00, 00) finally: if sunset_time < datetime.now().time(): @@ -32,7 +33,7 @@ def get_sunset() -> datetime: return datetime.combine(sunset_date, sunset_time) -def reset_all_camera_detection_at_sunset(): +def reset_all_camera_detection_at_sunset() -> None: while True: try: sunset = get_sunset() @@ -40,14 +41,19 @@ def reset_all_camera_detection_at_sunset(): seconds_until_sunset = (sunset - datetime.now()).total_seconds() sleep(seconds_until_sunset) - # Get all camera names + # Get names of cameras with detection enabled in configuration frigate_api_response = requests.get('http://frigate:5000/api/config') frigate_api_response.raise_for_status() - all_camera_names = json.loads(frigate_api_response.content)['cameras'].keys() - for camera_name in all_camera_names: - set_camera_detection(camera_name, True) - except Exception as e: - print(e, file=sys.stderr) + + frigate_camera_config = json.loads(frigate_api_response.content)['cameras'] + for camera_name in frigate_camera_config: + camera_enabled = frigate_camera_config[camera_name].get('enabled', True) + detection_enabled = frigate_camera_config[camera_name].get('detect', {}).get('enabled', True) + + if camera_enabled and detection_enabled: + set_camera_detection(camera_name, True) + except Exception: + traceback.print_exc() def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None: