Deprecate deprecated water_heater constants (#106226)

This commit is contained in:
Robert Resch 2023-12-22 11:23:03 +01:00 committed by GitHub
parent e18d2b8873
commit 06220849fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -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"

View File

@ -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"
)