thingsboard-python-rest-client
thingsboard-python-rest-client copied to clipboard
token_login() method doesn't change the logged_in attribute and doesn't verify a token
I see 2 issues with token_login() method
- token_login() method doesn't change logged_in attrubte to true. As a result, the token won't be refreshed in run() method.
- token_login() method doesn't verify token expiration or refresh it. I would expect an exception if the token had expired (without refreshToken) or if an error happened during refresh.
def token_login(self, token, refresh_token=None):
token_json = {
"token": token,
"refreshToken": refresh_token,
}
self.__save_token(token_json)
self.__load_configuration()
def run(self):
self.stopped = False
while not self.stopped:
try:
check_time = time()
if check_time >= self.token_info["exp"] and self.logged_in:
if self.token_info["refreshToken"]:
self.refresh()
else:
logger.error("No username or password provided!")
sleep(1)
except Exception as e:
logger.exception(e)
break
except KeyboardInterrupt:
break