Update example with async_config_entry_first_refresh (#870)

This commit is contained in:
J. Nick Koston 2021-03-29 12:51:52 -10:00 committed by GitHub
parent a3fbbee6ea
commit b1a3b5dc17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,8 +76,16 @@ async def async_setup_entry(hass, entry, async_add_entities):
update_interval=timedelta(seconds=30),
)
#
# Fetch initial data so we have data when entities subscribe
await coordinator.async_refresh()
#
# If the refresh fails, async_config_entry_first_refresh will
# raise ConfigEntryNotReady and setup will try again later
#
# If you do not want to retry setup on failure, use
# coordinator.async_refresh() instead
#
await coordinator.async_config_entry_first_refresh()
async_add_entities(
MyEntity(coordinator, idx) for idx, ent in enumerate(coordinator.data)