Improve august typing (4) (#108331)
This commit is contained in:
parent
6e8e14fbe2
commit
0206833cfd
1 changed files with 7 additions and 8 deletions
|
@ -35,19 +35,19 @@ class AugustGateway:
|
|||
"""Handle the connection to August."""
|
||||
|
||||
api: ApiAsync
|
||||
authenticator: AuthenticatorAsync
|
||||
authentication: Authentication
|
||||
_access_token_cache_file: str
|
||||
|
||||
def __init__(self, hass: HomeAssistant, aiohttp_session: ClientSession) -> None:
|
||||
"""Init the connection."""
|
||||
self._aiohttp_session = aiohttp_session
|
||||
self._token_refresh_lock = asyncio.Lock()
|
||||
self._access_token_cache_file: str | None = None
|
||||
self._hass: HomeAssistant = hass
|
||||
self._config: Mapping[str, Any] | None = None
|
||||
self.authenticator: AuthenticatorAsync | None = None
|
||||
self.authentication: Authentication | None = None
|
||||
|
||||
@property
|
||||
def access_token(self):
|
||||
def access_token(self) -> str:
|
||||
"""Access token for the api."""
|
||||
return self.authentication.access_token
|
||||
|
||||
|
@ -98,9 +98,8 @@ class AugustGateway:
|
|||
|
||||
await self.authenticator.async_setup_authentication()
|
||||
|
||||
async def async_authenticate(self):
|
||||
async def async_authenticate(self) -> Authentication:
|
||||
"""Authenticate with the details provided to setup."""
|
||||
self.authentication = None
|
||||
try:
|
||||
self.authentication = await self.authenticator.async_authenticate()
|
||||
if self.authentication.state == AuthenticationState.AUTHENTICATED:
|
||||
|
@ -137,13 +136,13 @@ class AugustGateway:
|
|||
"""Remove the cache file."""
|
||||
await self._hass.async_add_executor_job(self._reset_authentication)
|
||||
|
||||
def _reset_authentication(self):
|
||||
def _reset_authentication(self) -> None:
|
||||
"""Remove the cache file."""
|
||||
path = self._hass.config.path(self._access_token_cache_file)
|
||||
if os.path.exists(path):
|
||||
os.unlink(path)
|
||||
|
||||
async def async_refresh_access_token_if_needed(self):
|
||||
async def async_refresh_access_token_if_needed(self) -> None:
|
||||
"""Refresh the august access token if needed."""
|
||||
if not self.authenticator.should_refresh():
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue