From fd70d008ba4221d424f0a0e51c45b2e5dfaad7ee Mon Sep 17 00:00:00 2001 From: AIMAA Date: Thu, 5 Mar 2026 10:25:23 +1000 Subject: [PATCH] fix: speed_count crashes when using fan_speed_ordered_list When a fan entity is configured with `fan_speed_ordered_list`, the `_speed_range` tuple is `(None, None)`. Calling `int_states_in_range` on this raises a TypeError, making the fan entity unavailable. Fix: check `_use_ordered_list` first and return `len(self._ordered_list)` instead, consistent with how the rest of the class handles the two modes. --- custom_components/localtuya/fan.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/custom_components/localtuya/fan.py b/custom_components/localtuya/fan.py index 59c33acf0..c8375f9d3 100644 --- a/custom_components/localtuya/fan.py +++ b/custom_components/localtuya/fan.py @@ -208,6 +208,8 @@ def supported_features(self) -> FanEntityFeature: @property def speed_count(self) -> int: """Speed count for the fan.""" + if self._use_ordered_list: + return len(self._ordered_list) speed_count = int_states_in_range(self._speed_range) _LOGGER.debug("Fan speed_count: %s", speed_count) return speed_count