tuya / tuya-device-sharing-sdk

Tuya Device Sharing SDK
MIT License
19 stars 6 forks source link

API Difference Causing issues w/ Home Assistant Integration #11

Open EvanSchalton opened 6 months ago

EvanSchalton commented 6 months ago

In the Tuya IOT platform console when I call the Query Devices in Home endpoint https://openapi.tuyaus.com/v1.0/homes/{home_id}/devices or the Get Device Status or Get Device Details https://openapi.tuyaus.com/v1.0/devices/{device_id}/status, https://openapi.tuyaus.com/v1.0/devices/{device_id} I get all of the fields for the device including the fields added by setting the Select Control Instruction Mode to DP Instruction instead of Standard Instruction

However, the apigw api used in the repo only returns the Standard Instructions

gautamkrishnar commented 6 months ago

Hi, I am also getting issues like the following one:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 865, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1328, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1052, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1202, in state_attributes
    data[ATTR_BRIGHTNESS] = self.brightness
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 648, in brightness
    brightness = self._brightness.remap_value_to(brightness)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 63, in remap_value_to
    return remap_value(value, self.min, self.max, to_min, to_max, reverse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/util.py", line 16, in remap_value
    return ((value - from_min) / (from_max - from_min)) * (to_max - to_min) + to_min
             ~~~~~~^~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'
2024-03-18 23:37:25.678 ERROR (MainThread) [homeassistant.components.light] Error adding entity light.bathroom_light for domain light with platform tuya
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 865, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1328, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1052, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1202, in state_attributes
    data[ATTR_BRIGHTNESS] = self.brightness
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 648, in brightness
    brightness = self._brightness.remap_value_to(brightness)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 63, in remap_value_to
    return remap_value(value, self.min, self.max, to_min, to_max, reverse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/util.py", line 16, in remap_value
    return ((value - from_min) / (from_max - from_min)) * (to_max - to_min) + to_min
             ~~~~~~^~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

This could be maybe due to this bug.

Ref: https://github.com/home-assistant/core/issues/111839

cc: @shihuimiao

sliekens commented 3 months ago

+1 for adding non-standardized data points

Many Smartlife features are currently unavailable in HA because they rely on data points outside the standard set.