1
0
mirror of https://github.com/home-assistant/core.git synced 2025-05-08 16:09:22 +00:00
Christopher Fenner 144454b8c3
Remove duplicate oauth2 token validity check ()
* remove duplicate validity check

* Apply suggestions from code review

* add leftover

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-10-16 11:42:44 +02:00

32 lines
921 B
Python

"""API for myUplink bound to Home Assistant OAuth."""
from __future__ import annotations
from typing import cast
from aiohttp import ClientSession
from myuplink.auth_abstract import AbstractAuth
from homeassistant.helpers import config_entry_oauth2_flow
from .const import API_ENDPOINT
class AsyncConfigEntryAuth(AbstractAuth):
"""Provide myUplink authentication tied to an OAuth2 based config entry."""
def __init__(
self,
websession: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
"""Initialize myUplink auth."""
super().__init__(websession, API_ENDPOINT)
self._oauth_session = oauth_session
async def async_get_access_token(self) -> str:
"""Return a valid access token."""
await self._oauth_session.async_ensure_token_valid()
return cast(str, self._oauth_session.token["access_token"])