Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
more coordinator fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rlippmann committed Jan 31, 2024
1 parent 281ca92 commit 6cb72bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion custom_components/adtpulse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
await coordinator.async_config_entry_first_refresh()
# entities already have their data, no need to call async_refresh()
entry.async_on_unload(entry.add_update_listener(options_listener))
return True

Expand Down
15 changes: 7 additions & 8 deletions custom_components/adtpulse/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def __init__(self, hass: HomeAssistant, pulse_service: PyADTPulseAsync):
LOG.debug("%s: creating update coordinator", ADTPULSE_DOMAIN)
self._adt_pulse = pulse_service
super().__init__(
hass, LOG, name=ADTPULSE_DOMAIN, update_interval=timedelta(seconds=0)
hass,
LOG,
name=ADTPULSE_DOMAIN,
update_interval=timedelta(
seconds=pulse_service.site.gateway.backoff.initial_backoff_interval
),
)

@property
Expand All @@ -44,7 +49,7 @@ def adtpulse(self) -> PyADTPulseAsync:
async def _async_update_data(self) -> None:
"""Fetch data from ADT Pulse."""
LOG.debug("%s: coordinator waiting for updates", ADTPULSE_DOMAIN)
next_check = 0
next_check = self._adt_pulse.site.gateway.backoff.initial_backoff_interval
update_exception: Exception | None = None
try:
await self._adt_pulse.wait_for_update()
Expand All @@ -64,10 +69,4 @@ async def _async_update_data(self) -> None:
self.async_set_update_error(update_exception)
else:
self.async_set_updated_data(None)
if next_check != 0:
LOG.debug(
"%s: coordinator scheduling next update in %f seconds",
ADTPULSE_DOMAIN,
next_check,
)
self.update_interval = timedelta(seconds=next_check)

0 comments on commit 6cb72bd

Please sign in to comment.