Fix access token property (#673)

* Fix access token property

* revert
This commit is contained in:
Pascal Vizeli 2018-08-28 17:04:39 +02:00 committed by GitHub
parent aac4b9b24a
commit 051b63c7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,7 +47,7 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
self._error_state = False
# We don't persist access tokens. Instead we fetch new ones when needed
self.access_token = None
self.access_token_expires = None
self._access_token_expires = None
async def load(self):
"""Prepare HomeAssistant object."""
@ -355,7 +355,7 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
async def ensure_access_token(self):
"""Ensures there is an access token."""
if (self.access_token is not None and
self.access_token_expires < datetime.utcnow()):
self._access_token_expires > datetime.utcnow()):
return
with suppress(asyncio.TimeoutError, aiohttp.ClientError):
@ -374,7 +374,7 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
_LOGGER.info("Updated HomeAssistant API token")
tokens = await resp.json()
self.access_token = tokens['access_token']
self.access_token_expires = \
self._access_token_expires = \
datetime.utcnow() + timedelta(seconds=tokens['expires_in'])
@asynccontextmanager