Use new reauth helpers in vodafone_station (#128781)

This commit is contained in:
epenet 2024-10-19 16:42:01 +02:00 committed by GitHub
parent 6f9c99ac6c
commit 5f04a6239e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -60,7 +60,6 @@ class VodafoneStationConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Vodafone Station."""
VERSION = 1
entry: ConfigEntry | None = None
@staticmethod
@callback
@ -106,21 +105,19 @@ class VodafoneStationConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Handle reauth flow."""
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
assert self.entry
self.context["title_placeholders"] = {"host": self.entry.data[CONF_HOST]}
self.context["title_placeholders"] = {"host": entry_data[CONF_HOST]}
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle reauth confirm."""
assert self.entry
errors = {}
reauth_entry = self._get_reauth_entry()
if user_input is not None:
try:
await validate_input(self.hass, {**self.entry.data, **user_input})
await validate_input(self.hass, {**reauth_entry.data, **user_input})
except aiovodafone_exceptions.AlreadyLogged:
errors["base"] = "already_logged"
except aiovodafone_exceptions.CannotConnect:
@ -131,21 +128,16 @@ class VodafoneStationConfigFlow(ConfigFlow, domain=DOMAIN):
_LOGGER.exception("Unexpected exception")
errors["base"] = "unknown"
else:
self.hass.config_entries.async_update_entry(
self.entry,
data={
**self.entry.data,
return self.async_update_reload_and_abort(
reauth_entry,
data_updates={
CONF_PASSWORD: user_input[CONF_PASSWORD],
},
)
self.hass.async_create_task(
self.hass.config_entries.async_reload(self.entry.entry_id)
)
return self.async_abort(reason="reauth_successful")
return self.async_show_form(
step_id="reauth_confirm",
description_placeholders={CONF_HOST: self.entry.data[CONF_HOST]},
description_placeholders={CONF_HOST: reauth_entry.data[CONF_HOST]},
data_schema=STEP_REAUTH_DATA_SCHEMA,
errors=errors,
)