Skip to content

Commit

Permalink
Use new reauth helpers in youtube (home-assistant#128835)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored and Andrew committed Oct 21, 2024
1 parent 2ecf25d commit b6345b9
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions homeassistant/components/youtube/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from youtubeaio.youtube import YouTube

from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry,
ConfigFlowResult,
OptionsFlowWithConfigEntry,
Expand Down Expand Up @@ -45,7 +46,6 @@ class OAuth2FlowHandler(

DOMAIN = DOMAIN

reauth_entry: ConfigEntry | None = None
_youtube: YouTube | None = None

@staticmethod
Expand Down Expand Up @@ -75,9 +75,6 @@ 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(
Expand Down Expand Up @@ -117,22 +114,19 @@ async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResu
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:
Expand Down

0 comments on commit b6345b9

Please sign in to comment.