1
0
mirror of https://github.com/home-assistant/core.git synced 2026-07-13 01:27:57 +01:00
Files
core/homeassistant/components/monzo/api.py
T
2026-06-22 19:35:53 +02:00

29 lines
847 B
Python

"""API for Monzo bound to Home Assistant OAuth."""
from typing import override
from aiohttp import ClientSession
from monzopy import AbstractMonzoApi
from homeassistant.helpers import config_entry_oauth2_flow
class AuthenticatedMonzoAPI(AbstractMonzoApi):
"""A Monzo API instance with authentication tied to an OAuth2 based config entry."""
def __init__(
self,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
"""Initialize Monzo auth."""
super().__init__(websession)
self._oauth_session = oauth_session
@override
async def async_get_access_token(self) -> str:
"""Return a valid access token."""
await self._oauth_session.async_ensure_token_valid()
return str(self._oauth_session.token["access_token"])