Make ntfy url optional

This commit is contained in:
slashtechno 2023-10-27 11:08:17 -05:00
parent f669a39056
commit eedc2783c9
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
2 changed files with 18 additions and 15 deletions

View File

@ -98,14 +98,12 @@ def set_argparse():
# Defaults for the stuff here and down are already set in notify.py. # Defaults for the stuff here and down are already set in notify.py.
# Setting them here just means that argparse will display the default values as defualt # Setting them here just means that argparse will display the default values as defualt
# TODO: Perhaps just remove the default parameter and just add to the help message that the default is set is x
# TODO: Make ntfy optional in ntfy.py. Currently, unless there is a local or LAN instance of ntfy, this can't run offline
notifcation_services = argparser.add_argument_group("Notification Services") notifcation_services = argparser.add_argument_group("Notification Services")
notifcation_services.add_argument( notifcation_services.add_argument(
"--ntfy-url", "--ntfy-url",
default=os.environ["NTFY_URL"] default=os.environ["NTFY_URL"]
if "NTFY_URL" in os.environ and os.environ["NTFY_URL"] != "" if "NTFY_URL" in os.environ and os.environ["NTFY_URL"] != ""
else "https://ntfy.sh/wyzely-detect", else None,
type=str, type=str,
help="The URL to send notifications to", help="The URL to send notifications to",
) )

View File

@ -104,18 +104,23 @@ def thing_detected(
): ):
respective_type[thing_name]["last_notification_time"] = time.time() respective_type[thing_name]["last_notification_time"] = time.time()
print(f"Detected {thing_name} for {detection_duration} seconds") print(f"Detected {thing_name} for {detection_duration} seconds")
headers = construct_ntfy_headers( if ntfy_url is None:
title=f"{thing_name} detected", print(
tag="rotating_light", "ntfy_url is None. Not sending notification. Set ntfy_url to send notifications"
priority="default", )
) else:
send_notification( headers = construct_ntfy_headers(
data=f"{thing_name} detected for {detection_duration} seconds", title=f"{thing_name} detected",
headers=headers, tag="rotating_light",
url=ntfy_url, priority="default",
) )
# Reset the detection duration send_notification(
print("Just sent a notification - resetting detection duration") data=f"{thing_name} detected for {detection_duration} seconds",
headers=headers,
url=ntfy_url,
)
# Reset the detection duration
print("Just sent a notification - resetting detection duration")
respective_type[thing_name]["detection_duration"] = 0 respective_type[thing_name]["detection_duration"] = 0
# Take the aliased objects_and_peoples and update the respective dictionary # Take the aliased objects_and_peoples and update the respective dictionary