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
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]
None __init__(self, ClientSession websession, OAuth2Session oauth_session)
Definition: api.py:19