1 """Reproduce an Alarm control panel state."""
3 from __future__
import annotations
6 from collections.abc
import Iterable
8 from typing
import Any, Final
12 SERVICE_ALARM_ARM_AWAY,
13 SERVICE_ALARM_ARM_CUSTOM_BYPASS,
14 SERVICE_ALARM_ARM_HOME,
15 SERVICE_ALARM_ARM_NIGHT,
16 SERVICE_ALARM_ARM_VACATION,
18 SERVICE_ALARM_TRIGGER,
22 from .
import DOMAIN, AlarmControlPanelState
24 _LOGGER: Final = logging.getLogger(__name__)
26 VALID_STATES: Final[set[str]] = {
27 AlarmControlPanelState.ARMED_AWAY,
28 AlarmControlPanelState.ARMED_CUSTOM_BYPASS,
29 AlarmControlPanelState.ARMED_HOME,
30 AlarmControlPanelState.ARMED_NIGHT,
31 AlarmControlPanelState.ARMED_VACATION,
32 AlarmControlPanelState.DISARMED,
33 AlarmControlPanelState.TRIGGERED,
41 context: Context |
None =
None,
42 reproduce_options: dict[str, Any] |
None =
None,
44 """Reproduce a single state."""
45 if (cur_state := hass.states.get(state.entity_id))
is None:
46 _LOGGER.warning(
"Unable to find entity %s", state.entity_id)
49 if state.state
not in VALID_STATES:
51 "Invalid state specified for %s: %s", state.entity_id, state.state
56 if cur_state.state == state.state:
59 service_data = {ATTR_ENTITY_ID: state.entity_id}
61 if state.state == AlarmControlPanelState.ARMED_AWAY:
62 service = SERVICE_ALARM_ARM_AWAY
63 elif state.state == AlarmControlPanelState.ARMED_CUSTOM_BYPASS:
64 service = SERVICE_ALARM_ARM_CUSTOM_BYPASS
65 elif state.state == AlarmControlPanelState.ARMED_HOME:
66 service = SERVICE_ALARM_ARM_HOME
67 elif state.state == AlarmControlPanelState.ARMED_NIGHT:
68 service = SERVICE_ALARM_ARM_NIGHT
69 elif state.state == AlarmControlPanelState.ARMED_VACATION:
70 service = SERVICE_ALARM_ARM_VACATION
71 elif state.state == AlarmControlPanelState.DISARMED:
72 service = SERVICE_ALARM_DISARM
73 elif state.state == AlarmControlPanelState.TRIGGERED:
74 service = SERVICE_ALARM_TRIGGER
76 await hass.services.async_call(
77 DOMAIN, service, service_data, context=context, blocking=
True
83 states: Iterable[State],
85 context: Context |
None =
None,
86 reproduce_options: dict[str, Any] |
None =
None,
88 """Reproduce Alarm control panel states."""
92 hass, state, context=context, reproduce_options=reproduce_options
None _async_reproduce_state(HomeAssistant hass, State state, *Context|None context=None, dict[str, Any]|None reproduce_options=None)
None async_reproduce_states(HomeAssistant hass, Iterable[State] states, *Context|None context=None, dict[str, Any]|None reproduce_options=None)