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
871 stars 206 forks source link

Air conditioner not appearing in Home Assistant / `mode` command broken #168

Open matthid opened 3 years ago

matthid commented 3 years ago

Device normal info

Device info (please complete the following information, which can be found in log):

{
  "result": {
    "active_time": 1626602385,
    "biz_type": 18,
    "category": "kt",
    "create_time": 1625516593,
    "icon": "smart/product_icon/kt.png",
    "id": "24720770500291cec414",
    "ip": "REDACTED",
    "lat": "REDACTED",
    "local_key": "REDACTED",
    "lon": "REDACTED",
    "name": "Sichler AC",
    "online": true,
    "owner_id": "33706083",
    "product_id": "3Zf6iQv6aEBLh7Ia",
    "product_name": "Smart Portable AC",
    "status": [
      {
        "code": "switch",
        "value": true
      },
      {
        "code": "temp_set",
        "value": 19
      },
      {
        "code": "temp_current",
        "value": 24
      },
      {
        "code": "mode",
        "value": "clod"
      },
      {
        "code": "windspeed",
        "value": "1"
      },
      {
        "code": "c_f",
        "value": "C"
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "eu1625649613268rAHZs",
    "update_time": 1626613899,
    "uuid": "24720770500291cec414"
  },
  "success": true,
  "t": REDACTED
}

Device specifications (please complete the following information, which can be found in log):

{
  "result": {
    "category": "kt",
    "functions": [
      {
        "code": "windspeed",
        "type": "Enum",
        "values": "{\"range\":[\"1\",\"2\",\"3\"]}"
      },
      {
        "code": "c_f",
        "type": "Enum",
        "values": "{\"range\":[\"C\",\"F\"]}"
      },
      {
        "code": "switch",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "mode",
        "type": "Enum",
        "values": "{\"range\":[\"auto\",\"cold\",\"hot\",\"wet\",\"wind\",\"eco\"]}"
      },
      {
        "code": "temp_set",
        "type": "Integer",
        "values": "{\"min\":16,\"unit\":\"℃\",\"scale\":0,\"max\":86,\"step\":1}"
      }
    ],
    "status": [
      {
        "code": "switch",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "c_f",
        "type": "Enum",
        "values": "{\"range\":[\"C\",\"F\"]}"
      },
      {
        "code": "windspeed",
        "type": "Enum",
        "values": "{\"range\":[\"1\",\"2\",\"3\"]}"
      },
      {
        "code": "mode",
        "type": "Enum",
        "values": "{\"range\":[\"auto\",\"cold\",\"hot\",\"wet\",\"wind\",\"eco\"]}"
      },
      {
        "code": "temp_set",
        "type": "Integer",
        "values": "{\"min\":16,\"unit\":\"℃\",\"scale\":0,\"max\":86,\"step\":1}"
      },
      {
        "code": "temp_current",
        "type": "Integer",
        "values": "{\"min\":-7,\"scale\":0,\"unit\":\"℃\",\"max\":98,\"step\":1}"
      }
    ]
  },
  "success": true,
  "t": REDACTED
}

Additional debugging info

It seems like the code cannot handle the status the device is sending, as the log shows:

2021-07-18 18:23:56 DEBUG (MainThread) [custom_components.tuya_v2.climate] hvac_modes->['auto', 'cold', 'hot', 'wet', 'wind', 'eco']
2021-07-18 18:23:56 ERROR (MainThread) [homeassistant.components.climate] Error adding entities for domain climate with platform tuya_v2
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 666, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 419, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 453, in _async_write_ha_state
state = self._stringify_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 425, in _stringify_state
state = self.state
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 203, in state
return self.hvac_mode
File "/config/custom_components/tuya_v2/climate.py", line 311, in hvac_mode
return TUYA_HVAC_TO_HA[self.tuya_device.status.get(DPCODE_MODE)]
KeyError: 'clod'

2021-07-18 18:24:06 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 406, in async_update_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 453, in _async_write_ha_state
state = self._stringify_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 425, in _stringify_state
state = self.state
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 203, in state
return self.hvac_mode
File "/config/custom_components/tuya_v2/climate.py", line 311, in hvac_mode
return TUYA_HVAC_TO_HA[self.tuya_device.status.get(DPCODE_MODE)]
KeyError: 'clod'

I tried around with the Python SDK, and it seems like most commands work as expected but the mode-code is a bit broken. The device supports 4 modes (cool, fan, dry, heat), and the API behaves like this:

Note the device works perfectly fine in the Smart Life-App (including reading and writing of all modes)

tsutsuku commented 3 years ago

@matthid Your device is standardized, try again.

matthid commented 3 years ago

@tsutsuku thanks for the fast feedback, at least it doesn't crash anymore and I can see it in Home Assistant, but the mode is still broken: When trying to set the mode via Home Assistant the following happens: heat -> cool cool -> cool dry -> fan auto -> does nothing fan only -> does nothing

When setting the mode on the device, Home Assistant shows the following: Cool -> cool Fan -> shows "dry" Dry -> no changes (whatever home assistant has shown previously) Heat -> no changes (whatever home assistant has shown previously)

Which I believe matches what I have reported initially.