diff --git a/homeassistant/components/alarm_control_panel/device_action.py b/homeassistant/components/alarm_control_panel/device_action.py index 57ae2316c6b1..5c3404cc5175 100644 --- a/homeassistant/components/alarm_control_panel/device_action.py +++ b/homeassistant/components/alarm_control_panel/device_action.py @@ -1,17 +1,17 @@ """Provides device automations for Alarm control panel.""" -from typing import Final +from typing import Any, Final import probatio from homeassistant.components.device_automation import async_validate_entity_schema from homeassistant.const import ( - ATTR_ENTITY_ID, CONF_CODE, CONF_DEVICE_ID, CONF_DOMAIN, CONF_ENTITY_ID, CONF_TYPE, + TargetKey, ) from homeassistant.core import Context, HomeAssistant from homeassistant.helpers import config_validation as cv, entity_registry as er @@ -94,7 +94,7 @@ async def async_call_action_from_config( context: Context | None, ) -> None: """Execute a device action.""" - service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]} + service_data: dict[str, Any] = {TargetKey.ENTITY_ID: config[CONF_ENTITY_ID]} if CONF_CODE in config: service_data[AlarmControlPanelServiceArgument.CODE] = config[CONF_CODE] diff --git a/homeassistant/components/alarm_control_panel/reproduce_state.py b/homeassistant/components/alarm_control_panel/reproduce_state.py index 90b9b4520cd3..5ae8ff5b5640 100644 --- a/homeassistant/components/alarm_control_panel/reproduce_state.py +++ b/homeassistant/components/alarm_control_panel/reproduce_state.py @@ -5,7 +5,7 @@ from collections.abc import Iterable import logging from typing import Any, Final -from homeassistant.const import ATTR_ENTITY_ID +from homeassistant.const import TargetKey from homeassistant.core import Context, HomeAssistant, State from . import AlarmControlPanelState @@ -46,7 +46,7 @@ async def _async_reproduce_state( if cur_state.state == state.state: return - service_data = {ATTR_ENTITY_ID: state.entity_id} + service_data: dict[str, Any] = {TargetKey.ENTITY_ID: state.entity_id} if state.state == AlarmControlPanelState.ARMED_AWAY: service = AlarmControlPanelService.ARM_AWAY diff --git a/tests/components/alarm_control_panel/common.py b/tests/components/alarm_control_panel/common.py index 1dac34f40a24..972166bc8806 100644 --- a/tests/components/alarm_control_panel/common.py +++ b/tests/components/alarm_control_panel/common.py @@ -10,20 +10,11 @@ from homeassistant.components.alarm_control_panel import ( DOMAIN, AlarmControlPanelEntity, AlarmControlPanelEntityFeature, + AlarmControlPanelService, + AlarmControlPanelServiceArgument, AlarmControlPanelState, ) -from homeassistant.const import ( - ATTR_CODE, - ATTR_ENTITY_ID, - ENTITY_MATCH_ALL, - 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.const import ENTITY_MATCH_ALL, TargetKey from homeassistant.core import HomeAssistant @@ -33,11 +24,13 @@ async def async_alarm_disarm( """Send the alarm the command for disarm.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id - await hass.services.async_call(DOMAIN, SERVICE_ALARM_DISARM, data, blocking=True) + await hass.services.async_call( + DOMAIN, AlarmControlPanelService.DISARM, data, blocking=True + ) async def async_alarm_arm_home( @@ -46,11 +39,13 @@ async def async_alarm_arm_home( """Send the alarm the command for disarm.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id - await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_HOME, data, blocking=True) + await hass.services.async_call( + DOMAIN, AlarmControlPanelService.ARM_HOME, data, blocking=True + ) async def async_alarm_arm_away( @@ -59,11 +54,13 @@ async def async_alarm_arm_away( """Send the alarm the command for disarm.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id - await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_AWAY, data, blocking=True) + await hass.services.async_call( + DOMAIN, AlarmControlPanelService.ARM_AWAY, data, blocking=True + ) async def async_alarm_arm_night( @@ -72,11 +69,13 @@ async def async_alarm_arm_night( """Send the alarm the command for disarm.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id - await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_NIGHT, data, blocking=True) + await hass.services.async_call( + DOMAIN, AlarmControlPanelService.ARM_NIGHT, data, blocking=True + ) async def async_alarm_arm_vacation( @@ -85,12 +84,12 @@ async def async_alarm_arm_vacation( """Send the alarm the command for vacation mode.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id await hass.services.async_call( - DOMAIN, SERVICE_ALARM_ARM_VACATION, data, blocking=True + DOMAIN, AlarmControlPanelService.ARM_VACATION, data, blocking=True ) @@ -100,11 +99,13 @@ async def async_alarm_trigger( """Send the alarm the command for disarm.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id - await hass.services.async_call(DOMAIN, SERVICE_ALARM_TRIGGER, data, blocking=True) + await hass.services.async_call( + DOMAIN, AlarmControlPanelService.TRIGGER, data, blocking=True + ) async def async_alarm_arm_custom_bypass( @@ -113,12 +114,12 @@ async def async_alarm_arm_custom_bypass( """Send the alarm the command for disarm.""" data = {} if code: - data[ATTR_CODE] = code + data[AlarmControlPanelServiceArgument.CODE] = code if entity_id: - data[ATTR_ENTITY_ID] = entity_id + data[TargetKey.ENTITY_ID] = entity_id await hass.services.async_call( - DOMAIN, SERVICE_ALARM_ARM_CUSTOM_BYPASS, data, blocking=True + DOMAIN, AlarmControlPanelService.ARM_CUSTOM_BYPASS, data, blocking=True )