Home Assistant Unofficial Reference
2024.12.1
api.py
Go to the documentation of this file.
1
"""API for Weheat bound to Home Assistant OAuth."""
2
3
from
aiohttp
import
ClientSession
4
from
weheat.abstractions
import
AbstractAuth
5
6
from
homeassistant.const
import
CONF_ACCESS_TOKEN
7
from
homeassistant.helpers.config_entry_oauth2_flow
import
OAuth2Session
8
9
from
.const
import
API_URL
10
11
12
class
AsyncConfigEntryAuth
(AbstractAuth):
13
"""Provide Weheat authentication tied to an OAuth2 based config entry."""
14
15
def
__init__
(
16
self,
17
websession: ClientSession,
18
oauth_session: OAuth2Session,
19
) ->
None
:
20
"""Initialize Weheat auth."""
21
super().
__init__
(websession, host=API_URL)
22
self.
_oauth_session
_oauth_session = oauth_session
23
24
async
def
async_get_access_token
(self) -> str:
25
"""Return a valid access token."""
26
await self.
_oauth_session
_oauth_session.async_ensure_token_valid()
27
28
return
self.
_oauth_session
_oauth_session.token[CONF_ACCESS_TOKEN]
homeassistant.components.weheat.api.AsyncConfigEntryAuth
Definition:
api.py:12
homeassistant.components.weheat.api.AsyncConfigEntryAuth.async_get_access_token
str async_get_access_token(self)
Definition:
api.py:24
homeassistant.components.weheat.api.AsyncConfigEntryAuth._oauth_session
_oauth_session
Definition:
api.py:22
homeassistant.components.weheat.api.AsyncConfigEntryAuth.__init__
None __init__(self, ClientSession websession, OAuth2Session oauth_session)
Definition:
api.py:19
homeassistant.const
Definition:
const.py:1
homeassistant.helpers.config_entry_oauth2_flow
Definition:
config_entry_oauth2_flow.py:1
core
homeassistant
components
weheat
api.py
Generated by
1.9.1