Add example usage of ConfigEntryAuthFailed to the coordinator (#880)

This commit is contained in:
J. Nick Koston 2021-04-10 00:52:03 -10:00 committed by GitHub
parent 6e16c45514
commit ac688ee498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,7 @@ import logging
import async_timeout
from homeassistant.components.light import LightEntity
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
@ -63,6 +64,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
# handled by the data update coordinator.
async with async_timeout.timeout(10):
return await api.fetch_data()
except ApiAuthError as err:
# Raising ConfigEntryAuthFailed with cancel future updates
# and start a config flow with SOURCE_REAUTH (async_step_reauth)
raise ConfigEntryAuthFailed from err
except ApiError as err:
raise UpdateFailed(f"Error communicating with API: {err}")