From 153b3fbfc81ed0ea49942363b9c5ed21d33546d9 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:56:00 +0200 Subject: [PATCH] Use reauth helpers in comelit config flow (#127443) * Use reauth helpers in comelit config flow * Fix --- .../components/comelit/config_flow.py | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/comelit/config_flow.py b/homeassistant/components/comelit/config_flow.py index c83caeda642..46fc13796a0 100644 --- a/homeassistant/components/comelit/config_flow.py +++ b/homeassistant/components/comelit/config_flow.py @@ -14,7 +14,7 @@ from aiocomelit.api import ComelitCommonApi from aiocomelit.const import BRIDGE 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_PIN, CONF_PORT, CONF_TYPE from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -68,10 +68,6 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN): """Handle a config flow for Comelit.""" VERSION = 1 - _reauth_entry: ConfigEntry - _reauth_host: str - _reauth_port: int - _reauth_type: str async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -106,12 +102,7 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle reauth flow.""" - self._reauth_entry = self._get_reauth_entry() - self._reauth_host = entry_data[CONF_HOST] - self._reauth_port = entry_data.get(CONF_PORT, DEFAULT_PORT) - self._reauth_type = entry_data.get(CONF_TYPE, BRIDGE) - - self.context["title_placeholders"] = {"host": self._reauth_host} + self.context["title_placeholders"] = {"host": entry_data[CONF_HOST]} return await self.async_step_reauth_confirm() async def async_step_reauth_confirm( @@ -120,14 +111,17 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN): """Handle reauth confirm.""" errors = {} + reauth_entry = self._get_reauth_entry() + entry_data = reauth_entry.data + if user_input is not None: try: await validate_input( self.hass, { - CONF_HOST: self._reauth_host, - CONF_PORT: self._reauth_port, - CONF_TYPE: self._reauth_type, + CONF_HOST: entry_data[CONF_HOST], + CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT), + CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE), } | user_input, ) @@ -139,23 +133,19 @@ class ComelitConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" else: - self.hass.config_entries.async_update_entry( - self._reauth_entry, + return self.async_update_reload_and_abort( + reauth_entry, data={ - CONF_HOST: self._reauth_host, - CONF_PORT: self._reauth_port, + CONF_HOST: entry_data[CONF_HOST], + CONF_PORT: entry_data.get(CONF_PORT, DEFAULT_PORT), CONF_PIN: user_input[CONF_PIN], - CONF_TYPE: self._reauth_type, + CONF_TYPE: entry_data.get(CONF_TYPE, BRIDGE), }, ) - self.hass.async_create_task( - self.hass.config_entries.async_reload(self._reauth_entry.entry_id) - ) - return self.async_abort(reason="reauth_successful") return self.async_show_form( step_id="reauth_confirm", - description_placeholders={CONF_HOST: self._reauth_entry.data[CONF_HOST]}, + description_placeholders={CONF_HOST: entry_data[CONF_HOST]}, data_schema=STEP_REAUTH_DATA_SCHEMA, errors=errors, )