Skip to content

Commit

Permalink
NtfyPriority is an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Jun 14, 2024
1 parent 969dbf9 commit d2a19f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Optional

from health import HealthPingerConfig
from ntfy import NtfyConfig, Notifier, ImageAttachMethod
from ntfy import NtfyConfig, ImageAttachMethod, NtfyPriority
from track import ModelConfig, TrackerConfig
from web import WebConfig

Expand Down Expand Up @@ -104,7 +104,7 @@ def config_from_file(
)
if not isinstance(cfg.notifier.default_priority, str):
raise ConfigValidationError("notifier.default_priority must be a string")
if cfg.notifier.default_priority not in Notifier.valid_priorities():
if cfg.notifier.default_priority not in NtfyPriority.all_values():
raise ConfigValidationError(
"invalid notifier.default_priority "
f"'{cfg.notifier.default_priority}' "
Expand All @@ -116,7 +116,7 @@ def config_from_file(
raise ConfigValidationError(
"notifier.priorities must be a dict of str -> str"
)
if v not in Notifier.valid_priorities():
if v not in NtfyPriority.all_values():
raise ConfigValidationError(
"invalid notifier.priorities value "
f"'{v}' for key '{k}' "
Expand Down
44 changes: 23 additions & 21 deletions ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
from log import LOG_DEFAULT_FMT


NOTIF_PRIORITY_UNMUTED: Final = "4"
NOTIF_PRIORITY_MUTED: Final = "1"


class ImageAttachMethod(Enum):
ATTACH = "attach"
CLICK = "click"
Expand All @@ -26,6 +22,28 @@ def all_values() -> set:
return {e.value for e in ImageAttachMethod}


class NtfyPriority(Enum):
N_1 = "1"
MIN = "min"
N_2 = "2"
LOW = "low"
N_3 = "3"
DEFAULT = "default"
N_4 = "4"
HIGH = "high"
N_5 = "5"
MAX = "max"
URGENT = "urgent"

@staticmethod
def all_values() -> set:
return {e.value for e in NtfyPriority}


NOTIF_PRIORITY_UNMUTED: Final = NtfyPriority.DEFAULT
NOTIF_PRIORITY_MUTED: Final = NtfyPriority.MIN


@dataclasses.dataclass(frozen=True)
class NtfyRecord:
id: str
Expand All @@ -41,7 +59,7 @@ class NtfyConfig:
server: str = "https://ntfy.sh"
token: Optional[str] = None
debounce_threshold_s: float = 60.0
default_priority: str = "3"
default_priority: NtfyPriority = NtfyPriority.DEFAULT
priorities: Dict[str, str] = dataclasses.field(default_factory=lambda: {})
req_timeout_s: float = 10.0
image_method: Optional[ImageAttachMethod] = None
Expand Down Expand Up @@ -112,22 +130,6 @@ class UnknownNotificationType(Exception):


class Notifier(lib_mpex.ChildProcess):
@staticmethod
def valid_priorities() -> set:
return {
"1",
"2",
"3",
"4",
"5",
"max",
"urgent",
"high",
"default",
"low",
"min",
}

def __init__(
self,
config: NtfyConfig,
Expand Down

0 comments on commit d2a19f8

Please sign in to comment.