Fixed undesired sunset detection reset behavior #4

Squashed commit of the following:

commit 733c4fb387649d58621a86ff483c3c42c787c58d
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Tue Dec 5 21:37:21 2023 -0600

    Fixed sunset detection reset behavior

commit c581ea62d59bd21e4f024bf50578f75338aa91c5
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Tue Dec 5 21:35:10 2023 -0600

    Updated config.yaml to reflect regular state
This commit is contained in:
Ashish D'Souza 2023-12-05 21:38:09 -06:00
parent 70a5c983ea
commit ce1497cf86
2 changed files with 16 additions and 10 deletions

View File

@ -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:

View File

@ -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:
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 as e:
print(e, file=sys.stderr)
except Exception:
traceback.print_exc()
def set_camera_detection(camera: str, value: bool, delay: int = 0) -> None: