Skip to content

Commit

Permalink
reorganized icon prefixing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wsw70 committed Apr 25, 2024
1 parent 8bcace3 commit 40ecb72
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions simplemonitor/Alerters/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@ def __init__(self, config_options: dict) -> None:
str,
self.get_config_option("icon_prefix", required_type="bool", default=False),
)
self.ntfy_icon_failed = cast(
str,
self.get_config_option("icon_failed", required_type="str", default="274C"),
)
self.ntfy_icon_succeeded = cast(
str,
self.get_config_option(
"icon_succeeded", required_type="str", default="2705"
),
)
self.ntfy_icon_failed = chr(int(cast(str,self.get_config_option("icon_failed", required_type="str", default="274C")), 16))
self.ntfy_icon_succeeded = chr(int(cast(str, self.get_config_option("icon_succeeded", required_type="str", default="2705")), 16))

def send_ntfy_notification(self, subject: str, body: str) -> None:
"""Send a push notification."""
Expand Down Expand Up @@ -95,9 +87,9 @@ def send_alert(self, name: str, monitor: Monitor) -> None:

# prefix icon to subject when relevant
if self.ntfy_icon_prefix and subject.endswith("failed"):
subject = f"{chr(int(self.ntfy_icon_failed, 16))} {subject}"
subject = f"{self.ntfy_icon_failed} {subject}"
if self.ntfy_icon_prefix and subject.endswith("succeeded"):
subject = f"{chr(int(self.ntfy_icon_succeeded, 16))} {subject}"
subject = f"{self.ntfy_icon_succeeded} {subject}"

if not self._dry_run:
try:
Expand Down

0 comments on commit 40ecb72

Please sign in to comment.