Sfoglia il codice sorgente

config_flow: log limited dps info when adding devices.

This uses an old API call that does not return all the dps, but it is
better than nothing. Now we can get some dps in the log which will
hopefully help with the lower quality device requests received lately
(though the biggest problem is not including log messages, so
probably not).

On the downside, it may disuade users from looking up and including
the full Query Things Data Model info.
Jason Rumney 1 anno fa
parent
commit
c0e9a87645

+ 13 - 4
custom_components/tuya_local/cloud.py

@@ -185,13 +185,22 @@ class Cloud:
         )
         response = await self.__hass.async_add_executor_job(
             manager.customer_api.get,
-            f"/v2.0/cloud/things/{device_id}/model",
+            manager.customer_api,
+            f"/v1.0/m/life/devices/{device_id}/status",
         )
         if response.get("result"):
             response = response["result"]
-        if response.get("model"):
-            return json.loads(response["model"])
-        return response
+        transform = []
+        for entry in response.get("dpStatusRelationDTOS"):
+            if entry["supportLocal"]:
+                transform += {
+                    "id": entry["dpId"],
+                    "name": entry["dpCode"],
+                    "type": entry["valueType"],
+                    "format": entry["valueDesc"],
+                    "enumMap": entry["enumMappingMap"],
+                }
+        return transform
 
     @property
     def is_authenticated(self) -> bool:

+ 12 - 12
custom_components/tuya_local/config_flow.py

@@ -406,18 +406,18 @@ class ConfigFlowHandler(ConfigFlow, domain=DOMAIN):
                     "Local product id differs from cloud: %s",
                     self.__cloud_device.get("local_product_id"),
                 )
-            # try:
-            #     self.init_cloud()
-            #     model = await self.cloud.async_get_datamodel(
-            #         self.__cloud_device.get("id"),
-            #     )
-            #     if model:
-            #         _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)
+            try:
+                self.init_cloud()
+                model = await self.cloud.async_get_datamodel(
+                    self.__cloud_device.get("id"),
+                )
+                if model:
+                    _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,