Skip to content

Commit

Permalink
Remove deprecated alarm control panel constants (home-assistant#131790)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Nov 28, 2024
1 parent fd14add commit 54ff6fe
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 117 deletions.
26 changes: 1 addition & 25 deletions homeassistant/components/alarm_control_panel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import asyncio
from datetime import timedelta
from functools import partial
import logging
from typing import TYPE_CHECKING, Any, Final, final

Expand All @@ -27,27 +26,14 @@
from homeassistant.exceptions import ServiceValidationError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import make_entity_service_schema
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
from homeassistant.helpers.frame import ReportBehavior, report_usage
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.hass_dict import HassKey

from .const import ( # noqa: F401
_DEPRECATED_FORMAT_NUMBER,
_DEPRECATED_FORMAT_TEXT,
_DEPRECATED_SUPPORT_ALARM_ARM_AWAY,
_DEPRECATED_SUPPORT_ALARM_ARM_CUSTOM_BYPASS,
_DEPRECATED_SUPPORT_ALARM_ARM_HOME,
_DEPRECATED_SUPPORT_ALARM_ARM_NIGHT,
_DEPRECATED_SUPPORT_ALARM_ARM_VACATION,
_DEPRECATED_SUPPORT_ALARM_TRIGGER,
from .const import (
ATTR_CHANGED_BY,
ATTR_CODE_ARM_REQUIRED,
DOMAIN,
Expand Down Expand Up @@ -412,13 +398,3 @@ def _async_read_entity_options(self) -> None:
self._alarm_control_panel_option_default_code = default_code
return
self._alarm_control_panel_option_default_code = None


# As we import constants of the const module here, we need to add the following
# functions to check for deprecated constants again
# 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())
42 changes: 0 additions & 42 deletions homeassistant/components/alarm_control_panel/const.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
"""Provides the constants needed for component."""

from enum import IntFlag, StrEnum
from functools import partial
from typing import Final

from homeassistant.helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)

DOMAIN: Final = "alarm_control_panel"

ATTR_CHANGED_BY: Final = "changed_by"
Expand Down Expand Up @@ -39,12 +31,6 @@ class CodeFormat(StrEnum):
NUMBER = "number"


# These constants are deprecated as of Home Assistant 2022.5, can be removed in 2025.1
# Please use the CodeFormat enum instead.
_DEPRECATED_FORMAT_TEXT: Final = DeprecatedConstantEnum(CodeFormat.TEXT, "2025.1")
_DEPRECATED_FORMAT_NUMBER: Final = DeprecatedConstantEnum(CodeFormat.NUMBER, "2025.1")


class AlarmControlPanelEntityFeature(IntFlag):
"""Supported features of the alarm control panel entity."""

Expand All @@ -56,38 +42,10 @@ class AlarmControlPanelEntityFeature(IntFlag):
ARM_VACATION = 32


# These constants are deprecated as of Home Assistant 2022.5
# Please use the AlarmControlPanelEntityFeature enum instead.
_DEPRECATED_SUPPORT_ALARM_ARM_HOME: Final = DeprecatedConstantEnum(
AlarmControlPanelEntityFeature.ARM_HOME, "2025.1"
)
_DEPRECATED_SUPPORT_ALARM_ARM_AWAY: Final = DeprecatedConstantEnum(
AlarmControlPanelEntityFeature.ARM_AWAY, "2025.1"
)
_DEPRECATED_SUPPORT_ALARM_ARM_NIGHT: Final = DeprecatedConstantEnum(
AlarmControlPanelEntityFeature.ARM_NIGHT, "2025.1"
)
_DEPRECATED_SUPPORT_ALARM_TRIGGER: Final = DeprecatedConstantEnum(
AlarmControlPanelEntityFeature.TRIGGER, "2025.1"
)
_DEPRECATED_SUPPORT_ALARM_ARM_CUSTOM_BYPASS: Final = DeprecatedConstantEnum(
AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS, "2025.1"
)
_DEPRECATED_SUPPORT_ALARM_ARM_VACATION: Final = DeprecatedConstantEnum(
AlarmControlPanelEntityFeature.ARM_VACATION, "2025.1"
)

CONDITION_TRIGGERED: Final = "is_triggered"
CONDITION_DISARMED: Final = "is_disarmed"
CONDITION_ARMED_HOME: Final = "is_armed_home"
CONDITION_ARMED_AWAY: Final = "is_armed_away"
CONDITION_ARMED_NIGHT: Final = "is_armed_night"
CONDITION_ARMED_VACATION: Final = "is_armed_vacation"
CONDITION_ARMED_CUSTOM_BYPASS: Final = "is_armed_custom_bypass"

# 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())
50 changes: 0 additions & 50 deletions tests/components/alarm_control_panel/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test for the alarm control panel const module."""

from types import ModuleType
from typing import Any
from unittest.mock import patch

Expand Down Expand Up @@ -33,8 +32,6 @@
from tests.common import (
MockConfigEntry,
MockModule,
help_test_all,
import_and_test_deprecated_constant_enum,
mock_integration,
setup_test_component_platform,
)
Expand All @@ -57,53 +54,6 @@ async def help_test_async_alarm_control_panel_service(
await hass.async_block_till_done()


@pytest.mark.parametrize(
"module",
[alarm_control_panel, alarm_control_panel.const],
)
def test_all(module: ModuleType) -> None:
"""Test module.__all__ is correctly set."""
help_test_all(module)


@pytest.mark.parametrize(
"code_format",
list(alarm_control_panel.CodeFormat),
)
@pytest.mark.parametrize(
"module",
[alarm_control_panel, alarm_control_panel.const],
)
def test_deprecated_constant_code_format(
caplog: pytest.LogCaptureFixture,
code_format: alarm_control_panel.CodeFormat,
module: ModuleType,
) -> None:
"""Test deprecated format constants."""
import_and_test_deprecated_constant_enum(
caplog, module, code_format, "FORMAT_", "2025.1"
)


@pytest.mark.parametrize(
"entity_feature",
list(alarm_control_panel.AlarmControlPanelEntityFeature),
)
@pytest.mark.parametrize(
"module",
[alarm_control_panel, alarm_control_panel.const],
)
def test_deprecated_support_alarm_constants(
caplog: pytest.LogCaptureFixture,
entity_feature: alarm_control_panel.AlarmControlPanelEntityFeature,
module: ModuleType,
) -> None:
"""Test deprecated support alarm constants."""
import_and_test_deprecated_constant_enum(
caplog, module, entity_feature, "SUPPORT_ALARM_", "2025.1"
)


def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
"""Test deprecated supported features ints."""

Expand Down

0 comments on commit 54ff6fe

Please sign in to comment.