1 """Config flow for Google Photos."""
3 from collections.abc
import Mapping
7 from google_photos_library_api.api
import GooglePhotosLibraryApi
8 from google_photos_library_api.exceptions
import GooglePhotosApiError
15 from .const
import DOMAIN, OAUTH2_SCOPES
19 config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
21 """Config flow to handle Google Photos OAuth2 authentication."""
28 return logging.getLogger(__name__)
32 """Extra data that needs to be appended to the authorize url."""
34 "scope":
" ".join(OAUTH2_SCOPES),
36 "access_type":
"offline",
41 """Create an entry for the flow."""
42 session = aiohttp_client.async_get_clientsession(self.hass)
44 client = GooglePhotosLibraryApi(auth)
47 user_resource_info = await client.get_user_info()
48 await client.list_media_items(page_size=1)
49 except GooglePhotosApiError
as ex:
50 return self.async_abort(
51 reason=
"access_not_configured",
52 description_placeholders={
"message":
str(ex)},
55 self.
loggerlogger.exception(
"Unknown error occurred")
56 return self.async_abort(reason=
"unknown")
57 user_id = user_resource_info.id
59 await self.async_set_unique_id(user_id)
60 if self.
sourcesource == SOURCE_REAUTH:
61 self._abort_if_unique_id_mismatch(reason=
"wrong_account")
62 return self.async_update_reload_and_abort(
63 self._get_reauth_entry(), data=data
66 self._abort_if_unique_id_configured()
67 return self.async_create_entry(title=user_resource_info.name, data=data)
70 self, entry_data: Mapping[str, Any]
71 ) -> ConfigFlowResult:
72 """Perform reauth upon an API authentication error."""
76 self, user_input: Mapping[str, Any] |
None =
None
77 ) -> ConfigFlowResult:
78 """Confirm reauth dialog."""
79 if user_input
is None:
80 return self.async_show_form(step_id=
"reauth_confirm")
81 return await self.async_step_user()
ConfigFlowResult async_oauth_create_entry(self, dict[str, Any] data)
dict[str, Any] extra_authorize_data(self)
ConfigFlowResult async_step_reauth_confirm(self, Mapping[str, Any]|None user_input=None)
logging.Logger logger(self)
ConfigFlowResult async_step_reauth(self, Mapping[str, Any] entry_data)