Respect icloud Enable polling updates (#117984)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Filipe Pina 2024-07-05 08:24:02 +01:00 committed by GitHub
parent def27a082c
commit 213bbae63c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -161,6 +161,7 @@ class IcloudAccount:
"""Update iCloud devices."""
if self.api is None:
return
_LOGGER.debug("Updating devices")
if self.api.requires_2fa:
self._require_reauth()
@ -173,11 +174,7 @@ class IcloudAccount:
_LOGGER.error("Unknown iCloud error: %s", err)
self._fetch_interval = 2
dispatcher_send(self.hass, self.signal_device_update)
track_point_in_utc_time(
self.hass,
self.keep_alive,
utcnow() + timedelta(minutes=self._fetch_interval),
)
self._schedule_next_fetch()
return
# Gets devices infos
@ -223,11 +220,7 @@ class IcloudAccount:
if new_device:
dispatcher_send(self.hass, self.signal_device_new)
track_point_in_utc_time(
self.hass,
self.keep_alive,
utcnow() + timedelta(minutes=self._fetch_interval),
)
self._schedule_next_fetch()
def _require_reauth(self):
"""Require the user to log in again."""
@ -306,6 +299,14 @@ class IcloudAccount:
self._max_interval,
)
def _schedule_next_fetch(self) -> None:
if not self._config_entry.pref_disable_polling:
track_point_in_utc_time(
self.hass,
self.keep_alive,
utcnow() + timedelta(minutes=self._fetch_interval),
)
def keep_alive(self, now=None) -> None:
"""Keep the API alive."""
if self.api is None: