mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 01:11:51 -04:00
Move alarm_control_panel service registration to services module (#182816)
This commit is contained in:
@@ -4,7 +4,6 @@ from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any, Final, final, override
|
||||
|
||||
import probatio
|
||||
from propcache.api import cached_property
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@@ -22,25 +21,24 @@ from homeassistant.const import ( # noqa: F401
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.config_validation import make_entity_service_schema
|
||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
from .const import ( # noqa: F401
|
||||
ATTR_CHANGED_BY,
|
||||
ATTR_CODE_ARM_REQUIRED,
|
||||
DATA_COMPONENT,
|
||||
DOMAIN,
|
||||
AlarmControlPanelEntityFeature,
|
||||
AlarmControlPanelEntityStateAttribute,
|
||||
AlarmControlPanelState,
|
||||
CodeFormat,
|
||||
)
|
||||
from .services import async_setup_services
|
||||
|
||||
_LOGGER: Final = logging.getLogger(__name__)
|
||||
|
||||
DATA_COMPONENT: HassKey[EntityComponent[AlarmControlPanelEntity]] = HassKey(DOMAIN)
|
||||
ENTITY_ID_FORMAT: Final = DOMAIN + ".{}"
|
||||
PLATFORM_SCHEMA: Final = cv.PLATFORM_SCHEMA
|
||||
PLATFORM_SCHEMA_BASE: Final = cv.PLATFORM_SCHEMA_BASE
|
||||
@@ -48,11 +46,6 @@ SCAN_INTERVAL: Final = timedelta(seconds=30)
|
||||
|
||||
CONF_DEFAULT_CODE = "default_code"
|
||||
|
||||
ALARM_SERVICE_SCHEMA: Final = make_entity_service_schema(
|
||||
{probatio.Optional(ATTR_CODE): cv.string}
|
||||
)
|
||||
|
||||
|
||||
# mypy: disallow-any-generics
|
||||
|
||||
|
||||
@@ -64,47 +57,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
await component.async_setup(config)
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_DISARM,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_disarm",
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_home",
|
||||
[AlarmControlPanelEntityFeature.ARM_HOME],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_away",
|
||||
[AlarmControlPanelEntityFeature.ARM_AWAY],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_night",
|
||||
[AlarmControlPanelEntityFeature.ARM_NIGHT],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_VACATION,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_vacation",
|
||||
[AlarmControlPanelEntityFeature.ARM_VACATION],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_CUSTOM_BYPASS,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_custom_bypass",
|
||||
[AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_TRIGGER,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_trigger",
|
||||
[AlarmControlPanelEntityFeature.TRIGGER],
|
||||
)
|
||||
async_setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
"""Provides the constants needed for component."""
|
||||
|
||||
from enum import IntFlag, StrEnum
|
||||
from typing import Final
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from homeassistant.util.hass_dict import HassKey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
|
||||
from . import AlarmControlPanelEntity
|
||||
|
||||
DOMAIN: Final = "alarm_control_panel"
|
||||
DATA_COMPONENT: HassKey[EntityComponent[AlarmControlPanelEntity]] = HassKey(DOMAIN)
|
||||
|
||||
ATTR_CHANGED_BY: Final = "changed_by"
|
||||
ATTR_CODE_ARM_REQUIRED: Final = "code_arm_required"
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"""Services for the Alarm control panel integration."""
|
||||
|
||||
from typing import Final
|
||||
|
||||
import probatio
|
||||
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE,
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
SERVICE_ALARM_ARM_CUSTOM_BYPASS,
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
SERVICE_ALARM_ARM_VACATION,
|
||||
SERVICE_ALARM_DISARM,
|
||||
SERVICE_ALARM_TRIGGER,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.config_validation import make_entity_service_schema
|
||||
|
||||
from .const import DATA_COMPONENT, AlarmControlPanelEntityFeature
|
||||
|
||||
ALARM_SERVICE_SCHEMA: Final = make_entity_service_schema(
|
||||
{probatio.Optional(ATTR_CODE): cv.string}
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Register the alarm control panel services."""
|
||||
component = hass.data[DATA_COMPONENT]
|
||||
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_DISARM,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_disarm",
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_home",
|
||||
[AlarmControlPanelEntityFeature.ARM_HOME],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_away",
|
||||
[AlarmControlPanelEntityFeature.ARM_AWAY],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_NIGHT,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_night",
|
||||
[AlarmControlPanelEntityFeature.ARM_NIGHT],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_VACATION,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_vacation",
|
||||
[AlarmControlPanelEntityFeature.ARM_VACATION],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_ARM_CUSTOM_BYPASS,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_handle_alarm_arm_custom_bypass",
|
||||
[AlarmControlPanelEntityFeature.ARM_CUSTOM_BYPASS],
|
||||
)
|
||||
component.async_register_entity_service(
|
||||
SERVICE_ALARM_TRIGGER,
|
||||
ALARM_SERVICE_SCHEMA,
|
||||
"async_alarm_trigger",
|
||||
[AlarmControlPanelEntityFeature.TRIGGER],
|
||||
)
|
||||
Reference in New Issue
Block a user