From eedc2783c963cd9fd48d25d70de104d0c67e40be Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:08:17 -0500 Subject: [PATCH] Make ntfy url optional --- wyzely_detect/utils/cli_args.py | 4 +--- wyzely_detect/utils/notify.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/wyzely_detect/utils/cli_args.py b/wyzely_detect/utils/cli_args.py index 2b43bdf..8964cad 100644 --- a/wyzely_detect/utils/cli_args.py +++ b/wyzely_detect/utils/cli_args.py @@ -98,14 +98,12 @@ def set_argparse(): # 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 - # 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.add_argument( "--ntfy-url", default=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, help="The URL to send notifications to", ) diff --git a/wyzely_detect/utils/notify.py b/wyzely_detect/utils/notify.py index fce34de..d0c6b83 100644 --- a/wyzely_detect/utils/notify.py +++ b/wyzely_detect/utils/notify.py @@ -104,18 +104,23 @@ def thing_detected( ): respective_type[thing_name]["last_notification_time"] = time.time() print(f"Detected {thing_name} for {detection_duration} seconds") - headers = construct_ntfy_headers( - title=f"{thing_name} detected", - tag="rotating_light", - priority="default", - ) - send_notification( - 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") + if ntfy_url is None: + print( + "ntfy_url is None. Not sending notification. Set ntfy_url to send notifications" + ) + else: + headers = construct_ntfy_headers( + title=f"{thing_name} detected", + tag="rotating_light", + priority="default", + ) + send_notification( + 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 # Take the aliased objects_and_peoples and update the respective dictionary