xZetsubou / hass-localtuya

🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"
https://xzetsubou.github.io/hass-localtuya/
GNU General Public License v3.0
284 stars 30 forks source link

[Bug]: LocalTuya does not change fan speed #267

Open Lurker00 opened 3 weeks ago

Lurker00 commented 3 weeks ago

LocalTuya Version

2024.6.0

Home Assistant Version

2024.6.1

Environment

What happened?

I have a WiFi fan, with 3 speeds, integers as a list. When I change the speed, the log shows that percentage is correctly translated into the list value, but the speed does not change. You can see on screenshots that the speed control is medium or high, but the value remains 33%. If I change the speed from SmartLife, HA displays 66% or 100% as appropriate.

So, actually, HA/LocalTuya can only turn the fan off or on at the low speed.

Screenshots ![Снимок экрана 2024-06-08 125310](https://github.com/xZetsubou/hass-localtuya/assets/8679526/e752632e-3749-41d9-b8aa-6892bf7dce5b) ![Снимок экрана 2024-06-08 125342](https://github.com/xZetsubou/hass-localtuya/assets/8679526/3cbd9b1b-3c97-4a8a-9f5e-1a730b434072)

Steps to reproduce.

Change fan speed from HA.

Relevant log output

2024-06-08 12:46:42.790 INFO (MainThread) [custom_components.localtuya.fan] Fan async_set_percentage from list: 66 > 2
2024-06-08 12:47:09.071 INFO (MainThread) [custom_components.localtuya.fan] Fan async_set_percentage from list: 100 > 3
2024-06-08 12:49:11.351 INFO (MainThread) [custom_components.localtuya.fan] Fan async_set_percentage from list: 66 > 2
2024-06-08 12:49:28.339 INFO (MainThread) [custom_components.localtuya.fan] Fan async_set_percentage from list: 100 > 3

Diagnostics information.

localtuya-944c1616039a1d1ec6b9745179bff74e-Iot Fan Tower T1 -db41ae908ba13db49c2a0f489757fa32.json

xZetsubou commented 3 weeks ago

Re-configure the device and choose the DP Value on fan step "str" instead of "int"

Lurker00 commented 3 weeks ago

It works now! Now I see, that the device_cloud_info defines fan_speed as a string:

        "3": {
          "code": "fan_speed",
          "custom_name": "",
          "dp_id": 3,
          "time": 1717689204394,
          "value": "3",
          "type": "Enum",
          "values": "{\"type\": \"enum\", \"range\": [\"1\", \"2\", \"3\"]}",
          "id": 3,
          "accessMode": "rw"
        },

but it was mistakenly interpreted as int:

          "fan_speed_ordered_list": "1,2,3",
          "fan_dps_type": "int",
xZetsubou commented 3 weeks ago

It's not about the auto configuration, I mean I don't even understand what's the point of having the user to choose the type of the DP, As far as I saw if the speed DP is defined as "ordered list" and it always "String" and if it' defined as min/max it always "Integer"

I haven't made changes for fan but I may actually force the DP to be string type if speed defined as list, 🤔

Lurker00 commented 3 weeks ago

It's not about the auto configuration

I can't say for sure that I never touched those settings. OK, it works now and it is good! Thank you!

Not related, but while I can ask you without creating a ticket...

Is it correct that _async_reconnect stops on the first met disabled device? https://github.com/xZetsubou/hass-localtuya/blob/b0a806b72c07a3087d0f04ba8673fee17603baff/custom_components/localtuya/__init__.py#L461-L469

I have some disabled devices and now I wonder if they may prevent reconnecting to other devices.

xZetsubou commented 3 weeks ago

It does may break the reconnect process, thank you for pointing that It should be continue instead of return.