Home Assistant Unofficial Reference 2024.12.1
api.py
Go to the documentation of this file.
1 """API for Monzo bound to Home Assistant OAuth."""
2 
3 from aiohttp import ClientSession
4 from monzopy import AbstractMonzoApi
5 
6 from homeassistant.helpers import config_entry_oauth2_flow
7 
8 
9 class AuthenticatedMonzoAPI(AbstractMonzoApi):
10  """A Monzo API instance with authentication tied to an OAuth2 based config entry."""
11 
12  def __init__(
13  self,
14  websession: ClientSession,
15  oauth_session: config_entry_oauth2_flow.OAuth2Session,
16  ) -> None:
17  """Initialize Monzo auth."""
18  super().__init__(websession)
19  self._oauth_session_oauth_session = oauth_session
20 
21  async def async_get_access_token(self) -> str:
22  """Return a valid access token."""
23  await self._oauth_session_oauth_session.async_ensure_token_valid()
24 
25  return str(self._oauth_session_oauth_session.token["access_token"])
None __init__(self, ClientSession websession, config_entry_oauth2_flow.OAuth2Session oauth_session)
Definition: api.py:16