2018-09-26 07:49:55 +00:00
|
|
|
"""Collection of helper methods.
|
|
|
|
|
|
|
|
All containing methods are legacy helpers that should not be used by new
|
|
|
|
components. Instead call the service directly.
|
|
|
|
"""
|
|
|
|
from homeassistant.components.alarm_control_panel import DOMAIN
|
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_CODE,
|
|
|
|
ATTR_ENTITY_ID,
|
2019-12-08 12:42:31 +00:00
|
|
|
ENTITY_MATCH_ALL,
|
2019-07-31 19:25:30 +00:00
|
|
|
SERVICE_ALARM_ARM_AWAY,
|
|
|
|
SERVICE_ALARM_ARM_CUSTOM_BYPASS,
|
2019-12-08 12:42:31 +00:00
|
|
|
SERVICE_ALARM_ARM_HOME,
|
|
|
|
SERVICE_ALARM_ARM_NIGHT,
|
|
|
|
SERVICE_ALARM_DISARM,
|
|
|
|
SERVICE_ALARM_TRIGGER,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-11-07 08:56:24 +00:00
|
|
|
|
|
|
|
|
2019-12-03 00:23:12 +00:00
|
|
|
async def async_alarm_disarm(hass, code=None, entity_id=ENTITY_MATCH_ALL):
|
2018-11-07 08:56:24 +00:00
|
|
|
"""Send the alarm the command for disarm."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_ALARM_DISARM, data, blocking=True)
|
2018-09-26 07:49:55 +00:00
|
|
|
|
|
|
|
|
2019-12-03 00:23:12 +00:00
|
|
|
async def async_alarm_arm_home(hass, code=None, entity_id=ENTITY_MATCH_ALL):
|
2018-11-07 08:56:24 +00:00
|
|
|
"""Send the alarm the command for disarm."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_HOME, data, blocking=True)
|
2018-11-07 08:56:24 +00:00
|
|
|
|
|
|
|
|
2019-12-03 00:23:12 +00:00
|
|
|
async def async_alarm_arm_away(hass, code=None, entity_id=ENTITY_MATCH_ALL):
|
2018-11-07 08:56:24 +00:00
|
|
|
"""Send the alarm the command for disarm."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_AWAY, data, blocking=True)
|
2018-11-07 08:56:24 +00:00
|
|
|
|
|
|
|
|
2019-12-03 00:23:12 +00:00
|
|
|
async def async_alarm_arm_night(hass, code=None, entity_id=ENTITY_MATCH_ALL):
|
2018-11-07 08:56:24 +00:00
|
|
|
"""Send the alarm the command for disarm."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_ALARM_ARM_NIGHT, data, blocking=True)
|
2018-11-07 08:56:24 +00:00
|
|
|
|
|
|
|
|
2019-12-03 00:23:12 +00:00
|
|
|
async def async_alarm_trigger(hass, code=None, entity_id=ENTITY_MATCH_ALL):
|
2018-11-07 08:56:24 +00:00
|
|
|
"""Send the alarm the command for disarm."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_ALARM_TRIGGER, data, blocking=True)
|
2018-11-07 08:56:24 +00:00
|
|
|
|
|
|
|
|
2019-12-03 00:23:12 +00:00
|
|
|
async def async_alarm_arm_custom_bypass(hass, code=None, entity_id=ENTITY_MATCH_ALL):
|
2018-11-07 08:56:24 +00:00
|
|
|
"""Send the alarm the command for disarm."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
await hass.services.async_call(
|
2019-07-31 19:25:30 +00:00
|
|
|
DOMAIN, SERVICE_ALARM_ARM_CUSTOM_BYPASS, data, blocking=True
|
|
|
|
)
|