tuya / tuya-home-assistant

Home Assistant integration for controlling Powered by Tuya (PBT) devices using Tuya Open API, maintained by the Home Assistant Community and Tuya Developer Team.
MIT License
875 stars 206 forks source link

Error while setting up tuya platform for fan #808

Open deskoh opened 2 years ago

deskoh commented 2 years ago

Describe the bug

The reported fan speed and fan speed enum have different data types.

See home-assistant/core#70573.

Expected behavior

A clear and concise description of what you expected to happen.

Fan speed enum from Tuya API/Cloud response should be integer:

      "fan_speed": {
        "type": "Enum",
        "value": {
          "range": [1, 2, 3, 4, 5, 6]
          // current values are strings: ["1", "2", "3", "4", "5", "6"]
        }
      },

Diagnostics for integrations and devices

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.5.2",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.9",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Asia/Singapore",
    "os_name": "Linux",
    "os_version": "5.10.103-v8",
    "supervisor": "2022.05.1",
    "host_os": "Home Assistant OS 7.6",
    "docker_version": "20.10.9",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "xiaomi_gateway3": {
      "version": "2.0.10",
      "requirements": [
        "zigpy>=0.33.0"
      ]
    }
  },
  "integration_manifest": {
    "domain": "tuya",
    "name": "Tuya",
    "documentation": "https://www.home-assistant.io/integrations/tuya",
    "requirements": [
      "tuya-iot-py-sdk==0.6.6"
    ],
    "dependencies": [
      "ffmpeg"
    ],
    "codeowners": [
      "@Tuya",
      "@zlinoliver",
      "@frenck"
    ],
    "config_flow": true,
    "iot_class": "cloud_push",
    "dhcp": [
      {
        "macaddress": "105A17*"
      },
      {
        "macaddress": "10D561*"
      },
      {
        "macaddress": "1869D8*"
      },
      {
        "macaddress": "381F8D*"
      },
      {
        "macaddress": "508A06*"
      },
      {
        "macaddress": "68572D*"
      },
      {
        "macaddress": "708976*"
      },
      {
        "macaddress": "7CF666*"
      },
      {
        "macaddress": "84E342*"
      },
      {
        "macaddress": "D4A651*"
      },
      {
        "macaddress": "D81F12*"
      }
    ],
    "loggers": [
      "tuya_iot"
    ],
    "is_built_in": true
  },
  "data": {
    "endpoint": "https://openapi.tuyaeu.com",
    "auth_type": 0,
    "country_code": "65",
    "app_type": "smartlife",
    "mqtt_connected": true,
    "disabled_by": null,
    "disabled_polling": false,
    "name": "Common Room Fan",
    "model": "FP9805_TAIDE",
    "category": "fs",
    "product_id": "g0ewlb1vmwqljzji",
    "product_name": "Ceiling Fan With Light",
    "online": true,
    "sub": false,
    "time_zone": "+08:00",
    "active_time": "2022-04-09T02:10:20+00:00",
    "create_time": "2022-04-09T02:10:20+00:00",
    "update_time": "2022-04-09T02:11:00+00:00",
    "function": {
      "switch": {
        "type": "Boolean",
        "value": {}
      },
      "mode": {
        "type": "Enum",
        "value": {
          "range": [
            "normal",
            "sleep",
            "nature"
          ]
        }
      },
      "fan_speed": {
        "type": "Enum",
        "value": {
          "range": [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6"
          ]
        }
      },
      "fan_direction": {
        "type": "Enum",
        "value": {
          "range": [
            "forward",
            "reverse"
          ]
        }
      },
      "light": {
        "type": "Boolean",
        "value": {}
      },
      "bright_value": {
        "type": "Integer",
        "value": {
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "temp_value": {
        "type": "Integer",
        "value": {
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "countdown_set": {
        "type": "Enum",
        "value": {
          "range": [
            "cancel",
            "1h",
            "2h",
            "4h",
            "8h"
          ]
        }
      }
    },
    "status_range": {
      "switch": {
        "type": "Boolean",
        "value": {}
      },
      "mode": {
        "type": "Enum",
        "value": {
          "range": [
            "normal",
            "sleep",
            "nature"
          ]
        }
      },
      "fan_speed": {
        "type": "Enum",
        "value": {
          "range": [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6"
          ]
        }
      },
      "fan_direction": {
        "type": "Enum",
        "value": {
          "range": [
            "forward",
            "reverse"
          ]
        }
      },
      "light": {
        "type": "Boolean",
        "value": {}
      },
      "bright_value": {
        "type": "Integer",
        "value": {
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "temp_value": {
        "type": "Integer",
        "value": {
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "countdown_set": {
        "type": "Enum",
        "value": {
          "range": [
            "cancel",
            "1h",
            "2h",
            "4h",
            "8h"
          ]
        }
      }
    },
    "status": {
      "switch": false,
      "mode": "normal",
      "fan_speed": 2,
      "fan_direction": "forward",
      "light": false,
      "bright_value": 28,
      "temp_value": 50,
      "countdown_set": "off"
    },
    "home_assistant": {
      "name": "Common Room Fan",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "original_icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "light.common_room_fan",
            "state": "off",
            "attributes": {
              "min_mireds": 153,
              "max_mireds": 500,
              "supported_color_modes": [
                "brightness",
                "color_temp"
              ],
              "friendly_name": "Common Room Fan",
              "supported_features": 0
            },
            "last_changed": "2022-05-08T09:31:23.607331+00:00",
            "last_updated": "2022-05-08T09:31:23.607331+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": "tuya__countdown",
          "icon": null,
          "original_icon": "mdi:timer-cog-outline",
          "unit_of_measurement": null,
          "state": {
            "entity_id": "select.common_room_fan_countdown",
            "state": "unknown",
            "attributes": {
              "options": [
                "cancel",
                "1h",
                "2h",
                "4h",
                "8h"
              ],
              "device_class": "tuya__countdown",
              "icon": "mdi:timer-cog-outline",
              "friendly_name": "Common Room Fan Countdown"
            },
            "last_changed": "2022-05-08T09:31:23.608748+00:00",
            "last_updated": "2022-05-08T09:31:23.608748+00:00"
          }
        },
        {
          "disabled": true,
          "disabled_by": "user",
          "entity_category": null,
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "original_icon": null,
          "unit_of_measurement": null,
          "state": null
        }
      ]
    }
  }
}
almighty059 commented 2 years ago

I have this same error for my Tuya lights...

2022-05-15 07:37:54 ERROR (MainThread) [homeassistant.components.light] Error while setting up tuya platform for light Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform await asyncio.shield(task) File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 382, in async_setup_entry async_discover_device([*hass_data.device_manager.device_map]) File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 375, in async_discover_device TuyaLightEntity( File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 450, in __init__ h_type=IntegerTypeData(dpcode, **function_data["h"]), KeyError: 'h'

userosos commented 11 months ago

I have too the error. Error while setting up tuya platform for fan

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 367, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1057, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state
    state, attr = self._async_generate_attributes()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 822, in _async_generate_attributes
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 357, in state_attributes
    data[ATTR_PERCENTAGE] = self.percentage
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage
    return ordered_list_item_to_percentage(self._speeds.range, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 25, in ordered_list_item_to_percentage
    raise ValueError(f'The item "{item}" is not in "{ordered_list}"')
ValueError: The item "silent" is not in "['low', 'high']"
chpeck commented 2 months ago

FWIW is submitted a ticket with tuya developer platform.

https://service.console.tuya.com/8/3/detail?id=T202407190203

almighty059 commented 2 months ago

I switched to the below version of Local Tuya and everything is now working. It seems to be a more recent and up-to-date maintained version.

https://github.com/xZetsubou/hass-localtuya