Fix onvif setup failing when unable to parse camera time (#93677)
parent
2f1f32f0bb
commit
6cc5bee960
|
@ -23,7 +23,7 @@ from homeassistant.const import (
|
|||
CONF_USERNAME,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import (
|
||||
|
@ -189,14 +189,19 @@ class ONVIFDevice:
|
|||
dt_param.DateTimeType = "Manual"
|
||||
# Retrieve DST setting from system
|
||||
dt_param.DaylightSavings = bool(time.localtime().tm_isdst)
|
||||
dt_param.UTCDateTime = device_time.UTCDateTime
|
||||
dt_param.UTCDateTime = {
|
||||
"Date": {
|
||||
"Year": system_date.year,
|
||||
"Month": system_date.month,
|
||||
"Day": system_date.day,
|
||||
},
|
||||
"Time": {
|
||||
"Hour": system_date.hour,
|
||||
"Minute": system_date.minute,
|
||||
"Second": system_date.second,
|
||||
},
|
||||
}
|
||||
# Retrieve timezone from system
|
||||
dt_param.UTCDateTime.Date.Year = system_date.year
|
||||
dt_param.UTCDateTime.Date.Month = system_date.month
|
||||
dt_param.UTCDateTime.Date.Day = system_date.day
|
||||
dt_param.UTCDateTime.Time.Hour = system_date.hour
|
||||
dt_param.UTCDateTime.Time.Minute = system_date.minute
|
||||
dt_param.UTCDateTime.Time.Second = system_date.second
|
||||
system_timezone = str(system_date.astimezone().tzinfo)
|
||||
timezone_names: list[str | None] = [system_timezone]
|
||||
if (time_zone := device_time.TimeZone) and system_timezone != time_zone.TZ:
|
||||
|
@ -283,6 +288,22 @@ class ONVIFDevice:
|
|||
if abs(self._dt_diff_seconds) < 5:
|
||||
return
|
||||
|
||||
if device_time.DateTimeType != "Manual":
|
||||
self._async_log_time_out_of_sync(cam_date_utc, system_date)
|
||||
return
|
||||
|
||||
# Set Date and Time ourselves if Date and Time is set manually in the camera.
|
||||
try:
|
||||
await self.async_manually_set_date_and_time()
|
||||
except (RequestError, TransportError, IndexError, Fault):
|
||||
LOGGER.warning("%s: Could not sync date/time on this camera", self.name)
|
||||
self._async_log_time_out_of_sync(cam_date_utc, system_date)
|
||||
|
||||
@callback
|
||||
def _async_log_time_out_of_sync(
|
||||
self, cam_date_utc: dt.datetime, system_date: dt.datetime
|
||||
) -> None:
|
||||
"""Log a warning if the camera and system date/time are not synced."""
|
||||
LOGGER.warning(
|
||||
(
|
||||
"The date/time on %s (UTC) is '%s', "
|
||||
|
@ -294,15 +315,6 @@ class ONVIFDevice:
|
|||
system_date,
|
||||
)
|
||||
|
||||
if device_time.DateTimeType != "Manual":
|
||||
return
|
||||
|
||||
# Set Date and Time ourselves if Date and Time is set manually in the camera.
|
||||
try:
|
||||
await self.async_manually_set_date_and_time()
|
||||
except (RequestError, TransportError, IndexError, Fault):
|
||||
LOGGER.warning("%s: Could not sync date/time on this camera", self.name)
|
||||
|
||||
async def async_get_device_info(self) -> DeviceInfo:
|
||||
"""Obtain information about this device."""
|
||||
device_mgmt = await self.device.create_devicemgmt_service()
|
||||
|
|
Loading…
Reference in New Issue