Home Assistant Unofficial Reference 2024.12.1
api.py
Go to the documentation of this file.
1 """API for iotty bound to Home Assistant OAuth."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from aiohttp import ClientSession
8 from iottycloud.cloudapi import CloudApi
9 
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers import config_entry_oauth2_flow
12 
13 OAUTH2_CLIENT_ID = "hass-iotty"
14 IOTTYAPI_BASE = "https://homeassistant.iotty.com/"
15 
16 
17 class IottyProxy(CloudApi):
18  """Provide iotty authentication tied to an OAuth2 based config entry."""
19 
20  def __init__(
21  self,
22  hass: HomeAssistant,
23  websession: ClientSession,
24  oauth_session: config_entry_oauth2_flow.OAuth2Session,
25  ) -> None:
26  """Initialize iotty auth."""
27 
28  super().__init__(websession, IOTTYAPI_BASE, OAUTH2_CLIENT_ID)
29  if oauth_session is None:
30  raise ValueError("oauth_session")
31  self._oauth_session_oauth_session = oauth_session
32  self._hass_hass = hass
33 
34  async def async_get_access_token(self) -> Any:
35  """Return a valid access token."""
36  await self._oauth_session_oauth_session.async_ensure_token_valid()
37 
38  return self._oauth_session_oauth_session.token["access_token"]
None __init__(self, HomeAssistant hass, ClientSession websession, config_entry_oauth2_flow.OAuth2Session oauth_session)
Definition: api.py:25