Cancel august interval track at stop event (#49198)
parent
bbe58091a8
commit
9a7d500b80
|
@ -31,7 +31,6 @@ class ActivityStream(AugustSubscriberMixin):
|
|||
self._house_ids = house_ids
|
||||
self._latest_activities = {}
|
||||
self._last_update_time = None
|
||||
self._abort_async_track_time_interval = None
|
||||
self.pubnub = pubnub
|
||||
self._update_debounce = {}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Base class for August entity."""
|
||||
|
||||
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
||||
|
@ -15,6 +16,7 @@ class AugustSubscriberMixin:
|
|||
self._update_interval = update_interval
|
||||
self._subscriptions = {}
|
||||
self._unsub_interval = None
|
||||
self._stop_interval = None
|
||||
|
||||
@callback
|
||||
def async_subscribe_device_id(self, device_id, update_callback):
|
||||
|
@ -23,9 +25,8 @@ class AugustSubscriberMixin:
|
|||
Returns a callable that can be used to unsubscribe.
|
||||
"""
|
||||
if not self._subscriptions:
|
||||
self._unsub_interval = async_track_time_interval(
|
||||
self._hass, self._async_refresh, self._update_interval
|
||||
)
|
||||
self._async_setup_listeners()
|
||||
|
||||
self._subscriptions.setdefault(device_id, []).append(update_callback)
|
||||
|
||||
def _unsubscribe():
|
||||
|
@ -33,15 +34,37 @@ class AugustSubscriberMixin:
|
|||
|
||||
return _unsubscribe
|
||||
|
||||
@callback
|
||||
def _async_setup_listeners(self):
|
||||
"""Create interval and stop listeners."""
|
||||
self._unsub_interval = async_track_time_interval(
|
||||
self._hass, self._async_refresh, self._update_interval
|
||||
)
|
||||
|
||||
@callback
|
||||
def _async_cancel_update_interval(_):
|
||||
self._stop_interval = None
|
||||
self._unsub_interval()
|
||||
|
||||
self._stop_interval = self._hass.bus.async_listen(
|
||||
EVENT_HOMEASSISTANT_STOP, _async_cancel_update_interval
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_unsubscribe_device_id(self, device_id, update_callback):
|
||||
"""Remove a callback subscriber."""
|
||||
self._subscriptions[device_id].remove(update_callback)
|
||||
if not self._subscriptions[device_id]:
|
||||
del self._subscriptions[device_id]
|
||||
if not self._subscriptions:
|
||||
self._unsub_interval()
|
||||
self._unsub_interval = None
|
||||
|
||||
if self._subscriptions:
|
||||
return
|
||||
|
||||
self._unsub_interval()
|
||||
self._unsub_interval = None
|
||||
if self._stop_interval:
|
||||
self._stop_interval()
|
||||
self._stop_interval = None
|
||||
|
||||
@callback
|
||||
def async_signal_device_id_update(self, device_id):
|
||||
|
|
Loading…
Reference in New Issue