Skip to content

Commit

Permalink
Use reauth helpers in google_photos (home-assistant#128585)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Oct 18, 2024
1 parent 8a4d72e commit 84d4a1c
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions homeassistant/components/google_photos/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from google_photos_library_api.api import GooglePhotosLibraryApi
from google_photos_library_api.exceptions import GooglePhotosApiError

from homeassistant.config_entries import ConfigFlowResult
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
from homeassistant.helpers import aiohttp_client, config_entry_oauth2_flow

from . import GooglePhotosConfigEntry, api
from . import api
from .const import DOMAIN, OAUTH2_SCOPES


Expand All @@ -22,8 +22,6 @@ class OAuth2FlowHandler(

DOMAIN = DOMAIN

reauth_entry: GooglePhotosConfigEntry | None = None

@property
def logger(self) -> logging.Logger:
"""Return logger."""
Expand Down Expand Up @@ -58,24 +56,20 @@ async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResu
return self.async_abort(reason="unknown")
user_id = user_resource_info.id

if self.reauth_entry:
if self.reauth_entry.unique_id == user_id:
return self.async_update_reload_and_abort(
self.reauth_entry, unique_id=user_id, data=data
)
return self.async_abort(reason="wrong_account")

await self.async_set_unique_id(user_id)
if self.source == SOURCE_REAUTH:
self._abort_if_unique_id_mismatch(reason="wrong_account")
return self.async_update_reload_and_abort(
self._get_reauth_entry(), data=data
)

self._abort_if_unique_id_configured()
return self.async_create_entry(title=user_resource_info.name, 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(
Expand Down

0 comments on commit 84d4a1c

Please sign in to comment.