mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix onvif setup failing when unable to parse camera time (#93677)
This commit is contained in:
parent
2f1f32f0bb
commit
6cc5bee960
@ -23,7 +23,7 @@ from homeassistant.const import (
|
|||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant, callback
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -189,14 +189,19 @@ class ONVIFDevice:
|
|||||||
dt_param.DateTimeType = "Manual"
|
dt_param.DateTimeType = "Manual"
|
||||||
# Retrieve DST setting from system
|
# Retrieve DST setting from system
|
||||||
dt_param.DaylightSavings = bool(time.localtime().tm_isdst)
|
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
|
# 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)
|
system_timezone = str(system_date.astimezone().tzinfo)
|
||||||
timezone_names: list[str | None] = [system_timezone]
|
timezone_names: list[str | None] = [system_timezone]
|
||||||
if (time_zone := device_time.TimeZone) and system_timezone != time_zone.TZ:
|
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:
|
if abs(self._dt_diff_seconds) < 5:
|
||||||
return
|
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(
|
LOGGER.warning(
|
||||||
(
|
(
|
||||||
"The date/time on %s (UTC) is '%s', "
|
"The date/time on %s (UTC) is '%s', "
|
||||||
@ -294,15 +315,6 @@ class ONVIFDevice:
|
|||||||
system_date,
|
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:
|
async def async_get_device_info(self) -> DeviceInfo:
|
||||||
"""Obtain information about this device."""
|
"""Obtain information about this device."""
|
||||||
device_mgmt = await self.device.create_devicemgmt_service()
|
device_mgmt = await self.device.create_devicemgmt_service()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user