From 51c5e9c3aae0726f7255e045baf137d2416ff93b Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 18 Sep 2026 16:55:12 +0200 Subject: [PATCH] Turn off Tuya fans when the speed is set to 0% (#181972) --- homeassistant/components/tuya/fan.py | 5 +++++ tests/components/tuya/test_fan.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/homeassistant/components/tuya/fan.py b/homeassistant/components/tuya/fan.py index f979390ce2d6..d17015937332 100644 --- a/homeassistant/components/tuya/fan.py +++ b/homeassistant/components/tuya/fan.py @@ -121,6 +121,11 @@ class TuyaFanEntity(TuyaEntity, FanEntity): @override async def async_set_percentage(self, percentage: int) -> None: """Set the speed of the fan, as a percentage.""" + # The speed wrappers have no off position, 0% has to hit the switch + if percentage == 0 and self._switch_wrapper is not None: + await self.async_turn_off() + return + await self._async_send_wrapper_updates(self._speed_wrapper, percentage) @override diff --git a/tests/components/tuya/test_fan.py b/tests/components/tuya/test_fan.py index f2c15d164bf4..42c0b7b4b4c5 100644 --- a/tests/components/tuya/test_fan.py +++ b/tests/components/tuya/test_fan.py @@ -11,6 +11,7 @@ from homeassistant.components.fan import ( DOMAIN as FAN_DOMAIN, SERVICE_OSCILLATE, SERVICE_SET_DIRECTION, + SERVICE_SET_PERCENTAGE, SERVICE_SET_PRESET_MODE, SERVICE_TURN_OFF, SERVICE_TURN_ON, @@ -91,6 +92,27 @@ async def test_platform_setup_and_discovery( {"preset_mode": "sleep"}, [{"code": "switch", "value": True}, {"code": "mode", "value": "sleep"}], ), + ( + "fs_g0ewlb1vmwqljzji", + "fan.ceiling_fan_with_light", + SERVICE_SET_PERCENTAGE, + {"percentage": 50}, + [{"code": "fan_speed", "value": "3"}], + ), + ( + "fs_g0ewlb1vmwqljzji", + "fan.ceiling_fan_with_light", + SERVICE_SET_PERCENTAGE, + {"percentage": 0}, + [{"code": "switch", "value": False}], + ), + ( + "ks_j9fa8ahzac8uvlfl", + "fan.tower_fan_ca_407g_smart", + SERVICE_SET_PERCENTAGE, + {"percentage": 0}, + [{"code": "switch", "value": False}], + ), ], ) async def test_action(