Move alert service registration to services module (#184846)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
epenet
2026-10-08 10:58:50 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 12b72603b6
commit 3aee89bb7d
3 changed files with 30 additions and 8 deletions
+6 -7
View File
@@ -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)
+9 -1
View File
@@ -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"
@@ -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")