initialize all cameras in suspended array and use 0 for unsuspended

This commit is contained in:
Josh Hawkins 2024-12-17 14:20:49 -06:00
parent 9e710b2965
commit 82433ee75d
2 changed files with 7 additions and 9 deletions

View File

@ -308,7 +308,7 @@ class FrigateApp:
if c.enabled and c.notifications.enabled_in_config
]
if self.config.notifications.enabled_in_config or notification_cameras:
if notification_cameras:
comms.append(WebPushClient(self.config))
comms.append(WebSocketClient(self.config))

View File

@ -27,7 +27,10 @@ class WebPushClient(Communicator): # type: ignore[misc]
self.refresh: int = 0
self.web_pushers: dict[str, list[WebPusher]] = {}
self.expired_subs: dict[str, list[str]] = {}
self.suspended_cameras: dict[str, datetime.datetime] = {}
self.suspended_cameras: dict[str, datetime.datetime] = {
c.name: datetime.datetime.fromtimestamp(0)
for c in self.config.cameras.values()
}
if not self.config.notifications.email:
logger.warning("Email must be provided for push notifications to be sent.")
@ -112,16 +115,11 @@ class WebPushClient(Communicator): # type: ignore[misc]
def unsuspend_notifications(self, camera: str) -> None:
"""Unsuspend notifications for a specific camera."""
del self.suspended_cameras[camera]
self.suspended_cameras[camera] = datetime.datetime.fromtimestamp(0)
logger.info(f"Notifications for {camera} unsuspended")
def is_camera_suspended(self, camera: str) -> bool:
if camera in self.suspended_cameras:
if datetime.datetime.now() >= self.suspended_cameras[camera]:
del self.suspended_cameras[camera]
return False
return True
return False
return datetime.datetime.now() <= self.suspended_cameras[camera]
def publish(self, topic: str, payload: Any, retain: bool = False) -> None:
"""Wrapper for publishing when client is in valid state."""