Skip to content

Commit

Permalink
refactor: add additional debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jan 24, 2020
1 parent 948b438 commit b7750d7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion teslajsonpy/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(
self.generate_oauth(email, password, refresh_token)
if access_token:
self.__sethead(access_token)
_LOGGER.debug("Connecting with existing access token")

def generate_oauth(
self, email: Text = None, password: Text = None, refresh_token: Text = None
Expand Down Expand Up @@ -79,7 +80,7 @@ def generate_oauth(
self.oauth["refresh_token"] = refresh_token
else:
raise IncompleteCredentials(
"Connection requires email and password or access and refresh token."
"Connection requires email and password or refresh token to authenticate."
)

async def get(self, command):
Expand All @@ -90,6 +91,9 @@ async def post(self, command, method="post", data=None):
"""Post data to API."""
now = calendar.timegm(datetime.datetime.now().timetuple())
if now > self.expiration:
_LOGGER.debug(
"Requesting new oauth token using %s", self.oauth["grant_type"]
)
auth = await self.__open("/oauth/token", "post", data=self.oauth)
self.__sethead(auth["access_token"], auth["expires_in"])
self.refresh_token = auth["refresh_token"]
Expand Down

0 comments on commit b7750d7

Please sign in to comment.