Home Assistant Unofficial Reference 2024.12.1
api.py
Go to the documentation of this file.
1 """API for nVent RAYCHEM SENZ bound to Home Assistant OAuth."""
2 
3 from typing import cast
4 
5 from aiosenz import AbstractSENZAuth
6 from httpx import AsyncClient
7 
8 from homeassistant.helpers import config_entry_oauth2_flow
9 
10 
11 class SENZConfigEntryAuth(AbstractSENZAuth):
12  """Provide nVent RAYCHEM SENZ authentication tied to an OAuth2 based config entry."""
13 
14  def __init__(
15  self,
16  httpx_async_client: AsyncClient,
17  oauth_session: config_entry_oauth2_flow.OAuth2Session,
18  ) -> None:
19  """Initialize SENZ auth."""
20  super().__init__(httpx_async_client)
21  self._oauth_session_oauth_session = oauth_session
22 
23  async def get_access_token(self) -> str:
24  """Return a valid access token."""
25  await self._oauth_session_oauth_session.async_ensure_token_valid()
26  return cast(str, self._oauth_session_oauth_session.token["access_token"])
None __init__(self, AsyncClient httpx_async_client, config_entry_oauth2_flow.OAuth2Session oauth_session)
Definition: api.py:18