mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-18 09:04:28 +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,
|
"audio": self.config.cameras[camera].audio.enabled,
|
||||||
"notifications": self.config.cameras[camera].notifications.enabled,
|
"notifications": self.config.cameras[camera].notifications.enabled,
|
||||||
"notifications_suspended": int(
|
"notifications_suspended": int(
|
||||||
self.web_push_client.suspended_cameras.get(
|
self.web_push_client.suspended_cameras.get(camera, 0)
|
||||||
camera, None
|
|
||||||
).timestamp()
|
|
||||||
)
|
)
|
||||||
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,
|
else 0,
|
||||||
"autotracking": self.config.cameras[
|
"autotracking": self.config.cameras[
|
||||||
camera
|
camera
|
||||||
@ -518,7 +517,7 @@ class Dispatcher:
|
|||||||
self.web_push_client
|
self.web_push_client
|
||||||
and camera_name in self.web_push_client.suspended_cameras
|
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":
|
elif payload == "OFF":
|
||||||
if notification_settings.enabled:
|
if notification_settings.enabled:
|
||||||
logger.info(f"Turning off notifications for {camera_name}")
|
logger.info(f"Turning off notifications for {camera_name}")
|
||||||
@ -527,7 +526,7 @@ class Dispatcher:
|
|||||||
self.web_push_client
|
self.web_push_client
|
||||||
and camera_name in self.web_push_client.suspended_cameras
|
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(
|
self.config_updater.publish(
|
||||||
"config/notifications", {camera_name: notification_settings}
|
"config/notifications", {camera_name: notification_settings}
|
||||||
@ -561,11 +560,7 @@ class Dispatcher:
|
|||||||
self.publish(
|
self.publish(
|
||||||
f"{camera_name}/notifications/suspended",
|
f"{camera_name}/notifications/suspended",
|
||||||
str(
|
str(
|
||||||
int(
|
int(self.web_push_client.suspended_cameras.get(camera_name, 0))
|
||||||
self.web_push_client.suspended_cameras.get(
|
|
||||||
camera_name, None
|
|
||||||
).timestamp()
|
|
||||||
)
|
|
||||||
if camera_name in self.web_push_client.suspended_cameras
|
if camera_name in self.web_push_client.suspended_cameras
|
||||||
else 0
|
else 0
|
||||||
),
|
),
|
||||||
|
|||||||
@ -27,9 +27,8 @@ class WebPushClient(Communicator): # type: ignore[misc]
|
|||||||
self.refresh: int = 0
|
self.refresh: int = 0
|
||||||
self.web_pushers: dict[str, list[WebPusher]] = {}
|
self.web_pushers: dict[str, list[WebPusher]] = {}
|
||||||
self.expired_subs: dict[str, list[str]] = {}
|
self.expired_subs: dict[str, list[str]] = {}
|
||||||
self.suspended_cameras: dict[str, datetime.datetime] = {
|
self.suspended_cameras: dict[str, int] = {
|
||||||
c.name: datetime.datetime.fromtimestamp(0)
|
c.name: 0 for c in self.config.cameras.values()
|
||||||
for c in self.config.cameras.values()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if not self.config.notifications.email:
|
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:
|
def suspend_notifications(self, camera: str, minutes: int) -> None:
|
||||||
"""Suspend notifications for a specific camera."""
|
"""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
|
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:
|
def unsuspend_notifications(self, camera: str) -> None:
|
||||||
"""Unsuspend notifications for a specific camera."""
|
"""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")
|
logger.info(f"Notifications for {camera} unsuspended")
|
||||||
|
|
||||||
def is_camera_suspended(self, camera: str) -> bool:
|
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:
|
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."""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user