Skip to content

Commit

Permalink
Deprecate deprecated fan constants (home-assistant#106111)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Dec 20, 2023
1 parent 2403b21 commit c9c072f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
25 changes: 21 additions & 4 deletions homeassistant/components/fan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions tests/components/fan/test_init.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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


Expand Down Expand Up @@ -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")
2 changes: 1 addition & 1 deletion tests/components/tasmota/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down

0 comments on commit c9c072f

Please sign in to comment.