diff --git a/homeassistant/components/water_heater/__init__.py b/homeassistant/components/water_heater/__init__.py index 6506be10065..c780407af7c 100644 --- a/homeassistant/components/water_heater/__init__.py +++ b/homeassistant/components/water_heater/__init__.py @@ -28,6 +28,11 @@ from homeassistant.helpers.config_validation import ( # noqa: F401 PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ) +from homeassistant.helpers.deprecation import ( + DeprecatedConstantEnum, + check_if_deprecated_constant, + dir_with_deprecated_constants, +) from homeassistant.helpers.entity import Entity, EntityDescription from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.temperature import display_temp as show_temp @@ -65,9 +70,19 @@ class WaterHeaterEntityFeature(IntFlag): # These SUPPORT_* constants are deprecated as of Home Assistant 2022.5. # Please use the WaterHeaterEntityFeature enum instead. -SUPPORT_TARGET_TEMPERATURE = 1 -SUPPORT_OPERATION_MODE = 2 -SUPPORT_AWAY_MODE = 4 +_DEPRECATED_SUPPORT_TARGET_TEMPERATURE = DeprecatedConstantEnum( + WaterHeaterEntityFeature.TARGET_TEMPERATURE, "2025.1" +) +_DEPRECATED_SUPPORT_OPERATION_MODE = DeprecatedConstantEnum( + WaterHeaterEntityFeature.OPERATION_MODE, "2025.1" +) +_DEPRECATED_SUPPORT_AWAY_MODE = DeprecatedConstantEnum( + WaterHeaterEntityFeature.AWAY_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()) ATTR_MAX_TEMP = "max_temp" ATTR_MIN_TEMP = "min_temp" diff --git a/tests/components/water_heater/test_init.py b/tests/components/water_heater/test_init.py index bc996ab6fa4..8a7d76bd891 100644 --- a/tests/components/water_heater/test_init.py +++ b/tests/components/water_heater/test_init.py @@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock import pytest import voluptuous as vol +from homeassistant.components import water_heater from homeassistant.components.water_heater import ( SET_TEMPERATURE_SCHEMA, WaterHeaterEntity, @@ -13,7 +14,7 @@ from homeassistant.components.water_heater import ( ) from homeassistant.core import HomeAssistant -from tests.common import async_mock_service +from tests.common import async_mock_service, import_and_test_deprecated_constant_enum async def test_set_temp_schema_no_req( @@ -96,3 +97,21 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None: await water_heater.async_turn_off() assert water_heater.async_turn_off.call_count == 1 + + +@pytest.mark.parametrize( + ("enum"), + [ + WaterHeaterEntityFeature.TARGET_TEMPERATURE, + WaterHeaterEntityFeature.OPERATION_MODE, + WaterHeaterEntityFeature.AWAY_MODE, + ], +) +def test_deprecated_constants( + caplog: pytest.LogCaptureFixture, + enum: WaterHeaterEntityFeature, +) -> None: + """Test deprecated constants.""" + import_and_test_deprecated_constant_enum( + caplog, water_heater, enum, "SUPPORT_", "2025.1" + )