Home Assistant Unofficial Reference 2024.12.1
api.py
Go to the documentation of this file.
1 """API for microBees bound to Home Assistant OAuth."""
2 
3 from homeassistant.const import CONF_ACCESS_TOKEN
4 from homeassistant.core import HomeAssistant
5 from homeassistant.helpers import config_entry_oauth2_flow
6 
7 
9  """Provide microBees authentication tied to an OAuth2 based config entry."""
10 
11  def __init__(
12  self,
13  hass: HomeAssistant,
14  oauth2_session: config_entry_oauth2_flow.OAuth2Session,
15  ) -> None:
16  """Initialize microBees Auth."""
17  self.oauth_sessionoauth_session = oauth2_session
18  self.hasshass = hass
19 
20  @property
21  def access_token(self) -> str:
22  """Return the access token."""
23  return self.oauth_sessionoauth_session.token[CONF_ACCESS_TOKEN]
24 
25  async def check_and_refresh_token(self) -> str:
26  """Check the token."""
27  await self.oauth_sessionoauth_session.async_ensure_token_valid()
28  return self.access_tokenaccess_token
None __init__(self, HomeAssistant hass, config_entry_oauth2_flow.OAuth2Session oauth2_session)
Definition: api.py:15