Use reauth helpers in brunt config flow (#127438)

pull/127505/head
epenet 2024-10-03 19:48:47 +02:00 committed by GitHub
parent c634f6067a
commit 09014e3390
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 8 deletions

View File

@ -11,7 +11,7 @@ from aiohttp.client_exceptions import ServerDisconnectedError
from brunt import BruntClientAsync
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from .const import DOMAIN
@ -56,8 +56,6 @@ class BruntConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 1
_reauth_entry: ConfigEntry
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
@ -82,14 +80,14 @@ class BruntConfigFlow(ConfigFlow, domain=DOMAIN):
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Perform reauth upon an API authentication error."""
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."""
username = self._reauth_entry.data[CONF_USERNAME]
reauth_entry = self._get_reauth_entry()
username = reauth_entry.data[CONF_USERNAME]
if user_input is None:
return self.async_show_form(
step_id="reauth_confirm",
@ -106,6 +104,4 @@ class BruntConfigFlow(ConfigFlow, domain=DOMAIN):
description_placeholders={"username": username},
)
self.hass.config_entries.async_update_entry(self._reauth_entry, data=user_input)
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")
return self.async_update_reload_and_abort(reauth_entry, data=user_input)