소스 검색

cloud: use older device specification API call

Since the QueryThingsDataModel API is not working with the QR auth,
try the GetDeviceSpecificationAndAttribute API call instead.

This gives the most important info, but sometimes does not match
the local protocol where enum values differ between cloud and local
representation, and is often missing some diagnostic dps.

Issue #2419
Jason Rumney 1 년 전
부모
커밋
23487ecc0e
2개의 변경된 파일15개의 추가작업 그리고 9개의 파일을 삭제
  1. 2 1
      custom_components/tuya_local/cloud.py
  2. 13 8
      custom_components/tuya_local/config_flow.py

+ 2 - 1
custom_components/tuya_local/cloud.py

@@ -181,7 +181,8 @@ class Cloud:
         )
         response = await self.__hass.async_add_executor_job(
             manager.customer_api.get,
-            f"/v2.0/cloud/thing/{device_id}/model",
+            # f"/v2.0/cloud/things/{device_id}/model",
+            f"/v1.0/iot-03/devices/{device_id}/specification",
         )
         return response
 

+ 13 - 8
custom_components/tuya_local/config_flow.py

@@ -376,15 +376,20 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
                 self.__cloud_device["product_name"],
                 self.__cloud_device["product_id"],
             )
-            self.init_cloud()
-            response = await self.cloud.async_get_datamodel(self.__cloud_device["id"])
-            if response and response["result"] and response["result"]["model"]:
-                model = json.loads(response["result"]["model"])
-
-                _LOGGER.warning(
-                    "QueryThingsDataModel result:\n%s",
-                    json.dumps(model, indent=4),
+            try:
+                self.init_cloud()
+                response = await self.cloud.async_get_datamodel(
+                    self.__cloud_device["id"]
                 )
+                if response and response["result"]:
+                    model = response["result"]
+
+                    _LOGGER.warning(
+                        "Device specficication:\n%s",
+                        json.dumps(model, indent=4),
+                    )
+            except Exception as e:
+                _LOGGER.warning("Unable to fetch data model from cloud: %s", e)
         _LOGGER.warning(
             "Device matches %s with quality of %d%%. DPS: %s",
             best_matching_type,