Use _get_reauth/reconfigure_entry in tedee (#127312)
This commit is contained in:
parent
db9257f9fa
commit
fac3d575c9
1 changed files with 14 additions and 16 deletions
|
@ -14,7 +14,13 @@ from pytedee_async import (
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.webhook import async_generate_id as webhook_generate_id
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import (
|
||||
SOURCE_REAUTH,
|
||||
SOURCE_RECONFIGURE,
|
||||
ConfigEntry,
|
||||
ConfigFlow,
|
||||
ConfigFlowResult,
|
||||
)
|
||||
from homeassistant.const import CONF_HOST, CONF_WEBHOOK_ID
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
|
@ -29,8 +35,8 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
VERSION = 1
|
||||
MINOR_VERSION = 2
|
||||
|
||||
reauth_entry: ConfigEntry | None = None
|
||||
reconfigure_entry: ConfigEntry | None = None
|
||||
reauth_entry: ConfigEntry
|
||||
reconfigure_entry: ConfigEntry
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
|
@ -39,7 +45,7 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
errors: dict[str, str] = {}
|
||||
|
||||
if user_input is not None:
|
||||
if self.reauth_entry:
|
||||
if self.source == SOURCE_REAUTH:
|
||||
host = self.reauth_entry.data[CONF_HOST]
|
||||
else:
|
||||
host = user_input[CONF_HOST]
|
||||
|
@ -59,13 +65,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
_LOGGER.error("Error during local bridge discovery: %s", exc)
|
||||
errors["base"] = "cannot_connect"
|
||||
else:
|
||||
if self.reauth_entry:
|
||||
if self.source == SOURCE_REAUTH:
|
||||
return self.async_update_reload_and_abort(
|
||||
self.reauth_entry,
|
||||
data={**self.reauth_entry.data, **user_input},
|
||||
reason="reauth_successful",
|
||||
)
|
||||
if self.reconfigure_entry:
|
||||
if self.source == SOURCE_RECONFIGURE:
|
||||
return self.async_update_reload_and_abort(
|
||||
self.reconfigure_entry,
|
||||
data={**self.reconfigure_entry.data, **user_input},
|
||||
|
@ -97,17 +103,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Perform reauth upon an API authentication error."""
|
||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
self.reauth_entry = self._get_reauth_entry()
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
async def async_step_reauth_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Dialog that informs the user that reauth is required."""
|
||||
assert self.reauth_entry
|
||||
|
||||
if not user_input:
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm",
|
||||
|
@ -126,17 +128,13 @@ class TedeeConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
"""Perform a reconfiguration."""
|
||||
self.reconfigure_entry = self.hass.config_entries.async_get_entry(
|
||||
self.context["entry_id"]
|
||||
)
|
||||
self.reconfigure_entry = self._get_reconfigure_entry()
|
||||
return await self.async_step_reconfigure_confirm()
|
||||
|
||||
async def async_step_reconfigure_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Add reconfigure step to allow to reconfigure a config entry."""
|
||||
assert self.reconfigure_entry
|
||||
|
||||
if not user_input:
|
||||
return self.async_show_form(
|
||||
step_id="reconfigure_confirm",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue