Home Assistant Unofficial Reference 2024.12.1
gateway.py
Go to the documentation of this file.
1 """Handle Yale connection setup and authentication."""
2 
3 import logging
4 from pathlib import Path
5 
6 from aiohttp import ClientSession
7 from yalexs.authenticator_common import Authentication, AuthenticationState
8 from yalexs.manager.gateway import Gateway
9 
10 from homeassistant.helpers import config_entry_oauth2_flow
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 
15 class YaleGateway(Gateway):
16  """Handle the connection to Yale."""
17 
18  def __init__(
19  self,
20  config_path: Path,
21  aiohttp_session: ClientSession,
22  oauth_session: config_entry_oauth2_flow.OAuth2Session,
23  ) -> None:
24  """Init the connection."""
25  super().__init__(config_path, aiohttp_session)
26  self._oauth_session_oauth_session = oauth_session
27 
28  async def async_get_access_token(self) -> str:
29  """Get access token."""
30  await self._oauth_session_oauth_session.async_ensure_token_valid()
31  return self._oauth_session_oauth_session.token["access_token"]
32 
33  async def async_refresh_access_token_if_needed(self) -> None:
34  """Refresh the access token if needed."""
35  await self._oauth_session_oauth_session.async_ensure_token_valid()
36 
37  async def async_authenticate(self) -> Authentication:
38  """Authenticate with the details provided to setup."""
39  await self._oauth_session_oauth_session.async_ensure_token_valid()
40  self.authenticationauthentication = Authentication(
41  AuthenticationState.AUTHENTICATED, None, None, None
42  )
43  return self.authenticationauthentication
None __init__(self, Path config_path, ClientSession aiohttp_session, config_entry_oauth2_flow.OAuth2Session oauth_session)
Definition: gateway.py:23