Use reauth helpers in google_photos (#128585)

This commit is contained in:
epenet 2024-10-18 09:02:44 +02:00 committed by GitHub
parent 8a4d72e3b1
commit 84d4a1ce34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,11 +7,11 @@ from typing import Any
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
@ -22,8 +22,6 @@ class OAuth2FlowHandler(
DOMAIN = DOMAIN
reauth_entry: GooglePhotosConfigEntry | None = None
@property
def logger(self) -> logging.Logger:
"""Return logger."""
@ -58,14 +56,13 @@ class OAuth2FlowHandler(
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)
@ -73,9 +70,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(