Fixed sunset detection reset #6

This commit is contained in:
Ashish D'Souza 2023-12-17 12:40:26 -06:00
parent ce1497cf86
commit 4ec4531f86
1 changed files with 8 additions and 8 deletions

View File

@ -1,8 +1,8 @@
import os import os
import sys import sys
import json import json
import time
import traceback import traceback
from time import sleep
from threading import Thread from threading import Thread
from datetime import datetime, time, timedelta from datetime import datetime, time, timedelta
@ -36,16 +36,16 @@ def get_sunset() -> datetime:
def reset_all_camera_detection_at_sunset() -> None: def reset_all_camera_detection_at_sunset() -> None:
while True: while True:
try: 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 # Get names of cameras with detection enabled in configuration
frigate_api_response = requests.get('http://frigate:5000/api/config') frigate_api_response = requests.get('http://frigate:5000/api/config')
frigate_api_response.raise_for_status() frigate_api_response.raise_for_status()
frigate_camera_config = json.loads(frigate_api_response.content)['cameras'] 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: for camera_name in frigate_camera_config:
camera_enabled = frigate_camera_config[camera_name].get('enabled', True) camera_enabled = frigate_camera_config[camera_name].get('enabled', True)
detection_enabled = frigate_camera_config[camera_name].get('detect', {}).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: 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')} mqtt_auth = {'username': os.environ.get('MQTT_USERNAME'), 'password': os.environ.get('MQTT_PASSWORD')}
if not all(mqtt_auth.values()): if not all(mqtt_auth.values()):