Added sunset delay to allow full darkness #7 #8

Squashed commit of the following:

commit 423931bcd23136ff4aea6b1cb9d9bf6dfc210f5a
Author: Ashish D'Souza <sudouser512@gmail.com>
Date:   Sat Jan 27 16:03:57 2024 -0600

    Added 30 minute sunset delay
This commit is contained in:
Ashish D'Souza 2024-01-27 16:04:39 -06:00
parent f3dfaeea1b
commit c58751e6dd
1 changed files with 4 additions and 4 deletions

View File

@ -14,7 +14,7 @@ import paho.mqtt.publish as mqtt_publish
blueprint = Blueprint('detection', __name__)
def get_sunset() -> dt.datetime:
def get_sunset_time() -> dt.datetime:
sunset_date = dt.datetime.now().date()
try:
IPGEOLOCATION_API_KEY = os.environ['IPGEOLOCATION_API_KEY']
@ -41,9 +41,9 @@ def reset_all_camera_detection_at_sunset() -> None:
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 - dt.datetime.now()).total_seconds()
sunset_time = get_sunset_time() + dt.timedelta(minutes=30)
print(f'Waiting until {sunset_time} to reset detection for all cameras...', file=sys.stderr)
seconds_until_sunset = (sunset_time - dt.datetime.now()).total_seconds()
time.sleep(seconds_until_sunset)
for camera_name in frigate_camera_config: