Remove deprecated automation constants (#131792)

This commit is contained in:
Robert Resch 2024-11-28 11:07:00 +01:00 committed by GitHub
parent be81fd86d3
commit fb152c7d22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 62 deletions

View File

@ -6,7 +6,6 @@ from abc import ABC, abstractmethod
import asyncio import asyncio
from collections.abc import Callable, Mapping from collections.abc import Callable, Mapping
from dataclasses import dataclass from dataclasses import dataclass
from functools import partial
import logging import logging
from typing import Any, Protocol, cast from typing import Any, Protocol, cast
@ -51,12 +50,6 @@ from homeassistant.core import (
from homeassistant.exceptions import HomeAssistantError, ServiceNotFound, TemplateError from homeassistant.exceptions import HomeAssistantError, ServiceNotFound, TemplateError
from homeassistant.helpers import condition from homeassistant.helpers import condition
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.deprecation import (
DeprecatedConstant,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.issue_registry import ( from homeassistant.helpers.issue_registry import (
@ -86,12 +79,7 @@ from homeassistant.helpers.trace import (
trace_get, trace_get,
trace_path, trace_path,
) )
from homeassistant.helpers.trigger import ( from homeassistant.helpers.trigger import async_initialize_triggers
TriggerActionType,
TriggerData,
TriggerInfo,
async_initialize_triggers,
)
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import bind_hass from homeassistant.loader import bind_hass
from homeassistant.util.dt import parse_datetime from homeassistant.util.dt import parse_datetime
@ -137,20 +125,6 @@ class IfAction(Protocol):
"""AND all conditions.""" """AND all conditions."""
# AutomationActionType, AutomationTriggerData,
# and AutomationTriggerInfo are deprecated as of 2022.9.
# Can be removed in 2025.1
_DEPRECATED_AutomationActionType = DeprecatedConstant(
TriggerActionType, "TriggerActionType", "2025.1"
)
_DEPRECATED_AutomationTriggerData = DeprecatedConstant(
TriggerData, "TriggerData", "2025.1"
)
_DEPRECATED_AutomationTriggerInfo = DeprecatedConstant(
TriggerInfo, "TriggerInfo", "2025.1"
)
@bind_hass @bind_hass
def is_on(hass: HomeAssistant, entity_id: str) -> bool: def is_on(hass: HomeAssistant, entity_id: str) -> bool:
"""Return true if specified automation entity_id is on. """Return true if specified automation entity_id is on.
@ -477,6 +451,7 @@ class UnavailableAutomationEntity(BaseAutomationEntity):
) )
async def async_will_remove_from_hass(self) -> None: async def async_will_remove_from_hass(self) -> None:
"""Run when entity will be removed from hass."""
await super().async_will_remove_from_hass() await super().async_will_remove_from_hass()
async_delete_issue( async_delete_issue(
self.hass, DOMAIN, f"{self.entity_id}_validation_{self._validation_status}" self.hass, DOMAIN, f"{self.entity_id}_validation_{self._validation_status}"
@ -1219,11 +1194,3 @@ def websocket_config(
"config": automation.raw_config, "config": automation.raw_config,
}, },
) )
# 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())

View File

@ -50,7 +50,6 @@ from homeassistant.helpers.script import (
SCRIPT_MODE_SINGLE, SCRIPT_MODE_SINGLE,
_async_stop_scripts_at_shutdown, _async_stop_scripts_at_shutdown,
) )
from homeassistant.helpers.trigger import TriggerActionType, TriggerData, TriggerInfo
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from homeassistant.util import yaml from homeassistant.util import yaml
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
@ -62,8 +61,6 @@ from tests.common import (
async_capture_events, async_capture_events,
async_fire_time_changed, async_fire_time_changed,
async_mock_service, async_mock_service,
help_test_all,
import_and_test_deprecated_constant,
mock_restore_cache, mock_restore_cache,
) )
from tests.components.logbook.common import MockRow, mock_humanify from tests.components.logbook.common import MockRow, mock_humanify
@ -3153,30 +3150,6 @@ async def test_websocket_config(
assert msg["error"]["code"] == "not_found" assert msg["error"]["code"] == "not_found"
def test_all() -> None:
"""Test module.__all__ is correctly set."""
help_test_all(automation)
@pytest.mark.parametrize(
("constant_name", "replacement"),
[
("AutomationActionType", TriggerActionType),
("AutomationTriggerData", TriggerData),
("AutomationTriggerInfo", TriggerInfo),
],
)
def test_deprecated_constants(
caplog: pytest.LogCaptureFixture,
constant_name: str,
replacement: Any,
) -> None:
"""Test deprecated automation constants."""
import_and_test_deprecated_constant(
caplog, automation, constant_name, replacement.__name__, replacement, "2025.1"
)
async def test_automation_turns_off_other_automation(hass: HomeAssistant) -> None: async def test_automation_turns_off_other_automation(hass: HomeAssistant) -> None:
"""Test an automation that turns off another automation.""" """Test an automation that turns off another automation."""
hass.set_state(CoreState.not_running) hass.set_state(CoreState.not_running)