diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 23261c4d944311..ec6fc1aad7e0aa 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -24,6 +24,11 @@ PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ) +from homeassistant.helpers.deprecation import ( + DeprecatedConstantEnum, + check_if_deprecated_constant, + dir_with_deprecated_constants, +) from homeassistant.helpers.entity import ToggleEntity, ToggleEntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.typing import ConfigType @@ -52,10 +57,22 @@ class FanEntityFeature(IntFlag): # These SUPPORT_* constants are deprecated as of Home Assistant 2022.5. # Please use the FanEntityFeature enum instead. -SUPPORT_SET_SPEED = 1 -SUPPORT_OSCILLATE = 2 -SUPPORT_DIRECTION = 4 -SUPPORT_PRESET_MODE = 8 +_DEPRECATED_SUPPORT_SET_SPEED = DeprecatedConstantEnum( + FanEntityFeature.SET_SPEED, "2025.1" +) +_DEPRECATED_SUPPORT_OSCILLATE = DeprecatedConstantEnum( + FanEntityFeature.OSCILLATE, "2025.1" +) +_DEPRECATED_SUPPORT_DIRECTION = DeprecatedConstantEnum( + FanEntityFeature.DIRECTION, "2025.1" +) +_DEPRECATED_SUPPORT_PRESET_MODE = DeprecatedConstantEnum( + FanEntityFeature.PRESET_MODE, "2025.1" +) + +# Both can be removed if no deprecated constant are in this module anymore +__getattr__ = ft.partial(check_if_deprecated_constant, module_globals=globals()) +__dir__ = ft.partial(dir_with_deprecated_constants, module_globals=globals()) SERVICE_INCREASE_SPEED = "increase_speed" SERVICE_DECREASE_SPEED = "decrease_speed" diff --git a/tests/components/fan/test_init.py b/tests/components/fan/test_init.py index ec421141768cd6..e6a3ab546cc6a6 100644 --- a/tests/components/fan/test_init.py +++ b/tests/components/fan/test_init.py @@ -1,6 +1,7 @@ """Tests for fan platforms.""" import pytest +from homeassistant.components import fan from homeassistant.components.fan import ( ATTR_PRESET_MODE, ATTR_PRESET_MODES, @@ -13,6 +14,7 @@ import homeassistant.helpers.entity_registry as er from homeassistant.setup import async_setup_component +from tests.common import import_and_test_deprecated_constant_enum from tests.testing_config.custom_components.test.fan import MockFan @@ -145,3 +147,12 @@ async def test_preset_mode_validation( with pytest.raises(NotValidPresetModeError) as exc: await test_fan._valid_preset_mode_or_raise("invalid") assert exc.value.translation_key == "not_valid_preset_mode" + + +@pytest.mark.parametrize(("enum"), list(fan.FanEntityFeature)) +def test_deprecated_constants( + caplog: pytest.LogCaptureFixture, + enum: fan.FanEntityFeature, +) -> None: + """Test deprecated constants.""" + import_and_test_deprecated_constant_enum(caplog, fan, enum, "SUPPORT_", "2025.1") diff --git a/tests/components/tasmota/test_fan.py b/tests/components/tasmota/test_fan.py index 05e3151be2e6fe..727fddc9bd387b 100644 --- a/tests/components/tasmota/test_fan.py +++ b/tests/components/tasmota/test_fan.py @@ -60,7 +60,7 @@ async def test_controlling_state_via_mqtt( state = hass.states.get("fan.tasmota") assert state.state == STATE_OFF assert state.attributes["percentage"] is None - assert state.attributes["supported_features"] == fan.SUPPORT_SET_SPEED + assert state.attributes["supported_features"] == fan.FanEntityFeature.SET_SPEED assert not state.attributes.get(ATTR_ASSUMED_STATE) async_fire_mqtt_message(hass, "tasmota_49A3BC/tele/STATE", '{"FanSpeed":1}')