From edf34eea948f8ef09a39a7753e265e71e073800e Mon Sep 17 00:00:00 2001 From: karlkar Date: Fri, 17 May 2019 06:29:52 +0200 Subject: [PATCH] Fix problem with cameras that don't support time (#23924) Some onvif cameras don't support Date management. In that case None is returned and script crashes when trying to obtain date --- homeassistant/components/onvif/camera.py | 35 ++++++++++++------------ 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/onvif/camera.py b/homeassistant/components/onvif/camera.py index ea3d0277136..68c3c819567 100644 --- a/homeassistant/components/onvif/camera.py +++ b/homeassistant/components/onvif/camera.py @@ -164,27 +164,28 @@ class ONVIFHassCamera(Camera): system_date = dt_util.utcnow() device_time = await devicemgmt.GetSystemDateAndTime() - cdate = device_time.UTCDateTime - cam_date = dt.datetime(cdate.Date.Year, cdate.Date.Month, - cdate.Date.Day, cdate.Time.Hour, - cdate.Time.Minute, cdate.Time.Second, - 0, dt_util.UTC) + if device_time: + cdate = device_time.UTCDateTime + cam_date = dt.datetime(cdate.Date.Year, cdate.Date.Month, + cdate.Date.Day, cdate.Time.Hour, + cdate.Time.Minute, cdate.Time.Second, + 0, dt_util.UTC) - _LOGGER.debug("Camera date/time: %s", - cam_date) + _LOGGER.debug("Camera date/time: %s", + cam_date) - _LOGGER.debug("System date/time: %s", - system_date) + _LOGGER.debug("System date/time: %s", + system_date) - dt_diff = cam_date - system_date - dt_diff_seconds = dt_diff.total_seconds() + dt_diff = cam_date - system_date + dt_diff_seconds = dt_diff.total_seconds() - if dt_diff_seconds > 5: - _LOGGER.warning("The date/time on the camera is '%s', " - "which is different from the system '%s', " - "this could lead to authentication issues", - cam_date, - system_date) + if dt_diff_seconds > 5: + _LOGGER.warning("The date/time on the camera is '%s', " + "which is different from the system '%s', " + "this could lead to authentication issues", + cam_date, + system_date) _LOGGER.debug("Obtaining input uri")