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: