From f9ce8fa368f6ed2e66d7521b816753ef498e8231 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 20 Oct 2024 15:34:37 +0200 Subject: [PATCH] Use new reauth helpers in youtube (#128835) --- .../components/youtube/config_flow.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/youtube/config_flow.py b/homeassistant/components/youtube/config_flow.py index 32b37b93eb2..8d6c7753282 100644 --- a/homeassistant/components/youtube/config_flow.py +++ b/homeassistant/components/youtube/config_flow.py @@ -12,6 +12,7 @@ from youtubeaio.types import AuthScope, ForbiddenError from youtubeaio.youtube import YouTube from homeassistant.config_entries import ( + SOURCE_REAUTH, ConfigEntry, ConfigFlowResult, OptionsFlowWithConfigEntry, @@ -45,7 +46,6 @@ class OAuth2FlowHandler( DOMAIN = DOMAIN - reauth_entry: ConfigEntry | None = None _youtube: YouTube | None = None @staticmethod @@ -75,9 +75,6 @@ class OAuth2FlowHandler( 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( @@ -117,22 +114,19 @@ class OAuth2FlowHandler( self._title = own_channel.snippet.title self._data = data - if not self.reauth_entry: - await self.async_set_unique_id(own_channel.channel_id) + await self.async_set_unique_id(own_channel.channel_id) + if self.source != SOURCE_REAUTH: self._abort_if_unique_id_configured() return await self.async_step_channels() - if self.reauth_entry.unique_id == own_channel.channel_id: - self.hass.config_entries.async_update_entry(self.reauth_entry, data=data) - await self.hass.config_entries.async_reload(self.reauth_entry.entry_id) - return self.async_abort(reason="reauth_successful") - - return self.async_abort( + self._abort_if_unique_id_mismatch( reason="wrong_account", description_placeholders={"title": self._title}, ) + return self.async_update_reload_and_abort(self._get_reauth_entry(), data=data) + async def async_step_channels( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: