mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Remove deprecated climate constants (#131798)
* Remove deprecated climate constants * Fix * Fix * Fix --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
a68cf21179
commit
5c8fb5ec2c
@ -26,11 +26,6 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers import config_validation as cv, issue_registry as ir
|
from homeassistant.helpers import config_validation as cv, issue_registry as ir
|
||||||
from homeassistant.helpers.deprecation import (
|
|
||||||
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.entity_platform import EntityPlatform
|
from homeassistant.helpers.entity_platform import EntityPlatform
|
||||||
@ -41,20 +36,6 @@ from homeassistant.util.hass_dict import HassKey
|
|||||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||||
|
|
||||||
from .const import ( # noqa: F401
|
from .const import ( # noqa: F401
|
||||||
_DEPRECATED_HVAC_MODE_AUTO,
|
|
||||||
_DEPRECATED_HVAC_MODE_COOL,
|
|
||||||
_DEPRECATED_HVAC_MODE_DRY,
|
|
||||||
_DEPRECATED_HVAC_MODE_FAN_ONLY,
|
|
||||||
_DEPRECATED_HVAC_MODE_HEAT,
|
|
||||||
_DEPRECATED_HVAC_MODE_HEAT_COOL,
|
|
||||||
_DEPRECATED_HVAC_MODE_OFF,
|
|
||||||
_DEPRECATED_SUPPORT_AUX_HEAT,
|
|
||||||
_DEPRECATED_SUPPORT_FAN_MODE,
|
|
||||||
_DEPRECATED_SUPPORT_PRESET_MODE,
|
|
||||||
_DEPRECATED_SUPPORT_SWING_MODE,
|
|
||||||
_DEPRECATED_SUPPORT_TARGET_HUMIDITY,
|
|
||||||
_DEPRECATED_SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
_DEPRECATED_SUPPORT_TARGET_TEMPERATURE_RANGE,
|
|
||||||
ATTR_AUX_HEAT,
|
ATTR_AUX_HEAT,
|
||||||
ATTR_CURRENT_HUMIDITY,
|
ATTR_CURRENT_HUMIDITY,
|
||||||
ATTR_CURRENT_TEMPERATURE,
|
ATTR_CURRENT_TEMPERATURE,
|
||||||
@ -1082,13 +1063,3 @@ async def async_service_temperature_set(
|
|||||||
kwargs[value] = temp
|
kwargs[value] = temp
|
||||||
|
|
||||||
await entity.async_set_temperature(**kwargs)
|
await entity.async_set_temperature(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
# As we import deprecated constants from the const module, we need to add these two functions
|
|
||||||
# otherwise this module will be logged for using deprecated constants and not the custom component
|
|
||||||
# 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())
|
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
"""Provides the constants needed for component."""
|
"""Provides the constants needed for component."""
|
||||||
|
|
||||||
from enum import IntFlag, StrEnum
|
from enum import IntFlag, StrEnum
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
from homeassistant.helpers.deprecation import (
|
|
||||||
DeprecatedConstantEnum,
|
|
||||||
all_with_deprecated_constants,
|
|
||||||
check_if_deprecated_constant,
|
|
||||||
dir_with_deprecated_constants,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class HVACMode(StrEnum):
|
class HVACMode(StrEnum):
|
||||||
@ -37,15 +29,6 @@ class HVACMode(StrEnum):
|
|||||||
FAN_ONLY = "fan_only"
|
FAN_ONLY = "fan_only"
|
||||||
|
|
||||||
|
|
||||||
# These HVAC_MODE_* constants are deprecated as of Home Assistant 2022.5.
|
|
||||||
# Please use the HVACMode enum instead.
|
|
||||||
_DEPRECATED_HVAC_MODE_OFF = DeprecatedConstantEnum(HVACMode.OFF, "2025.1")
|
|
||||||
_DEPRECATED_HVAC_MODE_HEAT = DeprecatedConstantEnum(HVACMode.HEAT, "2025.1")
|
|
||||||
_DEPRECATED_HVAC_MODE_COOL = DeprecatedConstantEnum(HVACMode.COOL, "2025.1")
|
|
||||||
_DEPRECATED_HVAC_MODE_HEAT_COOL = DeprecatedConstantEnum(HVACMode.HEAT_COOL, "2025.1")
|
|
||||||
_DEPRECATED_HVAC_MODE_AUTO = DeprecatedConstantEnum(HVACMode.AUTO, "2025.1")
|
|
||||||
_DEPRECATED_HVAC_MODE_DRY = DeprecatedConstantEnum(HVACMode.DRY, "2025.1")
|
|
||||||
_DEPRECATED_HVAC_MODE_FAN_ONLY = DeprecatedConstantEnum(HVACMode.FAN_ONLY, "2025.1")
|
|
||||||
HVAC_MODES = [cls.value for cls in HVACMode]
|
HVAC_MODES = [cls.value for cls in HVACMode]
|
||||||
|
|
||||||
# No preset is active
|
# No preset is active
|
||||||
@ -110,14 +93,6 @@ class HVACAction(StrEnum):
|
|||||||
PREHEATING = "preheating"
|
PREHEATING = "preheating"
|
||||||
|
|
||||||
|
|
||||||
# These CURRENT_HVAC_* constants are deprecated as of Home Assistant 2022.5.
|
|
||||||
# Please use the HVACAction enum instead.
|
|
||||||
_DEPRECATED_CURRENT_HVAC_OFF = DeprecatedConstantEnum(HVACAction.OFF, "2025.1")
|
|
||||||
_DEPRECATED_CURRENT_HVAC_HEAT = DeprecatedConstantEnum(HVACAction.HEATING, "2025.1")
|
|
||||||
_DEPRECATED_CURRENT_HVAC_COOL = DeprecatedConstantEnum(HVACAction.COOLING, "2025.1")
|
|
||||||
_DEPRECATED_CURRENT_HVAC_DRY = DeprecatedConstantEnum(HVACAction.DRYING, "2025.1")
|
|
||||||
_DEPRECATED_CURRENT_HVAC_IDLE = DeprecatedConstantEnum(HVACAction.IDLE, "2025.1")
|
|
||||||
_DEPRECATED_CURRENT_HVAC_FAN = DeprecatedConstantEnum(HVACAction.FAN, "2025.1")
|
|
||||||
CURRENT_HVAC_ACTIONS = [cls.value for cls in HVACAction]
|
CURRENT_HVAC_ACTIONS = [cls.value for cls in HVACAction]
|
||||||
|
|
||||||
|
|
||||||
@ -176,35 +151,3 @@ class ClimateEntityFeature(IntFlag):
|
|||||||
TURN_OFF = 128
|
TURN_OFF = 128
|
||||||
TURN_ON = 256
|
TURN_ON = 256
|
||||||
SWING_HORIZONTAL_MODE = 512
|
SWING_HORIZONTAL_MODE = 512
|
||||||
|
|
||||||
|
|
||||||
# These SUPPORT_* constants are deprecated as of Home Assistant 2022.5.
|
|
||||||
# Please use the ClimateEntityFeature enum instead.
|
|
||||||
_DEPRECATED_SUPPORT_TARGET_TEMPERATURE = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.TARGET_TEMPERATURE, "2025.1"
|
|
||||||
)
|
|
||||||
_DEPRECATED_SUPPORT_TARGET_TEMPERATURE_RANGE = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE, "2025.1"
|
|
||||||
)
|
|
||||||
_DEPRECATED_SUPPORT_TARGET_HUMIDITY = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.TARGET_HUMIDITY, "2025.1"
|
|
||||||
)
|
|
||||||
_DEPRECATED_SUPPORT_FAN_MODE = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.FAN_MODE, "2025.1"
|
|
||||||
)
|
|
||||||
_DEPRECATED_SUPPORT_PRESET_MODE = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.PRESET_MODE, "2025.1"
|
|
||||||
)
|
|
||||||
_DEPRECATED_SUPPORT_SWING_MODE = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.SWING_MODE, "2025.1"
|
|
||||||
)
|
|
||||||
_DEPRECATED_SUPPORT_AUX_HEAT = DeprecatedConstantEnum(
|
|
||||||
ClimateEntityFeature.AUX_HEAT, "2025.1"
|
|
||||||
)
|
|
||||||
|
|
||||||
# These can be removed if no deprecated constant are in this module anymore
|
|
||||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
|
||||||
__dir__ = partial(
|
|
||||||
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
|
|
||||||
)
|
|
||||||
__all__ = all_with_deprecated_constants(globals())
|
|
||||||
|
@ -48,7 +48,7 @@ async def test_get_triggers(
|
|||||||
)
|
)
|
||||||
hass.states.async_set(
|
hass.states.async_set(
|
||||||
entity_entry.entity_id,
|
entity_entry.entity_id,
|
||||||
const.HVAC_MODE_COOL,
|
HVACMode.COOL,
|
||||||
{
|
{
|
||||||
const.ATTR_HVAC_ACTION: HVACAction.IDLE,
|
const.ATTR_HVAC_ACTION: HVACAction.IDLE,
|
||||||
const.ATTR_CURRENT_HUMIDITY: 23,
|
const.ATTR_CURRENT_HUMIDITY: 23,
|
||||||
|
@ -3,14 +3,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from types import ModuleType
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import MagicMock, Mock, patch
|
from unittest.mock import MagicMock, Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import climate
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SET_TEMPERATURE_SCHEMA,
|
SET_TEMPERATURE_SCHEMA,
|
||||||
@ -58,9 +56,6 @@ from tests.common import (
|
|||||||
MockModule,
|
MockModule,
|
||||||
MockPlatform,
|
MockPlatform,
|
||||||
async_mock_service,
|
async_mock_service,
|
||||||
help_test_all,
|
|
||||||
import_and_test_deprecated_constant,
|
|
||||||
import_and_test_deprecated_constant_enum,
|
|
||||||
mock_integration,
|
mock_integration,
|
||||||
mock_platform,
|
mock_platform,
|
||||||
setup_test_component_platform,
|
setup_test_component_platform,
|
||||||
@ -213,63 +208,6 @@ def _create_tuples(enum: type[Enum], constant_prefix: str) -> list[tuple[Enum, s
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"module",
|
|
||||||
[climate, climate.const],
|
|
||||||
)
|
|
||||||
def test_all(module: ModuleType) -> None:
|
|
||||||
"""Test module.__all__ is correctly set."""
|
|
||||||
help_test_all(module)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("enum", "constant_prefix"),
|
|
||||||
_create_tuples(climate.ClimateEntityFeature, "SUPPORT_")
|
|
||||||
+ _create_tuples(climate.HVACMode, "HVAC_MODE_"),
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"module",
|
|
||||||
[climate, climate.const],
|
|
||||||
)
|
|
||||||
def test_deprecated_constants(
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
enum: Enum,
|
|
||||||
constant_prefix: str,
|
|
||||||
module: ModuleType,
|
|
||||||
) -> None:
|
|
||||||
"""Test deprecated constants."""
|
|
||||||
import_and_test_deprecated_constant_enum(
|
|
||||||
caplog, module, enum, constant_prefix, "2025.1"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("enum", "constant_postfix"),
|
|
||||||
[
|
|
||||||
(climate.HVACAction.OFF, "OFF"),
|
|
||||||
(climate.HVACAction.HEATING, "HEAT"),
|
|
||||||
(climate.HVACAction.COOLING, "COOL"),
|
|
||||||
(climate.HVACAction.DRYING, "DRY"),
|
|
||||||
(climate.HVACAction.IDLE, "IDLE"),
|
|
||||||
(climate.HVACAction.FAN, "FAN"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_deprecated_current_constants(
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
|
||||||
enum: climate.HVACAction,
|
|
||||||
constant_postfix: str,
|
|
||||||
) -> None:
|
|
||||||
"""Test deprecated current constants."""
|
|
||||||
import_and_test_deprecated_constant(
|
|
||||||
caplog,
|
|
||||||
climate.const,
|
|
||||||
"CURRENT_HVAC_" + constant_postfix,
|
|
||||||
f"{enum.__class__.__name__}.{enum.name}",
|
|
||||||
enum,
|
|
||||||
"2025.1",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_temperature_features_is_valid(
|
async def test_temperature_features_is_valid(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
register_test_integration: MockConfigEntry,
|
register_test_integration: MockConfigEntry,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user