Make notifications toggleable via MQTT (#13657)

* Add ability to toggle mqtt state from MQTT / ws

* Listen to notification config updates

* Add docs for notifications
This commit is contained in:
Nicolas Mowen
2024-09-10 11:24:44 -06:00
committed by GitHub
parent 8db9824842
commit 07d1692f2b
6 changed files with 63 additions and 4 deletions
+13
View File
@@ -9,6 +9,7 @@ from typing import Any, Callable
from py_vapid import Vapid01
from pywebpush import WebPusher
from frigate.comms.config_updater import ConfigSubscriber
from frigate.comms.dispatcher import Communicator
from frigate.config import FrigateConfig
from frigate.const import CONFIG_DIR
@@ -41,6 +42,9 @@ class WebPushClient(Communicator): # type: ignore[misc]
for sub in user["notification_tokens"]:
self.web_pushers[user["username"]].append(WebPusher(sub))
# notification config updater
self.config_subscriber = ConfigSubscriber("config/notifications")
def subscribe(self, receiver: Callable) -> None:
"""Wrapper for allowing dispatcher to subscribe."""
pass
@@ -101,6 +105,15 @@ class WebPushClient(Communicator): # type: ignore[misc]
def publish(self, topic: str, payload: Any, retain: bool = False) -> None:
"""Wrapper for publishing when client is in valid state."""
# check for updated notification config
_, updated_notif_config = self.config_subscriber.check_for_update()
if updated_notif_config:
self.config.notifications = updated_notif_config
if not self.config.notifications.enabled:
return
if topic == "reviews":
self.send_alert(json.loads(payload))