Use reauth helpers in fyta (#128571)
parent
be2c3217dc
commit
f37c0e0548
|
@ -23,7 +23,6 @@ from homeassistant.helpers.selector import (
|
||||||
TextSelectorType,
|
TextSelectorType,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import FytaConfigEntry
|
|
||||||
from .const import CONF_EXPIRATION, DOMAIN
|
from .const import CONF_EXPIRATION, DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -51,7 +50,6 @@ class FytaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for Fyta."""
|
"""Handle a config flow for Fyta."""
|
||||||
|
|
||||||
credentials: Credentials
|
credentials: Credentials
|
||||||
_entry: FytaConfigEntry | None = None
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
MINOR_VERSION = 2
|
MINOR_VERSION = 2
|
||||||
|
|
||||||
|
@ -100,7 +98,6 @@ class FytaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle flow upon an API authentication error."""
|
"""Handle flow upon an API authentication error."""
|
||||||
self._entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
|
@ -108,20 +105,21 @@ class FytaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle reauthorization flow."""
|
"""Handle reauthorization flow."""
|
||||||
errors = {}
|
errors = {}
|
||||||
assert self._entry is not None
|
|
||||||
|
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
if user_input and not (errors := await self.async_auth(user_input)):
|
if user_input and not (errors := await self.async_auth(user_input)):
|
||||||
user_input |= {
|
user_input |= {
|
||||||
CONF_ACCESS_TOKEN: self.credentials.access_token,
|
CONF_ACCESS_TOKEN: self.credentials.access_token,
|
||||||
CONF_EXPIRATION: self.credentials.expiration.isoformat(),
|
CONF_EXPIRATION: self.credentials.expiration.isoformat(),
|
||||||
}
|
}
|
||||||
return self.async_update_reload_and_abort(
|
return self.async_update_reload_and_abort(
|
||||||
self._entry, data={**self._entry.data, **user_input}
|
reauth_entry,
|
||||||
|
data_updates=user_input,
|
||||||
)
|
)
|
||||||
|
|
||||||
data_schema = self.add_suggested_values_to_schema(
|
data_schema = self.add_suggested_values_to_schema(
|
||||||
DATA_SCHEMA,
|
DATA_SCHEMA,
|
||||||
{CONF_USERNAME: self._entry.data[CONF_USERNAME], **(user_input or {})},
|
{CONF_USERNAME: reauth_entry.data[CONF_USERNAME], **(user_input or {})},
|
||||||
)
|
)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
|
|
Loading…
Reference in New Issue