mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
parent
d058802325
commit
34cb12d3c9
@ -12,7 +12,7 @@ from onvif import ONVIFCamera, ONVIFService
|
|||||||
from zeep.exceptions import Fault
|
from zeep.exceptions import Fault
|
||||||
|
|
||||||
from homeassistant.core import CALLBACK_TYPE, CoreState, 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_call_later
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import LOGGER
|
from .const import LOGGER
|
||||||
@ -56,7 +56,7 @@ class EventManager:
|
|||||||
"""Listen for data updates."""
|
"""Listen for data updates."""
|
||||||
# This is the first listener, set up polling.
|
# This is the first listener, set up polling.
|
||||||
if not self._listeners:
|
if not self._listeners:
|
||||||
self.schedule_pull()
|
self.async_schedule_pull()
|
||||||
|
|
||||||
self._listeners.append(update_callback)
|
self._listeners.append(update_callback)
|
||||||
|
|
||||||
@ -135,16 +135,12 @@ class EventManager:
|
|||||||
self.unique_id,
|
self.unique_id,
|
||||||
)
|
)
|
||||||
# Try again in a minute
|
# Try again in a minute
|
||||||
self._unsub_refresh = async_track_point_in_utc_time(
|
self._unsub_refresh = async_call_later(self.hass, 60, self.async_restart)
|
||||||
self.hass,
|
|
||||||
self.async_restart,
|
|
||||||
dt_util.utcnow() + dt.timedelta(seconds=60),
|
|
||||||
)
|
|
||||||
elif self._listeners:
|
elif self._listeners:
|
||||||
LOGGER.info(
|
LOGGER.debug(
|
||||||
"Restarted ONVIF PullPoint subscription for '%s'", self.unique_id
|
"Restarted ONVIF PullPoint subscription for '%s'", self.unique_id
|
||||||
)
|
)
|
||||||
self.schedule_pull()
|
self.async_schedule_pull()
|
||||||
|
|
||||||
async def async_renew(self) -> None:
|
async def async_renew(self) -> None:
|
||||||
"""Renew subscription."""
|
"""Renew subscription."""
|
||||||
@ -158,13 +154,9 @@ class EventManager:
|
|||||||
)
|
)
|
||||||
await self._subscription.Renew(termination_time)
|
await self._subscription.Renew(termination_time)
|
||||||
|
|
||||||
def schedule_pull(self) -> None:
|
def async_schedule_pull(self) -> None:
|
||||||
"""Schedule async_pull_messages to run."""
|
"""Schedule async_pull_messages to run."""
|
||||||
self._unsub_refresh = async_track_point_in_utc_time(
|
self._unsub_refresh = async_call_later(self.hass, 1, self.async_pull_messages)
|
||||||
self.hass,
|
|
||||||
self.async_pull_messages,
|
|
||||||
dt_util.utcnow() + dt.timedelta(seconds=1),
|
|
||||||
)
|
|
||||||
|
|
||||||
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."""
|
||||||
@ -201,7 +193,7 @@ class EventManager:
|
|||||||
|
|
||||||
# Reschedule another pull
|
# Reschedule another pull
|
||||||
if self._listeners:
|
if self._listeners:
|
||||||
self.schedule_pull()
|
self.async_schedule_pull()
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
async def async_parse_messages(self, messages) -> None:
|
async def async_parse_messages(self, messages) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user