Fix ONVIF subscription renewal (#35792)

* fix subscription renewal

* catch ValueError for #35762
pull/35799/head
Jason Hunter 2020-05-18 23:02:23 -04:00 committed by GitHub
parent ef6b1f9302
commit aeae4edb74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View File

@ -54,6 +54,8 @@ class ONVIFDevice:
self.profiles: List[Profile] = []
self.max_resolution: int = 0
self._dt_diff_seconds: int = 0
@property
def name(self) -> str:
"""Return the name of this device."""
@ -100,6 +102,16 @@ class ONVIFDevice:
if self.capabilities.ptz:
self.device.create_ptz_service()
if self._dt_diff_seconds > 300 and self.capabilities.events:
self.capabilities.events = False
LOGGER.warning(
"The system clock on '%s' is more than 5 minutes off. "
"Although this device supports events, they will be "
"disabled until the device clock is fixed as we will "
"not be able to renew the subscription.",
self.name,
)
if self.capabilities.events:
self.events = EventManager(
self.hass, self.device, self.config_entry.unique_id
@ -179,9 +191,9 @@ class ONVIFDevice:
)
dt_diff = cam_date - system_date
dt_diff_seconds = dt_diff.total_seconds()
self._dt_diff_seconds = dt_diff.total_seconds()
if dt_diff_seconds > 5:
if self._dt_diff_seconds > 5:
LOGGER.warning(
"The date/time on the device (UTC) is '%s', "
"which is different from the system '%s', "

View File

@ -104,7 +104,8 @@ class EventManager:
if not self._subscription:
return
await self._subscription.Renew(dt_util.utcnow() + dt.timedelta(minutes=10))
termination_time = (dt_util.utcnow() + dt.timedelta(minutes=30)).isoformat()
await self._subscription.Renew(termination_time)
async def async_pull_messages(self, _now: dt = None) -> None:
"""Pull messages from device."""

View File

@ -308,7 +308,7 @@ async def async_parse_last_reboot(uid: str, msg) -> Event:
dt_util.parse_datetime(msg.Message._value_1.Data.SimpleItem[0].Value)
),
)
except (AttributeError, KeyError):
except (AttributeError, KeyError, ValueError):
return None
@ -331,7 +331,7 @@ async def async_parse_last_reset(uid: str, msg) -> Event:
),
entity_enabled=False,
)
except (AttributeError, KeyError):
except (AttributeError, KeyError, ValueError):
return None
@ -354,5 +354,5 @@ async def async_parse_last_clock_sync(uid: str, msg) -> Event:
),
entity_enabled=False,
)
except (AttributeError, KeyError):
except (AttributeError, KeyError, ValueError):
return None