Use reauth helpers in glances (#128579)

This commit is contained in:
epenet 2024-10-18 10:01:20 +02:00 committed by GitHub
parent 2d90ffcbf0
commit d2eb0e1fde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,7 @@ from glances_api.exceptions import (
)
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
@ -40,15 +40,11 @@ class GlancesFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle a Glances config flow."""
VERSION = 1
_reauth_entry: ConfigEntry | None
async def async_step_reauth(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Perform reauth upon an API authentication error."""
self._reauth_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(
@ -56,9 +52,10 @@ class GlancesFlowHandler(ConfigFlow, domain=DOMAIN):
) -> ConfigFlowResult:
"""Confirm reauth dialog."""
errors = {}
assert self._reauth_entry
reauth_entry = self._get_reauth_entry()
if user_input is not None:
user_input = {**self._reauth_entry.data, **user_input}
user_input = {**reauth_entry.data, **user_input}
try:
await get_api(self.hass, user_input)
except GlancesApiAuthorizationError:
@ -67,15 +64,13 @@ class GlancesFlowHandler(ConfigFlow, domain=DOMAIN):
errors["base"] = "cannot_connect"
else:
self.hass.config_entries.async_update_entry(
self._reauth_entry, data=user_input
reauth_entry, data=user_input
)
await self.hass.config_entries.async_reload(self._reauth_entry.entry_id)
await self.hass.config_entries.async_reload(reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")
return self.async_show_form(
description_placeholders={
CONF_USERNAME: self._reauth_entry.data[CONF_USERNAME]
},
description_placeholders={CONF_USERNAME: reauth_entry.data[CONF_USERNAME]},
step_id="reauth_confirm",
data_schema=vol.Schema(
{