Adjust deprecation in water heater (#136577)

This commit is contained in:
epenet 2025-01-29 16:15:20 +01:00 committed by GitHub
parent 653ff47171
commit 83b34c6faf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 14 deletions

View File

@ -25,7 +25,12 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.deprecation import deprecated_class
from homeassistant.helpers.deprecation import (
DeprecatedConstant,
all_with_deprecated_constants,
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
@ -134,11 +139,11 @@ class WaterHeaterEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes water heater entities."""
@deprecated_class("WaterHeaterEntityDescription", breaks_in_ha_version="2026.1")
class WaterHeaterEntityEntityDescription(
WaterHeaterEntityDescription, frozen_or_thawed=True
):
"""A (deprecated) class that describes water heater entities."""
_DEPRECATED_WaterHeaterEntityEntityDescription = DeprecatedConstant(
WaterHeaterEntityDescription,
"WaterHeaterEntityDescription",
breaks_in_ha_version="2026.1",
)
CACHED_PROPERTIES_WITH_ATTR_ = {
@ -414,3 +419,11 @@ async def async_service_temperature_set(
kwargs[value] = temp
await entity.async_set_temperature(**kwargs)
# These 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_keys=[*globals().keys()]
)
__all__ = all_with_deprecated_constants(globals())

View File

@ -2,19 +2,20 @@
from __future__ import annotations
from typing import Any
from unittest import mock
from unittest.mock import AsyncMock, MagicMock
import pytest
import voluptuous as vol
from homeassistant.components import water_heater
from homeassistant.components.water_heater import (
DOMAIN,
SERVICE_SET_OPERATION_MODE,
SET_TEMPERATURE_SCHEMA,
WaterHeaterEntity,
WaterHeaterEntityDescription,
WaterHeaterEntityEntityDescription,
WaterHeaterEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
@ -29,6 +30,7 @@ from tests.common import (
MockModule,
MockPlatform,
async_mock_service,
import_and_test_deprecated_constant,
mock_integration,
mock_platform,
)
@ -209,12 +211,27 @@ async def test_operation_mode_validation(
@pytest.mark.parametrize(
("class_name", "expected_log"),
[(WaterHeaterEntityDescription, False), (WaterHeaterEntityEntityDescription, True)],
("constant_name", "replacement_name", "replacement"),
[
(
"WaterHeaterEntityEntityDescription",
"WaterHeaterEntityDescription",
WaterHeaterEntityDescription,
),
],
)
async def test_deprecated_entity_description(
caplog: pytest.LogCaptureFixture, class_name: type, expected_log: bool
def test_deprecated_constants(
caplog: pytest.LogCaptureFixture,
constant_name: str,
replacement_name: str,
replacement: Any,
) -> None:
"""Test deprecated WaterHeaterEntityEntityDescription logs warning."""
class_name(key="test")
assert ("is a deprecated class" in caplog.text) is expected_log
"""Test deprecated automation constants."""
import_and_test_deprecated_constant(
caplog,
water_heater,
constant_name,
replacement_name,
replacement,
"2026.1",
)