Skip to content

Commit

Permalink
Remove deprecated climate constants (home-assistant#131798)
Browse files Browse the repository at this point in the history
* Remove deprecated climate constants

* Fix

* Fix

* Fix

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
  • Loading branch information
edenhaus and epenet authored Nov 28, 2024
1 parent a68cf21 commit 5c8fb5e
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 149 deletions.
29 changes: 0 additions & 29 deletions homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
from homeassistant.core import HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import ServiceValidationError
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_component import EntityComponent
from homeassistant.helpers.entity_platform import EntityPlatform
Expand All @@ -41,20 +36,6 @@
from homeassistant.util.unit_conversion import TemperatureConverter

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_CURRENT_HUMIDITY,
ATTR_CURRENT_TEMPERATURE,
Expand Down Expand Up @@ -1082,13 +1063,3 @@ async def async_service_temperature_set(
kwargs[value] = temp

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())
57 changes: 0 additions & 57 deletions homeassistant/components/climate/const.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
"""Provides the constants needed for component."""

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):
Expand Down Expand Up @@ -37,15 +29,6 @@ class HVACMode(StrEnum):
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]

# No preset is active
Expand Down Expand Up @@ -110,14 +93,6 @@ class HVACAction(StrEnum):
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]


Expand Down Expand Up @@ -176,35 +151,3 @@ class ClimateEntityFeature(IntFlag):
TURN_OFF = 128
TURN_ON = 256
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())
2 changes: 1 addition & 1 deletion tests/components/climate/test_device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def test_get_triggers(
)
hass.states.async_set(
entity_entry.entity_id,
const.HVAC_MODE_COOL,
HVACMode.COOL,
{
const.ATTR_HVAC_ACTION: HVACAction.IDLE,
const.ATTR_CURRENT_HUMIDITY: 23,
Expand Down
62 changes: 0 additions & 62 deletions tests/components/climate/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from __future__ import annotations

from enum import Enum
from types import ModuleType
from typing import Any
from unittest.mock import MagicMock, Mock, patch

import pytest
import voluptuous as vol

from homeassistant.components import climate
from homeassistant.components.climate import (
DOMAIN,
SET_TEMPERATURE_SCHEMA,
Expand Down Expand Up @@ -58,9 +56,6 @@
MockModule,
MockPlatform,
async_mock_service,
help_test_all,
import_and_test_deprecated_constant,
import_and_test_deprecated_constant_enum,
mock_integration,
mock_platform,
setup_test_component_platform,
Expand Down Expand Up @@ -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(
hass: HomeAssistant,
register_test_integration: MockConfigEntry,
Expand Down

0 comments on commit 5c8fb5e

Please sign in to comment.