core: Duux Whisper Flex Ultimate fan no longer working in new Tuya integration (`fs`)

The problem

Entity for fan is “unavailable” on the new Tuya integration.

What is version of Home Assistant Core has the issue?

2021.10

What was the last working version of Home Assistant Core?

2021.9

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tuya

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tuya/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.fan
Source: components/tuya/fan.py:211 
Integration: Fan (documentation, issues) 
First occurred: 09:38:27 (2 occurrences) 
Last logged: 09:38:27

Error adding entities for domain fan with platform tuya
Error while setting up tuya platform for fan
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 587, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 682, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 456, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 491, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 620, in state_attributes
    data[ATTR_SPEED] = self.speed
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 462, in speed
    preset_mode = self.preset_mode
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 211, in preset_mode
    return self.tuya_device.status[DPCODE_MODE]
KeyError: 'mode'

Additional information

22AB3C9C-DB76-4CD3-AB37-1CDA06F1C2F4

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

@frenck this PR solves all fan speed and control issues i am aware of https://github.com/tuya/tuya-home-assistant/pull/490 except for fan direction (forward/reverse)

I’m seeing a similar issue (if not the same) with a Fanco Infinity-ID DC fan:

Logger: homeassistant.components.fan
Source: components/tuya/fan.py:165 
Integration: Fan (documentation, issues) 
First occurred: 6:49:35 PM (2 occurrences) 
Last logged: 6:49:35 PM

Error adding entities for domain fan with platform tuya
Error while setting up tuya platform for fan
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 607, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 486, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 617, in state_attributes
    data[ATTR_SPEED] = self.speed
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 461, in speed
    if self._implemented_preset_mode and (preset_mode := self.preset_mode):
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 165, in preset_mode
    return self.device.status[DPCode.MODE]
KeyError: <DPCode.MODE: 'mode'>

I tried to get the device info as posted above but couldn’t figure out how to retrieve that. If anyone could post a link or instructions I can provide more details on the device.

@frenck I was able to gather device info using the method from tuya-home-assistant github. Hope this will help. To summarize: this fan was working partially in tuya-home-assistant v1.5 (HACS), and seems to be broken in the same way as of tuya-home-assistant v1.6 (HACS) and the latest Tuya integration (in core).

{
"active_time": 1628696958,
"biz_type": 0,
"category": "fs",
"create_time": 1628696958,
"icon": "smart/icon/001441070657466AAETE/a3de89a299843127e4d716cd35e5fd4e.png",
"id": "ebbc7c0bf2c73d0e33d7xp",
"ip": "***",
"lat": "***",
"local_key": "***",
"lon": "***",
"model": "DXCF14/15",
"name": "Whisper Flex Ultimate",
"online": true,
"owner_id": "34993017",
"product_id": "cjsa4k7tqbpuyq3l",
"product_name": "",
"status": [
{
"code": "switch",
"value": false
},
{
"code": "fan_speed_percent",
"value": 1
},
{
"code": "temp",
"value": 17
}
],
"sub": false,
"time_zone": "+02:00",
"uid": "***",
"update_time": 1634031730,
"uuid": "00588b1fb206c170"
}
2021-10-16 15:02:03 DEBUG (SyncWorker_2) [tuya iot] Request: method = GET, url = https://openapi.tuyaus.com/v1.0/devices/ebbc7c0bf2c73d0e33d7xp/specifications, params = None, body = None, t = 1634389323950
2021-10-16 15:02:03 DEBUG (Thread-4) [tuya iot] _on_log: Received SUBACK
2021-10-16 15:02:03 DEBUG (Thread-4) [tuya iot] _on_subscribe: 1
2021-10-16 15:02:04 DEBUG (SyncWorker_2) [tuya iot] Response: {
"result": {
"category": "fs",
"functions": [
{
"code": "switch",
"type": "Boolean",
"values": "{}"
},
{
"code": "fan_speed_percent",
"type": "Integer",
"values": "{\"min\":\"1\",\"max\":\"30\",\"scale\":\"0\",\"step\":\"1\"}"
},
{
"code": "temp",
"type": "Integer",
"values": "{\"unit\":\"℃\",\"min\":\"17\",\"max\":\"28\",\"scale\":\"0\",\"step\":\"1\"}"
}
],
"status": [
{
"code": "switch",
"type": "Boolean",
"values": "{}"
},
{
"code": "fan_speed_percent",
"type": "Integer",
"values": "{\"min\":\"1\",\"max\":\"30\",\"scale\":\"0\",\"step\":\"1\"}"
},
{
"code": "temp",
"type": "Integer",
"values": "{\"unit\":\"℃\",\"min\":\"17\",\"max\":\"28\",\"scale\":\"0\",\"step\":\"1\"}"
}
]
},
"success": true,
"t": 1634389324061
}

This is already helpful! If can try again later, that would be great. Otherwise, we have to do it with what is available 😉