J. Nick Koston 03ead27f6c
Split august and yale integrations (#124677)
* Split august and yale integrations [part 1] (#122253)

* merge with dev

* Remove unused constant

* Remove yale IPv6 workaround (#123409)

* Convert yale to use oauth (#123806)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* Update yale for switch from pubnub to websockets (#124675)

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-08-28 17:46:03 +02:00

44 lines
1.4 KiB
Python

"""Handle Yale connection setup and authentication."""
import logging
from pathlib import Path
from aiohttp import ClientSession
from yalexs.authenticator_common import Authentication, AuthenticationState
from yalexs.manager.gateway import Gateway
from homeassistant.helpers import config_entry_oauth2_flow
_LOGGER = logging.getLogger(__name__)
class YaleGateway(Gateway):
"""Handle the connection to Yale."""
def __init__(
self,
config_path: Path,
aiohttp_session: ClientSession,
oauth_session: config_entry_oauth2_flow.OAuth2Session,
) -> None:
"""Init the connection."""
super().__init__(config_path, aiohttp_session)
self._oauth_session = oauth_session
async def async_get_access_token(self) -> str:
"""Get access token."""
await self._oauth_session.async_ensure_token_valid()
return self._oauth_session.token["access_token"]
async def async_refresh_access_token_if_needed(self) -> None:
"""Refresh the access token if needed."""
await self._oauth_session.async_ensure_token_valid()
async def async_authenticate(self) -> Authentication:
"""Authenticate with the details provided to setup."""
await self._oauth_session.async_ensure_token_valid()
self.authentication = Authentication(
AuthenticationState.AUTHENTICATED, None, None, None
)
return self.authentication