Преглед изворни кода

Cloud: fix errors in refactoring

Jason Rumney пре 1 година
родитељ
комит
89ec7b623c
2 измењених фајлова са 9 додато и 5 уклоњено
  1. 8 4
      custom_components/tuya_local/cloud.py
  2. 1 1
      custom_components/tuya_local/config_flow.py

+ 8 - 4
custom_components/tuya_local/cloud.py

@@ -12,10 +12,14 @@ from tuya_sharing import (
 )
 
 from .const import (
+    CONF_DEVICE_CID,
     CONF_ENDPOINT,
+    CONF_LOCAL_KEY,
     CONF_TERMINAL_ID,
     DOMAIN,
     TUYA_CLIENT_ID,
+    TUYA_RESPONSE_CODE,
+    TUYA_RESPONSE_MSG,
     TUYA_RESPONSE_QR_CODE,
     TUYA_RESPONSE_RESULT,
     TUYA_RESPONSE_SUCCESS,
@@ -67,7 +71,7 @@ class Cloud:
             TUYA_SCHEMA,
             user_code,
         )
-        if success := response.get(TUYA_RESPONSE_SUCCESS, False):
+        if response.get(TUYA_RESPONSE_SUCCESS, False):
             self.__user_code = user_code
             self.__qr_code = response[TUYA_RESPONSE_RESULT][TUYA_RESPONSE_QR_CODE]
             return self.__qr_code
@@ -103,8 +107,8 @@ class Cloud:
                 },
             }
         else:
-            self.__error_code = response.get(TUYA_RESPONSE_CODE, {})
-            self.__error_msg = response.get(TUYA_RESPONSE_MSG, "Unknown error")
+            self.__error_code = info.get(TUYA_RESPONSE_CODE, {})
+            self.__error_msg = info.get(TUYA_RESPONSE_MSG, "Unknown error")
 
         return success
 
@@ -135,7 +139,7 @@ class Cloud:
                 "id": device.id,
                 "ip": device.ip,
                 CONF_LOCAL_KEY: device.local_key
-                if hassattr(device, CONF_LOCAL_KEY)
+                if hasattr(device, CONF_LOCAL_KEY)
                 else "",
                 "name": device.name,
                 "node_id": device.node_id if hasattr(device, "node_id") else "",

+ 1 - 1
custom_components/tuya_local/config_flow.py

@@ -149,7 +149,7 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
         if not await self.cloud.async_login():
             # Try to get a new QR code on failure
             response = await self.cloud.async_get_qr_code()
-            errors["base"] = "login_error"
+            errors = {"base": "login_error"}
             placeholders = self.cloud.last_error
             if response:
                 self.__qr_code = response