Skip to content

Commit

Permalink
Use reauth helpers in fyta (#128571)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 17, 2024
1 parent be2c321 commit f37c0e0
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions homeassistant/components/fyta/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
TextSelectorType,
)

from . import FytaConfigEntry
from .const import CONF_EXPIRATION, DOMAIN

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -51,7 +50,6 @@ class FytaConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Fyta."""

credentials: Credentials
_entry: FytaConfigEntry | None = None
VERSION = 1
MINOR_VERSION = 2

Expand Down Expand Up @@ -100,28 +98,28 @@ async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""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()

async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reauthorization flow."""
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)):
user_input |= {
CONF_ACCESS_TOKEN: self.credentials.access_token,
CONF_EXPIRATION: self.credentials.expiration.isoformat(),
}
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,
{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(
step_id="reauth_confirm",
Expand Down

0 comments on commit f37c0e0

Please sign in to comment.