mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-18 00:54:27 +03:00
use timestamp instead of datetime
This commit is contained in:
parent
b0c5fe931c
commit
1540434e4c
@ -171,11 +171,10 @@ class Dispatcher:
|
||||
"audio": self.config.cameras[camera].audio.enabled,
|
||||
"notifications": self.config.cameras[camera].notifications.enabled,
|
||||
"notifications_suspended": int(
|
||||
self.web_push_client.suspended_cameras.get(
|
||||
camera, None
|
||||
).timestamp()
|
||||
self.web_push_client.suspended_cameras.get(camera, 0)
|
||||
)
|
||||
if camera in self.web_push_client.suspended_cameras
|
||||
if self.web_push_client
|
||||
and camera in self.web_push_client.suspended_cameras
|
||||
else 0,
|
||||
"autotracking": self.config.cameras[
|
||||
camera
|
||||
@ -518,7 +517,7 @@ class Dispatcher:
|
||||
self.web_push_client
|
||||
and camera_name in self.web_push_client.suspended_cameras
|
||||
):
|
||||
del self.web_push_client.suspended_cameras[camera_name]
|
||||
self.web_push_client.suspended_cameras[camera_name] = 0
|
||||
elif payload == "OFF":
|
||||
if notification_settings.enabled:
|
||||
logger.info(f"Turning off notifications for {camera_name}")
|
||||
@ -527,7 +526,7 @@ class Dispatcher:
|
||||
self.web_push_client
|
||||
and camera_name in self.web_push_client.suspended_cameras
|
||||
):
|
||||
del self.web_push_client.suspended_cameras[camera_name]
|
||||
self.web_push_client.suspended_cameras[camera_name] = 0
|
||||
|
||||
self.config_updater.publish(
|
||||
"config/notifications", {camera_name: notification_settings}
|
||||
@ -561,11 +560,7 @@ class Dispatcher:
|
||||
self.publish(
|
||||
f"{camera_name}/notifications/suspended",
|
||||
str(
|
||||
int(
|
||||
self.web_push_client.suspended_cameras.get(
|
||||
camera_name, None
|
||||
).timestamp()
|
||||
)
|
||||
int(self.web_push_client.suspended_cameras.get(camera_name, 0))
|
||||
if camera_name in self.web_push_client.suspended_cameras
|
||||
else 0
|
||||
),
|
||||
|
||||
@ -27,9 +27,8 @@ 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] = {
|
||||
c.name: datetime.datetime.fromtimestamp(0)
|
||||
for c in self.config.cameras.values()
|
||||
self.suspended_cameras: dict[str, int] = {
|
||||
c.name: 0 for c in self.config.cameras.values()
|
||||
}
|
||||
|
||||
if not self.config.notifications.email:
|
||||
@ -109,17 +108,21 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
||||
|
||||
def suspend_notifications(self, camera: str, minutes: int) -> None:
|
||||
"""Suspend notifications for a specific camera."""
|
||||
suspend_until = datetime.datetime.now() + datetime.timedelta(minutes=minutes)
|
||||
suspend_until = int(
|
||||
(datetime.datetime.now() + datetime.timedelta(minutes=minutes)).timestamp()
|
||||
)
|
||||
self.suspended_cameras[camera] = suspend_until
|
||||
logger.info(f"Notifications for {camera} suspended until {suspend_until}")
|
||||
logger.info(
|
||||
f"Notifications for {camera} suspended until {datetime.datetime.fromtimestamp(suspend_until).strftime('%Y-%m-%d %H:%M:%S')}"
|
||||
)
|
||||
|
||||
def unsuspend_notifications(self, camera: str) -> None:
|
||||
"""Unsuspend notifications for a specific camera."""
|
||||
self.suspended_cameras[camera] = datetime.datetime.fromtimestamp(0)
|
||||
self.suspended_cameras[camera] = 0
|
||||
logger.info(f"Notifications for {camera} unsuspended")
|
||||
|
||||
def is_camera_suspended(self, camera: str) -> bool:
|
||||
return datetime.datetime.now() <= self.suspended_cameras[camera]
|
||||
return datetime.datetime.now().timestamp() <= self.suspended_cameras[camera]
|
||||
|
||||
def publish(self, topic: str, payload: Any, retain: bool = False) -> None:
|
||||
"""Wrapper for publishing when client is in valid state."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user