diff --git a/homeassistant/components/bmw_connected_drive/config_flow.py b/homeassistant/components/bmw_connected_drive/config_flow.py index 636274a01ad..8132d241ca4 100644 --- a/homeassistant/components/bmw_connected_drive/config_flow.py +++ b/homeassistant/components/bmw_connected_drive/config_flow.py @@ -12,6 +12,7 @@ from httpx import RequestError import voluptuous as vol from homeassistant.config_entries import ( + SOURCE_REAUTH, ConfigEntry, ConfigFlow, ConfigFlowResult, @@ -71,7 +72,7 @@ class BMWConfigFlow(ConfigFlow, domain=DOMAIN): VERSION = 1 - _reauth_entry: ConfigEntry | None = None + _reauth_entry: ConfigEntry async def async_step_user( self, user_input: dict[str, Any] | None = None @@ -82,7 +83,7 @@ class BMWConfigFlow(ConfigFlow, domain=DOMAIN): if user_input is not None: unique_id = f"{user_input[CONF_REGION]}-{user_input[CONF_USERNAME]}" - if not self._reauth_entry: + if self.source != SOURCE_REAUTH: await self.async_set_unique_id(unique_id) self._abort_if_unique_id_configured() @@ -100,7 +101,7 @@ class BMWConfigFlow(ConfigFlow, domain=DOMAIN): errors["base"] = "invalid_auth" if info: - if self._reauth_entry: + if self.source == SOURCE_REAUTH: self.hass.config_entries.async_update_entry( self._reauth_entry, data=entry_data ) @@ -117,7 +118,7 @@ class BMWConfigFlow(ConfigFlow, domain=DOMAIN): ) schema = self.add_suggested_values_to_schema( - DATA_SCHEMA, self._reauth_entry.data if self._reauth_entry else {} + DATA_SCHEMA, self._reauth_entry.data if self.source == SOURCE_REAUTH else {} ) return self.async_show_form(step_id="user", data_schema=schema, errors=errors) @@ -126,9 +127,7 @@ class BMWConfigFlow(ConfigFlow, domain=DOMAIN): self, entry_data: Mapping[str, Any] ) -> ConfigFlowResult: """Handle configuration by re-auth.""" - self._reauth_entry = self.hass.config_entries.async_get_entry( - self.context["entry_id"] - ) + self._reauth_entry = self._get_reauth_entry() return await self.async_step_user() @staticmethod