Home Assistant Unofficial Reference
2024.12.1
api.py
Go to the documentation of this file.
1
"""API for Google Photos bound to Home Assistant OAuth."""
2
3
from
typing
import
cast
4
5
import
aiohttp
6
from
google_photos_library_api
import
api
7
8
from
homeassistant.const
import
CONF_ACCESS_TOKEN
9
from
homeassistant.helpers
import
config_entry_oauth2_flow
10
11
12
class
AsyncConfigEntryAuth
(api.AbstractAuth):
13
"""Provide Google Photos authentication tied to an OAuth2 based config entry."""
14
15
def
__init__
(
16
self,
17
websession: aiohttp.ClientSession,
18
oauth_session: config_entry_oauth2_flow.OAuth2Session,
19
) ->
None
:
20
"""Initialize AsyncConfigEntryAuth."""
21
super().
__init__
(websession)
22
self.
_session
_session = oauth_session
23
24
async
def
async_get_access_token
(self) -> str:
25
"""Return a valid access token."""
26
await self.
_session
_session.async_ensure_token_valid()
27
return
cast(str, self.
_session
_session.token[CONF_ACCESS_TOKEN])
28
29
30
class
AsyncConfigFlowAuth
(api.AbstractAuth):
31
"""An API client used during the config flow with a fixed token."""
32
33
def
__init__
(
34
self,
35
websession: aiohttp.ClientSession,
36
token: str,
37
) ->
None
:
38
"""Initialize ConfigFlowAuth."""
39
super().
__init__
(websession)
40
self.
_token
_token = token
41
42
async
def
async_get_access_token
(self) -> str:
43
"""Return a valid access token."""
44
return
self.
_token
_token
homeassistant.components.google_photos.api.AsyncConfigEntryAuth
Definition:
api.py:12
homeassistant.components.google_photos.api.AsyncConfigEntryAuth._session
_session
Definition:
api.py:22
homeassistant.components.google_photos.api.AsyncConfigEntryAuth.__init__
None __init__(self, aiohttp.ClientSession websession, config_entry_oauth2_flow.OAuth2Session oauth_session)
Definition:
api.py:19
homeassistant.components.google_photos.api.AsyncConfigEntryAuth.async_get_access_token
str async_get_access_token(self)
Definition:
api.py:24
homeassistant.components.google_photos.api.AsyncConfigFlowAuth
Definition:
api.py:30
homeassistant.components.google_photos.api.AsyncConfigFlowAuth.__init__
None __init__(self, aiohttp.ClientSession websession, str token)
Definition:
api.py:37
homeassistant.components.google_photos.api.AsyncConfigFlowAuth.async_get_access_token
str async_get_access_token(self)
Definition:
api.py:42
homeassistant.components.google_photos.api.AsyncConfigFlowAuth._token
_token
Definition:
api.py:40
homeassistant.const
Definition:
const.py:1
homeassistant.helpers
Definition:
__init__.py:1
core
homeassistant
components
google_photos
api.py
Generated by
1.9.1