From 3aee89bb7d2bbe94a7b5141e368de449f4fd1139 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 8 Oct 2026 10:58:50 +0200 Subject: [PATCH] Move alert service registration to services module (#184846) Co-authored-by: Claude Opus 5.5 --- homeassistant/components/alert/__init__.py | 13 ++++++------- homeassistant/components/alert/const.py | 10 +++++++++- homeassistant/components/alert/services.py | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 homeassistant/components/alert/services.py diff --git a/homeassistant/components/alert/__init__.py b/homeassistant/components/alert/__init__.py index 4c8a5bddfbb5..e5071a46990c 100644 --- a/homeassistant/components/alert/__init__.py +++ b/homeassistant/components/alert/__init__.py @@ -10,9 +10,6 @@ from homeassistant.const import ( CONF_NAME, CONF_REPEAT, CONF_STATE, - SERVICE_TOGGLE, - SERVICE_TURN_OFF, - SERVICE_TURN_ON, STATE_ON, ) from homeassistant.core import HomeAssistant @@ -28,12 +25,14 @@ from .const import ( CONF_NOTIFIERS, CONF_SKIP_FIRST, CONF_TITLE, + DATA_COMPONENT, DEFAULT_CAN_ACK, DEFAULT_SKIP_FIRST, DOMAIN, LOGGER, ) from .entity import AlertEntity +from .services import async_setup_services ALERT_SCHEMA = probatio.Schema( { @@ -68,7 +67,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: DEVELOPMENT OF THE ALERT INTEGRATION IS FROZEN. """ - component = EntityComponent[AlertEntity](LOGGER, DOMAIN, hass) + component = hass.data[DATA_COMPONENT] = EntityComponent[AlertEntity]( + LOGGER, DOMAIN, hass + ) entities: list[AlertEntity] = [] @@ -109,9 +110,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if not entities: return False - component.async_register_entity_service(SERVICE_TURN_OFF, None, "async_turn_off") - component.async_register_entity_service(SERVICE_TURN_ON, None, "async_turn_on") - component.async_register_entity_service(SERVICE_TOGGLE, None, "async_toggle") + async_setup_services(hass) await component.async_add_entities(entities) diff --git a/homeassistant/components/alert/const.py b/homeassistant/components/alert/const.py index e8afd5ab4520..bea3e921cdc0 100644 --- a/homeassistant/components/alert/const.py +++ b/homeassistant/components/alert/const.py @@ -1,10 +1,18 @@ """Constants for the Alert integration.""" import logging -from typing import Final +from typing import TYPE_CHECKING, Final + +from homeassistant.helpers.entity_component import EntityComponent +from homeassistant.util.hass_dict import HassKey + +if TYPE_CHECKING: + from .entity import AlertEntity DOMAIN: Final = "alert" +DATA_COMPONENT: HassKey[EntityComponent[AlertEntity]] = HassKey(DOMAIN) + LOGGER = logging.getLogger(__package__) CONF_CAN_ACK = "can_acknowledge" diff --git a/homeassistant/components/alert/services.py b/homeassistant/components/alert/services.py new file mode 100644 index 000000000000..a1b151e43fef --- /dev/null +++ b/homeassistant/components/alert/services.py @@ -0,0 +1,15 @@ +"""Services for the Alert integration.""" + +from homeassistant.const import SERVICE_TOGGLE, SERVICE_TURN_OFF, SERVICE_TURN_ON +from homeassistant.core import HomeAssistant, callback + +from .const import DATA_COMPONENT + + +@callback +def async_setup_services(hass: HomeAssistant) -> None: + """Set up the services for the Alert integration.""" + component = hass.data[DATA_COMPONENT] + component.async_register_entity_service(SERVICE_TURN_OFF, None, "async_turn_off") + component.async_register_entity_service(SERVICE_TURN_ON, None, "async_turn_on") + component.async_register_entity_service(SERVICE_TOGGLE, None, "async_toggle")