Просмотр исходного кода

Cloud: revert implementation to QueryThingsDataModel

As the result is the same with both functions, revert to the preferred
one for future reference, and disable the logging code that
unsuccessfully tried to use it.

- device: add an asyncio.sleep to the async generator so that it is
async on every iteration.

Issue #2419
Jason Rumney 1 год назад
Родитель
Сommit
9302cd5d46

+ 6 - 2
custom_components/tuya_local/cloud.py

@@ -1,3 +1,4 @@
+import json
 import logging
 from typing import Any
 
@@ -181,9 +182,12 @@ class Cloud:
         )
         response = await self.__hass.async_add_executor_job(
             manager.customer_api.get,
-            # f"/v2.0/cloud/things/{device_id}/model",
-            f"/v1.0/iot-03/devices/{device_id}/specification",
+            f"/v2.0/cloud/things/{device_id}/model",
         )
+        if response.get("result"):
+            response = response["result"]
+        if response.get("model"):
+            return json.loads(response["model"])
         return response
 
     @property

+ 12 - 14
custom_components/tuya_local/config_flow.py

@@ -376,20 +376,18 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
                 self.__cloud_device["product_name"],
                 self.__cloud_device["product_id"],
             )
-            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)
+            # try:
+            #     self.init_cloud()
+            #     model = await self.cloud.async_get_datamodel(
+            #         self.__cloud_device["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,

+ 1 - 0
custom_components/tuya_local/device.py

@@ -373,6 +373,7 @@ class TuyaLocalDevice(object):
             cached_state,
         )
         for match in possible:
+            await asyncio.sleep(0)
             yield match
 
     async def async_inferred_type(self):