From fb152c7d220ec9c7227e9ea495699db1937aee8f Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Thu, 28 Nov 2024 11:07:00 +0100 Subject: [PATCH] Remove deprecated automation constants (#131792) --- .../components/automation/__init__.py | 37 +------------------ tests/components/automation/test_init.py | 27 -------------- 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 4fcd8a1416d..bd8af526d75 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -6,7 +6,6 @@ from abc import ABC, abstractmethod import asyncio from collections.abc import Callable, Mapping from dataclasses import dataclass -from functools import partial import logging from typing import Any, Protocol, cast @@ -51,12 +50,6 @@ from homeassistant.core import ( from homeassistant.exceptions import HomeAssistantError, ServiceNotFound, TemplateError from homeassistant.helpers import condition 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_component import EntityComponent from homeassistant.helpers.issue_registry import ( @@ -86,12 +79,7 @@ from homeassistant.helpers.trace import ( trace_get, trace_path, ) -from homeassistant.helpers.trigger import ( - TriggerActionType, - TriggerData, - TriggerInfo, - async_initialize_triggers, -) +from homeassistant.helpers.trigger import async_initialize_triggers from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass from homeassistant.util.dt import parse_datetime @@ -137,20 +125,6 @@ class IfAction(Protocol): """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 def is_on(hass: HomeAssistant, entity_id: str) -> bool: """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: + """Run when entity will be removed from hass.""" await super().async_will_remove_from_hass() async_delete_issue( self.hass, DOMAIN, f"{self.entity_id}_validation_{self._validation_status}" @@ -1219,11 +1194,3 @@ def websocket_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()) diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py index 2bdc0f7516b..98d8bf0396e 100644 --- a/tests/components/automation/test_init.py +++ b/tests/components/automation/test_init.py @@ -50,7 +50,6 @@ from homeassistant.helpers.script import ( SCRIPT_MODE_SINGLE, _async_stop_scripts_at_shutdown, ) -from homeassistant.helpers.trigger import TriggerActionType, TriggerData, TriggerInfo from homeassistant.setup import async_setup_component from homeassistant.util import yaml import homeassistant.util.dt as dt_util @@ -62,8 +61,6 @@ from tests.common import ( async_capture_events, async_fire_time_changed, async_mock_service, - help_test_all, - import_and_test_deprecated_constant, mock_restore_cache, ) from tests.components.logbook.common import MockRow, mock_humanify @@ -3153,30 +3150,6 @@ async def test_websocket_config( 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: """Test an automation that turns off another automation.""" hass.set_state(CoreState.not_running)