mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-01 19:17:41 +03:00
Handle notifications
This commit is contained in:
parent
8dec3418c9
commit
35f74a52dc
@ -417,9 +417,7 @@ class Dispatcher:
|
|||||||
notification_settings = self.config.notifications
|
notification_settings = self.config.notifications
|
||||||
logger.info(f"Setting all notifications: {payload}")
|
logger.info(f"Setting all notifications: {payload}")
|
||||||
notification_settings.enabled = payload == "ON" # type: ignore[union-attr]
|
notification_settings.enabled = payload == "ON" # type: ignore[union-attr]
|
||||||
self.config_updater.publish(
|
self.config_updater.publisher.publish("config/notifications", notification_settings)
|
||||||
"config/notifications", {"_global_notifications": notification_settings}
|
|
||||||
)
|
|
||||||
self.publish("notifications/state", payload, retain=True)
|
self.publish("notifications/state", payload, retain=True)
|
||||||
|
|
||||||
def _on_audio_command(self, camera_name: str, payload: str) -> None:
|
def _on_audio_command(self, camera_name: str, payload: str) -> None:
|
||||||
@ -582,8 +580,9 @@ class Dispatcher:
|
|||||||
):
|
):
|
||||||
self.web_push_client.suspended_cameras[camera_name] = 0
|
self.web_push_client.suspended_cameras[camera_name] = 0
|
||||||
|
|
||||||
self.config_updater.publish(
|
self.config_updater.publish_update(
|
||||||
"config/notifications", {camera_name: notification_settings}
|
CameraConfigUpdateTopic(CameraConfigUpdateEnum.notifications, camera_name),
|
||||||
|
notification_settings,
|
||||||
)
|
)
|
||||||
self.publish(f"{camera_name}/notifications/state", payload, retain=True)
|
self.publish(f"{camera_name}/notifications/state", payload, retain=True)
|
||||||
self.publish(f"{camera_name}/notifications/suspended", "0", retain=True)
|
self.publish(f"{camera_name}/notifications/suspended", "0", retain=True)
|
||||||
|
|||||||
@ -17,6 +17,10 @@ from titlecase import titlecase
|
|||||||
from frigate.comms.base_communicator import Communicator
|
from frigate.comms.base_communicator import Communicator
|
||||||
from frigate.comms.config_updater import ConfigSubscriber
|
from frigate.comms.config_updater import ConfigSubscriber
|
||||||
from frigate.config import FrigateConfig
|
from frigate.config import FrigateConfig
|
||||||
|
from frigate.config.camera.updater import (
|
||||||
|
CameraConfigUpdateEnum,
|
||||||
|
CameraConfigUpdateSubscriber,
|
||||||
|
)
|
||||||
from frigate.const import CONFIG_DIR
|
from frigate.const import CONFIG_DIR
|
||||||
from frigate.models import User
|
from frigate.models import User
|
||||||
|
|
||||||
@ -73,7 +77,12 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
|||||||
self.web_pushers[user["username"]].append(WebPusher(sub))
|
self.web_pushers[user["username"]].append(WebPusher(sub))
|
||||||
|
|
||||||
# notification config updater
|
# notification config updater
|
||||||
self.config_subscriber = ConfigSubscriber("config/notifications")
|
self.global_config_subscriber = ConfigSubscriber(
|
||||||
|
"config/notifications", exact=True
|
||||||
|
)
|
||||||
|
self.config_subscriber = CameraConfigUpdateSubscriber(
|
||||||
|
self.config.cameras, [CameraConfigUpdateEnum.notifications]
|
||||||
|
)
|
||||||
|
|
||||||
def subscribe(self, receiver: Callable) -> None:
|
def subscribe(self, receiver: Callable) -> None:
|
||||||
"""Wrapper for allowing dispatcher to subscribe."""
|
"""Wrapper for allowing dispatcher to subscribe."""
|
||||||
@ -154,15 +163,14 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
|||||||
def publish(self, topic: str, payload: Any, retain: bool = False) -> None:
|
def publish(self, topic: str, payload: Any, retain: bool = False) -> None:
|
||||||
"""Wrapper for publishing when client is in valid state."""
|
"""Wrapper for publishing when client is in valid state."""
|
||||||
# check for updated notification config
|
# check for updated notification config
|
||||||
_, updated_notification_config = self.config_subscriber.check_for_update()
|
_, updated_notification_config = (
|
||||||
|
self.global_config_subscriber.check_for_update()
|
||||||
|
)
|
||||||
|
|
||||||
if updated_notification_config:
|
if updated_notification_config:
|
||||||
for key, value in updated_notification_config.items():
|
self.config.notifications = updated_notification_config
|
||||||
if key == "_global_notifications":
|
|
||||||
self.config.notifications = value
|
|
||||||
|
|
||||||
elif key in self.config.cameras:
|
self.config_subscriber.check_for_updates()
|
||||||
self.config.cameras[key].notifications = value
|
|
||||||
|
|
||||||
if topic == "reviews":
|
if topic == "reviews":
|
||||||
decoded = json.loads(payload)
|
decoded = json.loads(payload)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user