diff --git a/homeassistant/components/elmax/config_flow.py b/homeassistant/components/elmax/config_flow.py index 69f69a5fd31..bf479e997ef 100644 --- a/homeassistant/components/elmax/config_flow.py +++ b/homeassistant/components/elmax/config_flow.py @@ -13,7 +13,7 @@ import httpx import voluptuous as vol from homeassistant.components.zeroconf import ZeroconfServiceInfo -from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult from homeassistant.exceptions import HomeAssistantError from .common import ( @@ -114,7 +114,6 @@ class ElmaxConfigFlow(ConfigFlow, domain=DOMAIN): # Panel selection variables _panels_schema: vol.Schema _panel_names: dict - _entry: ConfigEntry | None async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -395,7 +394,6 @@ class ElmaxConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Perform reauth upon an API authentication error.""" - self._entry = self.hass.config_entries.async_get_entry(self.context["entry_id"]) self._reauth_cloud_username = entry_data.get(CONF_ELMAX_USERNAME) self._reauth_cloud_panelid = entry_data.get(CONF_ELMAX_PANEL_ID) return await self.async_step_reauth_confirm() @@ -413,7 +411,7 @@ class ElmaxConfigFlow(ConfigFlow, domain=DOMAIN): # Handle authentication, make sure the panel we are re-authenticating against is listed among results # and verify its pin is correct. - assert self._entry is not None + reauth_entry = self._get_reauth_entry() try: # Test login. client = await self._async_login(username=username, password=password) @@ -421,14 +419,14 @@ class ElmaxConfigFlow(ConfigFlow, domain=DOMAIN): panels = [ p for p in await client.list_control_panels() - if p.hash == self._entry.data[CONF_ELMAX_PANEL_ID] + if p.hash == reauth_entry.data[CONF_ELMAX_PANEL_ID] ] if len(panels) < 1: raise NoOnlinePanelsError # noqa: TRY301 # Verify the pin is still valid. await client.get_panel_status( - control_panel_id=self._entry.data[CONF_ELMAX_PANEL_ID], + control_panel_id=reauth_entry.data[CONF_ELMAX_PANEL_ID], pin=panel_pin, ) @@ -440,18 +438,16 @@ class ElmaxConfigFlow(ConfigFlow, domain=DOMAIN): errors["base"] = "invalid_pin" # If all went right, update the config entry - if not errors: - self.hass.config_entries.async_update_entry( - self._entry, + else: + return self.async_update_reload_and_abort( + reauth_entry, data={ - CONF_ELMAX_PANEL_ID: self._entry.data[CONF_ELMAX_PANEL_ID], + CONF_ELMAX_PANEL_ID: reauth_entry.data[CONF_ELMAX_PANEL_ID], CONF_ELMAX_PANEL_PIN: panel_pin, CONF_ELMAX_USERNAME: username, CONF_ELMAX_PASSWORD: password, }, ) - await self.hass.config_entries.async_reload(self._entry.entry_id) - return self.async_abort(reason="reauth_successful") # Otherwise start over and show the relative error message return self.async_show_form(