From ed2cb0c0cd81cb71897f0ac29efda5001cd33078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=BE=E5=90=AF?= <18442047+tsutsuku@users.noreply.github.com> Date: Mon, 25 Oct 2021 11:11:07 +0800 Subject: [PATCH] [update] log in refresh token logic --- tuya_iot/device.py | 2 -- tuya_iot/openapi.py | 15 +++------------ 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/tuya_iot/device.py b/tuya_iot/device.py index 352fdba..74d193c 100644 --- a/tuya_iot/device.py +++ b/tuya_iot/device.py @@ -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]: diff --git a/tuya_iot/openapi.py b/tuya_iot/openapi.py index 7ba48d2..493f593 100644 --- a/tuya_iot/openapi.py +++ b/tuya_iot/openapi.py @@ -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" @@ -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) @@ -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},\