Now uses timezone of the NVR for all timestamps

This commit is contained in:
Sebastian Goscik
2022-03-10 22:28:34 +00:00
parent 3c3c47b3b4
commit 0a4a2401be
3 changed files with 310 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ from asyncio.exceptions import TimeoutError
from typing import Callable, List, Optional
import aiocron
import pytz
from aiohttp.client_exceptions import ClientPayloadError
from pyunifiprotect import NvrError, ProtectApiClient
from pyunifiprotect.data.nvr import Event
@@ -436,6 +437,11 @@ class UnifiProtectBackup:
try:
event = await self._download_queue.get()
# Fix timezones since pyunifiprotect sets all timestamps to UTC. Instead localize them to
# the timezone of the unifi protect NVR.
event.start.replace(tzinfo=pytz.utc).astimezone(self._protect.bootstrap.nvr.timezone)
event.end.replace(tzinfo=pytz.utc).astimezone(self._protect.bootstrap.nvr.timezone)
logger.info(f"Backing up event: {event.id}")
logger.debug(f"Remaining Queue: {self._download_queue.qsize()}")
logger.debug(f" Camera: {await self._get_camera_name(event.camera_id)}")