diff --git a/homeassistant/components/google_tasks/config_flow.py b/homeassistant/components/google_tasks/config_flow.py index 965c215ee4d..795b6e6eff5 100644 --- a/homeassistant/components/google_tasks/config_flow.py +++ b/homeassistant/components/google_tasks/config_flow.py @@ -9,7 +9,7 @@ from googleapiclient.discovery import build from googleapiclient.errors import HttpError from googleapiclient.http import HttpRequest -from homeassistant.config_entries import ConfigEntry, ConfigFlowResult +from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN from homeassistant.helpers import config_entry_oauth2_flow @@ -23,8 +23,6 @@ class OAuth2FlowHandler( DOMAIN = DOMAIN - reauth_entry: ConfigEntry | None = None - @property def logger(self) -> logging.Logger: """Return logger.""" @@ -70,25 +68,24 @@ class OAuth2FlowHandler( self.logger.exception("Unknown error occurred") return self.async_abort(reason="unknown") user_id = user_resource_info["id"] - if not self.reauth_entry: - await self.async_set_unique_id(user_id) + await self.async_set_unique_id(user_id) + + if self.source != SOURCE_REAUTH: self._abort_if_unique_id_configured() return self.async_create_entry(title=user_resource_info["name"], data=data) - if self.reauth_entry.unique_id == user_id or not self.reauth_entry.unique_id: - return self.async_update_reload_and_abort( - self.reauth_entry, unique_id=user_id, data=data - ) + reauth_entry = self._get_reauth_entry() + if reauth_entry.unique_id: + self._abort_if_unique_id_mismatch(reason="wrong_account") - return self.async_abort(reason="wrong_account") + return self.async_update_reload_and_abort( + reauth_entry, unique_id=user_id, data=data + ) 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(