From 5228aa5e5c5570b2d5c8b7500cc909f49962fa59 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 20 Oct 2024 10:01:53 +0200 Subject: [PATCH] Use new reauth helpers in yale (#128828) --- homeassistant/components/yale/config_flow.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/yale/config_flow.py b/homeassistant/components/yale/config_flow.py index 6cbc9543ea4..fecf286fdd6 100644 --- a/homeassistant/components/yale/config_flow.py +++ b/homeassistant/components/yale/config_flow.py @@ -6,7 +6,7 @@ from typing import Any import jwt -from homeassistant.config_entries import ConfigEntry, ConfigFlowResult +from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult from homeassistant.helpers import config_entry_oauth2_flow from .const import DOMAIN @@ -19,7 +19,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain= VERSION = 1 DOMAIN = DOMAIN - reauth_entry: ConfigEntry | None = None @property def logger(self) -> logging.Logger: @@ -30,9 +29,6 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, 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"] - ) return await self.async_step_user() def _async_get_user_id_from_access_token(self, encoded: str) -> str: @@ -51,10 +47,11 @@ class YaleConfigFlow(config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain= user_id = self._async_get_user_id_from_access_token( data["token"]["access_token"] ) - if entry := self.reauth_entry: - if entry.unique_id != user_id: - return self.async_abort(reason="reauth_invalid_user") - return self.async_update_reload_and_abort(entry, data=data) await self.async_set_unique_id(user_id) + if self.source == SOURCE_REAUTH: + self._abort_if_unique_id_mismatch(reason="reauth_invalid_user") + return self.async_update_reload_and_abort( + self._get_reauth_entry(), data=data + ) self._abort_if_unique_id_configured() return await super().async_oauth_create_entry(data)