Skip to content

Commit

Permalink
[update] log in refresh token logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutsuku committed Oct 25, 2021
1 parent 56816b2 commit ed2cb0c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
2 changes: 0 additions & 2 deletions tuya_iot/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,6 @@ def get_device_stream_allocate(
return response["result"]["url"]
return None

def get_device_statistics_

def send_commands(
self, device_id: str, commands: list[dict[str, Any]]
) -> dict[str, Any]:
Expand Down
15 changes: 3 additions & 12 deletions tuya_iot/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

TUYA_ERROR_CODE_TOKEN_INVALID = 1010

TO_C_REFRESH_TOKEN_API = "/v1.0/iot-03/users/token/{}"
TO_C_REFRESH_TOKEN_API_PRE = "/v1.0/iot-03/users/token/"

TO_C_CUSTOM_TOKEN_API = "/v1.0/iot-03/users/login"
TO_C_SMART_HOME_TOKEN_API = "/v1.0/iot-01/associated-users/actions/authorized-login"
Expand Down Expand Up @@ -155,7 +155,7 @@ def __refresh_access_token_if_need(self, path: str):

self.token_info.access_token = ""
response = self.post(
TO_C_REFRESH_TOKEN_API.format(self.token_info.refresh_token)
TO_C_REFRESH_TOKEN_API_PRE + self.token_info.refresh_token
)

self.token_info = TuyaTokenInfo(response)
Expand Down Expand Up @@ -241,20 +241,11 @@ def __request(
"lang": self.lang,
}

if self.__login_path == path == path:
if path == self.__login_path or path.startswith(TO_C_REFRESH_TOKEN_API_PRE):
headers["dev_lang"] = "python"
headers["dev_version"] = VERSION
headers["dev_channel"] = self.dev_channel

if self.token_info is not None:
refresh_token_api = TO_C_REFRESH_TOKEN_API.format(
self.token_info.refresh_token
)
if refresh_token_api == path:
headers["dev_lang"] = "python"
headers["dev_version"] = VERSION
headers["dev_channel"] = self.dev_channel

logger.debug(
f"Request: method = {method}, \
url = {self.endpoint + path},\
Expand Down

0 comments on commit ed2cb0c

Please sign in to comment.