Use reauth helpers in fyta (#128571)

pull/128608/head^2
epenet 2024-10-17 22:03:19 +02:00 committed by GitHub
parent be2c3217dc
commit f37c0e0548
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 6 deletions

View File

@ -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",