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.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ServiceValidationError from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import config_validation as cv 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 import Entity, EntityDescription
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.temperature import display_temp as show_temp 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.""" """A class that describes water heater entities."""
@deprecated_class("WaterHeaterEntityDescription", breaks_in_ha_version="2026.1") _DEPRECATED_WaterHeaterEntityEntityDescription = DeprecatedConstant(
class WaterHeaterEntityEntityDescription( WaterHeaterEntityDescription,
WaterHeaterEntityDescription, frozen_or_thawed=True "WaterHeaterEntityDescription",
): breaks_in_ha_version="2026.1",
"""A (deprecated) class that describes water heater entities.""" )
CACHED_PROPERTIES_WITH_ATTR_ = { CACHED_PROPERTIES_WITH_ATTR_ = {
@ -414,3 +419,11 @@ async def async_service_temperature_set(
kwargs[value] = temp kwargs[value] = temp
await entity.async_set_temperature(**kwargs) 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 __future__ import annotations
from typing import Any
from unittest import mock from unittest import mock
from unittest.mock import AsyncMock, MagicMock from unittest.mock import AsyncMock, MagicMock
import pytest import pytest
import voluptuous as vol import voluptuous as vol
from homeassistant.components import water_heater
from homeassistant.components.water_heater import ( from homeassistant.components.water_heater import (
DOMAIN, DOMAIN,
SERVICE_SET_OPERATION_MODE, SERVICE_SET_OPERATION_MODE,
SET_TEMPERATURE_SCHEMA, SET_TEMPERATURE_SCHEMA,
WaterHeaterEntity, WaterHeaterEntity,
WaterHeaterEntityDescription, WaterHeaterEntityDescription,
WaterHeaterEntityEntityDescription,
WaterHeaterEntityFeature, WaterHeaterEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -29,6 +30,7 @@ from tests.common import (
MockModule, MockModule,
MockPlatform, MockPlatform,
async_mock_service, async_mock_service,
import_and_test_deprecated_constant,
mock_integration, mock_integration,
mock_platform, mock_platform,
) )
@ -209,12 +211,27 @@ async def test_operation_mode_validation(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("class_name", "expected_log"), ("constant_name", "replacement_name", "replacement"),
[(WaterHeaterEntityDescription, False), (WaterHeaterEntityEntityDescription, True)], [
(
"WaterHeaterEntityEntityDescription",
"WaterHeaterEntityDescription",
WaterHeaterEntityDescription,
),
],
) )
async def test_deprecated_entity_description( def test_deprecated_constants(
caplog: pytest.LogCaptureFixture, class_name: type, expected_log: bool caplog: pytest.LogCaptureFixture,
constant_name: str,
replacement_name: str,
replacement: Any,
) -> None: ) -> None:
"""Test deprecated WaterHeaterEntityEntityDescription logs warning.""" """Test deprecated automation constants."""
class_name(key="test") import_and_test_deprecated_constant(
assert ("is a deprecated class" in caplog.text) is expected_log caplog,
water_heater,
constant_name,
replacement_name,
replacement,
"2026.1",
)