Skip to content

Commit

Permalink
Add more type safety to notifier parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnatar committed Feb 7, 2023
1 parent 7ee8d4d commit 0d133b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/notifier/notify_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# std
import logging
import time
from typing import List, Dict
from typing import List, Dict, Type

# lib
from confuse import ConfigView
Expand Down Expand Up @@ -36,7 +36,7 @@ def __init__(self, config: ConfigView, keep_alive_monitor: KeepAliveMonitor):
self._initialize_notifiers()

def _initialize_notifiers(self) -> None:
key_notifier_mapping = {
key_notifier_mapping: Dict[str, Type[Notifier]] = {
"pushover": PushoverNotifier,
"pushcut": PushcutNotifier,
"script": ScriptNotifier,
Expand All @@ -48,11 +48,11 @@ def _initialize_notifiers(self) -> None:
"grafana": GrafanaNotifier,
"ifttt": IftttNotifier,
}
for key in self._config.keys():
for key in self._config:
if key not in key_notifier_mapping.keys():
logging.warning(f"Cannot find mapping for {key} notifier.")
if self._config[key]["enable"].get(bool):
self._notifiers[key] = key_notifier_mapping[key]( # type: ignore[abstract]
self._notifiers[key] = key_notifier_mapping[key](
title_prefix=self._notification_title_prefix, config=self._config[key]
)

Expand Down

0 comments on commit 0d133b8

Please sign in to comment.