Skip to content

Commit

Permalink
cloud: use older device specification API call
Browse files Browse the repository at this point in the history
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
  • Loading branch information
make-all committed Oct 21, 2024
1 parent 4c06b74 commit 23487ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion custom_components/tuya_local/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ async def async_get_datamodel(self, device_id) -> dict[str, Any] | None:
)
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

Expand Down
21 changes: 13 additions & 8 deletions custom_components/tuya_local/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,20 @@ async def async_step_select_type(self, user_input=None):
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,
Expand Down

0 comments on commit 23487ec

Please sign in to comment.