Raise ConfigEntryAuthFailed during setup or coordinator update to start reauth (#48962)
This commit is contained in:
parent
7cc857a298
commit
4cd7f9bd8b
51 changed files with 534 additions and 517 deletions
|
@ -14,8 +14,8 @@ from homeassistant.components.azure_devops.const import (
|
|||
DATA_AZURE_DEVOPS_CLIENT,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
|
||||
|
||||
|
@ -30,17 +30,9 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||
if entry.data[CONF_PAT] is not None:
|
||||
await client.authorize(entry.data[CONF_PAT], entry.data[CONF_ORG])
|
||||
if not client.authorized:
|
||||
_LOGGER.warning(
|
||||
raise ConfigEntryAuthFailed(
|
||||
"Could not authorize with Azure DevOps. You may need to update your token"
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_REAUTH},
|
||||
data=entry.data,
|
||||
)
|
||||
)
|
||||
return False
|
||||
await client.get_project(entry.data[CONF_ORG], entry.data[CONF_PROJECT])
|
||||
except aiohttp.ClientError as exception:
|
||||
_LOGGER.warning(exception)
|
||||
|
|
|
@ -105,17 +105,16 @@ class AzureDevOpsFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
if errors is not None:
|
||||
return await self._show_reauth_form(errors)
|
||||
|
||||
for entry in self._async_current_entries():
|
||||
if entry.unique_id == self.unique_id:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
data={
|
||||
CONF_ORG: self._organization,
|
||||
CONF_PROJECT: self._project,
|
||||
CONF_PAT: self._pat,
|
||||
},
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
entry = await self.async_set_unique_id(self.unique_id)
|
||||
self.hass.config_entries.async_update_entry(
|
||||
entry,
|
||||
data={
|
||||
CONF_ORG: self._organization,
|
||||
CONF_PROJECT: self._project,
|
||||
CONF_PAT: self._pat,
|
||||
},
|
||||
)
|
||||
return self.async_abort(reason="reauth_successful")
|
||||
|
||||
def _async_create_entry(self):
|
||||
"""Handle create entry."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue