From d2eb0e1fde2b598c6167f83f48a148acdca66e41 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:01:20 +0200 Subject: [PATCH] Use reauth helpers in glances (#128579) --- .../components/glances/config_flow.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/glances/config_flow.py b/homeassistant/components/glances/config_flow.py index 9208a4b0ebd..1dbc939d532 100644 --- a/homeassistant/components/glances/config_flow.py +++ b/homeassistant/components/glances/config_flow.py @@ -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( {