From ac688ee4986daf4873658b23ce197f6f2cf44b3b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 10 Apr 2021 00:52:03 -1000 Subject: [PATCH] Add example usage of ConfigEntryAuthFailed to the coordinator (#880) --- docs/integration_fetching_data.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/integration_fetching_data.md b/docs/integration_fetching_data.md index 7098fcb6..03bc9c99 100644 --- a/docs/integration_fetching_data.md +++ b/docs/integration_fetching_data.md @@ -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}")