diff --git a/webcontrol/src/detection.py b/webcontrol/src/detection.py index daffb69..39a335e 100644 --- a/webcontrol/src/detection.py +++ b/webcontrol/src/detection.py @@ -1,8 +1,8 @@ import os import sys import json +import time import traceback -from time import sleep from threading import Thread from datetime import datetime, time, timedelta @@ -36,16 +36,16 @@ def get_sunset() -> datetime: def reset_all_camera_detection_at_sunset() -> None: while True: try: - sunset = get_sunset() - print(f'Waiting until {sunset} to reset detection for all cameras...', file=sys.stderr) - seconds_until_sunset = (sunset - datetime.now()).total_seconds() - sleep(seconds_until_sunset) - # 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() - frigate_camera_config = json.loads(frigate_api_response.content)['cameras'] + + sunset = get_sunset() + print(f'Waiting until {sunset} to reset detection for all cameras...', file=sys.stderr) + seconds_until_sunset = (sunset - datetime.now()).total_seconds() + time.sleep(seconds_until_sunset) + 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) @@ -57,7 +57,7 @@ def reset_all_camera_detection_at_sunset() -> None: def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None: - sleep(delay) + time.sleep(delay) mqtt_auth = {'username': os.environ.get('MQTT_USERNAME'), 'password': os.environ.get('MQTT_PASSWORD')} if not all(mqtt_auth.values()):