mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Prevent onvif from blocking startup (#38256)
This commit is contained in:
parent
da30ed06d8
commit
8b06d1d4bd
@ -6,7 +6,7 @@ from aiohttp.client_exceptions import ServerDisconnectedError
|
|||||||
from onvif import ONVIFCamera, ONVIFService
|
from onvif import ONVIFCamera, ONVIFService
|
||||||
from zeep.exceptions import Fault
|
from zeep.exceptions import Fault
|
||||||
|
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, CoreState, HomeAssistant, callback
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
@ -114,30 +114,31 @@ class EventManager:
|
|||||||
|
|
||||||
async def async_pull_messages(self, _now: dt = None) -> None:
|
async def async_pull_messages(self, _now: dt = None) -> None:
|
||||||
"""Pull messages from device."""
|
"""Pull messages from device."""
|
||||||
try:
|
if self.hass.state == CoreState.running:
|
||||||
pullpoint = self.device.create_pullpoint_service()
|
try:
|
||||||
req = pullpoint.create_type("PullMessages")
|
pullpoint = self.device.create_pullpoint_service()
|
||||||
req.MessageLimit = 100
|
req = pullpoint.create_type("PullMessages")
|
||||||
req.Timeout = dt.timedelta(seconds=60)
|
req.MessageLimit = 100
|
||||||
response = await pullpoint.PullMessages(req)
|
req.Timeout = dt.timedelta(seconds=60)
|
||||||
|
response = await pullpoint.PullMessages(req)
|
||||||
|
|
||||||
# Renew subscription if less than two hours is left
|
# Renew subscription if less than two hours is left
|
||||||
if (
|
if (
|
||||||
dt_util.as_utc(response.TerminationTime) - dt_util.utcnow()
|
dt_util.as_utc(response.TerminationTime) - dt_util.utcnow()
|
||||||
).total_seconds() < 7200:
|
).total_seconds() < 7200:
|
||||||
await self.async_renew()
|
await self.async_renew()
|
||||||
|
|
||||||
# Parse response
|
# Parse response
|
||||||
await self.async_parse_messages(response.NotificationMessage)
|
await self.async_parse_messages(response.NotificationMessage)
|
||||||
|
|
||||||
except ServerDisconnectedError:
|
except ServerDisconnectedError:
|
||||||
pass
|
pass
|
||||||
except Fault:
|
except Fault:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Update entities
|
# Update entities
|
||||||
for update_callback in self._listeners:
|
for update_callback in self._listeners:
|
||||||
update_callback()
|
update_callback()
|
||||||
|
|
||||||
# Reschedule another pull
|
# Reschedule another pull
|
||||||
if self._listeners:
|
if self._listeners:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user