2019-09-10 23:56:28 +00:00
|
|
|
"""Provides device automations for deconz events."""
|
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
import homeassistant.components.automation.event as event
|
|
|
|
|
2019-09-24 21:57:05 +00:00
|
|
|
from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
|
2019-09-10 23:56:28 +00:00
|
|
|
from homeassistant.components.device_automation.exceptions import (
|
|
|
|
InvalidDeviceAutomationConfig,
|
|
|
|
)
|
|
|
|
from homeassistant.const import (
|
|
|
|
CONF_DEVICE_ID,
|
|
|
|
CONF_DOMAIN,
|
|
|
|
CONF_EVENT,
|
|
|
|
CONF_PLATFORM,
|
|
|
|
CONF_TYPE,
|
|
|
|
)
|
|
|
|
|
|
|
|
from . import DOMAIN
|
|
|
|
from .config_flow import configured_gateways
|
|
|
|
from .deconz_event import CONF_DECONZ_EVENT, CONF_UNIQUE_ID
|
|
|
|
from .gateway import get_gateway_from_config_entry
|
|
|
|
|
|
|
|
CONF_SUBTYPE = "subtype"
|
|
|
|
|
|
|
|
CONF_SHORT_PRESS = "remote_button_short_press"
|
|
|
|
CONF_SHORT_RELEASE = "remote_button_short_release"
|
|
|
|
CONF_LONG_PRESS = "remote_button_long_press"
|
|
|
|
CONF_LONG_RELEASE = "remote_button_long_release"
|
|
|
|
CONF_DOUBLE_PRESS = "remote_button_double_press"
|
|
|
|
CONF_TRIPLE_PRESS = "remote_button_triple_press"
|
|
|
|
CONF_QUADRUPLE_PRESS = "remote_button_quadruple_press"
|
|
|
|
CONF_QUINTUPLE_PRESS = "remote_button_quintuple_press"
|
|
|
|
CONF_ROTATED = "remote_button_rotated"
|
2019-10-02 20:12:59 +00:00
|
|
|
CONF_ROTATION_STOPPED = "remote_button_rotation_stopped"
|
2019-11-01 21:29:34 +00:00
|
|
|
CONF_AWAKE = "remote_awakened"
|
|
|
|
CONF_MOVE = "remote_moved"
|
|
|
|
CONF_DOUBLE_TAP = "remote_double_tap"
|
2019-09-10 23:56:28 +00:00
|
|
|
CONF_SHAKE = "remote_gyro_activated"
|
2019-11-01 21:29:34 +00:00
|
|
|
CONF_FREE_FALL = "remote_falling"
|
|
|
|
CONF_ROTATE_FROM_SIDE_1 = "remote_rotate_from_side_1"
|
|
|
|
CONF_ROTATE_FROM_SIDE_2 = "remote_rotate_from_side_2"
|
|
|
|
CONF_ROTATE_FROM_SIDE_3 = "remote_rotate_from_side_3"
|
|
|
|
CONF_ROTATE_FROM_SIDE_4 = "remote_rotate_from_side_4"
|
|
|
|
CONF_ROTATE_FROM_SIDE_5 = "remote_rotate_from_side_5"
|
|
|
|
CONF_ROTATE_FROM_SIDE_6 = "remote_rotate_from_side_6"
|
2019-09-10 23:56:28 +00:00
|
|
|
|
|
|
|
CONF_TURN_ON = "turn_on"
|
|
|
|
CONF_TURN_OFF = "turn_off"
|
|
|
|
CONF_DIM_UP = "dim_up"
|
|
|
|
CONF_DIM_DOWN = "dim_down"
|
|
|
|
CONF_LEFT = "left"
|
|
|
|
CONF_RIGHT = "right"
|
|
|
|
CONF_OPEN = "open"
|
|
|
|
CONF_CLOSE = "close"
|
|
|
|
CONF_BOTH_BUTTONS = "both_buttons"
|
|
|
|
CONF_BUTTON_1 = "button_1"
|
|
|
|
CONF_BUTTON_2 = "button_2"
|
|
|
|
CONF_BUTTON_3 = "button_3"
|
|
|
|
CONF_BUTTON_4 = "button_4"
|
2019-11-01 21:29:34 +00:00
|
|
|
CONF_SIDE_1 = "side_1"
|
|
|
|
CONF_SIDE_2 = "side_2"
|
|
|
|
CONF_SIDE_3 = "side_3"
|
|
|
|
CONF_SIDE_4 = "side_4"
|
|
|
|
CONF_SIDE_5 = "side_5"
|
|
|
|
CONF_SIDE_6 = "side_6"
|
|
|
|
|
2019-09-10 23:56:28 +00:00
|
|
|
|
2019-11-01 22:06:29 +00:00
|
|
|
HUE_DIMMER_REMOTE_MODEL_GEN1 = "RWL020"
|
|
|
|
HUE_DIMMER_REMOTE_MODEL_GEN2 = "RWL021"
|
2019-09-10 23:56:28 +00:00
|
|
|
HUE_DIMMER_REMOTE = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1000,
|
|
|
|
(CONF_SHORT_RELEASE, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_ON): 1001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_ON): 1003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_DIM_UP): 2000,
|
|
|
|
(CONF_SHORT_RELEASE, CONF_DIM_UP): 2002,
|
|
|
|
(CONF_LONG_PRESS, CONF_DIM_UP): 2001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_DIM_UP): 2003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_DIM_DOWN): 3000,
|
|
|
|
(CONF_SHORT_RELEASE, CONF_DIM_DOWN): 3002,
|
|
|
|
(CONF_LONG_PRESS, CONF_DIM_DOWN): 3001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_DIM_DOWN): 3003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_OFF): 4000,
|
|
|
|
(CONF_SHORT_RELEASE, CONF_TURN_OFF): 4002,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_OFF): 4001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_OFF): 4003,
|
|
|
|
}
|
|
|
|
|
|
|
|
HUE_TAP_REMOTE_MODEL = "ZGPSWITCH"
|
|
|
|
HUE_TAP_REMOTE = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_BUTTON_1): 34,
|
|
|
|
(CONF_SHORT_PRESS, CONF_BUTTON_2): 16,
|
|
|
|
(CONF_SHORT_PRESS, CONF_BUTTON_3): 17,
|
|
|
|
(CONF_SHORT_PRESS, CONF_BUTTON_4): 18,
|
|
|
|
}
|
|
|
|
|
2019-10-02 20:12:59 +00:00
|
|
|
SYMFONISK_SOUND_CONTROLLER_MODEL = "SYMFONISK Sound Controller"
|
|
|
|
SYMFONISK_SOUND_CONTROLLER = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_TURN_ON): 1004,
|
|
|
|
(CONF_TRIPLE_PRESS, CONF_TURN_ON): 1005,
|
|
|
|
(CONF_ROTATED, CONF_LEFT): 2001,
|
|
|
|
(CONF_ROTATION_STOPPED, CONF_LEFT): 2003,
|
|
|
|
(CONF_ROTATED, CONF_RIGHT): 3001,
|
|
|
|
(CONF_ROTATION_STOPPED, CONF_RIGHT): 3003,
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:56:28 +00:00
|
|
|
TRADFRI_ON_OFF_SWITCH_MODEL = "TRADFRI on/off switch"
|
|
|
|
TRADFRI_ON_OFF_SWITCH = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_ON): 1001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_ON): 1003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_OFF): 2002,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_OFF): 2001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_OFF): 2003,
|
|
|
|
}
|
|
|
|
|
|
|
|
TRADFRI_OPEN_CLOSE_REMOTE_MODEL = "TRADFRI open/close remote"
|
|
|
|
TRADFRI_OPEN_CLOSE_REMOTE = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_OPEN): 1002,
|
|
|
|
(CONF_LONG_PRESS, CONF_OPEN): 1003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_CLOSE): 2002,
|
|
|
|
(CONF_LONG_PRESS, CONF_CLOSE): 2003,
|
|
|
|
}
|
|
|
|
|
|
|
|
TRADFRI_REMOTE_MODEL = "TRADFRI remote control"
|
|
|
|
TRADFRI_REMOTE = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_ON): 1001,
|
|
|
|
(CONF_SHORT_PRESS, CONF_DIM_UP): 2002,
|
|
|
|
(CONF_LONG_PRESS, CONF_DIM_UP): 2001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_DIM_UP): 2003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_DIM_DOWN): 3002,
|
|
|
|
(CONF_LONG_PRESS, CONF_DIM_DOWN): 3001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_DIM_DOWN): 3003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_LEFT): 4002,
|
|
|
|
(CONF_LONG_PRESS, CONF_LEFT): 4001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_LEFT): 4003,
|
|
|
|
(CONF_SHORT_PRESS, CONF_RIGHT): 5002,
|
|
|
|
(CONF_LONG_PRESS, CONF_RIGHT): 5001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_RIGHT): 5003,
|
|
|
|
}
|
|
|
|
|
|
|
|
TRADFRI_WIRELESS_DIMMER_MODEL = "TRADFRI wireless dimmer"
|
|
|
|
TRADFRI_WIRELESS_DIMMER = {
|
|
|
|
(CONF_ROTATED, CONF_LEFT): 3002,
|
|
|
|
(CONF_ROTATED, CONF_RIGHT): 2002,
|
|
|
|
}
|
|
|
|
|
2019-11-01 21:29:34 +00:00
|
|
|
AQARA_CUBE_MODEL = "lumi.sensor_cube"
|
|
|
|
AQARA_CUBE = {
|
|
|
|
(CONF_ROTATE_FROM_SIDE_1, CONF_SIDE_2): 6002,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_1, CONF_SIDE_3): 3002,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_1, CONF_SIDE_4): 4002,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_1, CONF_SIDE_5): 1002,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_1, CONF_SIDE_6): 5002,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_2, CONF_SIDE_1): 2006,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_2, CONF_SIDE_3): 3006,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_2, CONF_SIDE_4): 4006,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_2, CONF_SIDE_5): 1006,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_2, CONF_SIDE_6): 5006,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_3, CONF_SIDE_1): 2003,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_3, CONF_SIDE_2): 6003,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_3, CONF_SIDE_4): 4003,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_3, CONF_SIDE_5): 1003,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_3, CONF_SIDE_6): 5003,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_4, CONF_SIDE_1): 2004,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_4, CONF_SIDE_2): 6004,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_4, CONF_SIDE_3): 3004,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_4, CONF_SIDE_5): 1004,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_4, CONF_SIDE_6): 5004,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_5, CONF_SIDE_1): 2001,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_5, CONF_SIDE_2): 6001,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_5, CONF_SIDE_3): 3001,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_5, CONF_SIDE_4): 4001,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_5, CONF_SIDE_6): 5001,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_6, CONF_SIDE_1): 2005,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_6, CONF_SIDE_2): 6005,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_6, CONF_SIDE_3): 3005,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_6, CONF_SIDE_4): 4005,
|
|
|
|
(CONF_ROTATE_FROM_SIDE_6, CONF_SIDE_5): 1005,
|
|
|
|
(CONF_MOVE, CONF_SIDE_1): 2000,
|
|
|
|
(CONF_MOVE, CONF_SIDE_2): 6000,
|
|
|
|
(CONF_MOVE, CONF_SIDE_3): 3000,
|
|
|
|
(CONF_MOVE, CONF_SIDE_4): 4000,
|
|
|
|
(CONF_MOVE, CONF_SIDE_5): 1000,
|
|
|
|
(CONF_MOVE, CONF_SIDE_6): 5000,
|
|
|
|
(CONF_DOUBLE_TAP, CONF_SIDE_1): 2002,
|
|
|
|
(CONF_DOUBLE_TAP, CONF_SIDE_2): 6002,
|
|
|
|
(CONF_DOUBLE_TAP, CONF_SIDE_3): 3003,
|
|
|
|
(CONF_DOUBLE_TAP, CONF_SIDE_4): 4004,
|
|
|
|
(CONF_DOUBLE_TAP, CONF_SIDE_5): 1001,
|
|
|
|
(CONF_DOUBLE_TAP, CONF_SIDE_6): 5005,
|
|
|
|
(CONF_AWAKE, ""): 7000,
|
|
|
|
(CONF_FREE_FALL, ""): 7008,
|
|
|
|
(CONF_SHAKE, ""): 7007,
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:56:28 +00:00
|
|
|
AQARA_DOUBLE_WALL_SWITCH_MODEL = "lumi.remote.b286acn01"
|
|
|
|
AQARA_DOUBLE_WALL_SWITCH = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_LEFT): 1002,
|
|
|
|
(CONF_LONG_PRESS, CONF_LEFT): 1001,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_LEFT): 1004,
|
|
|
|
(CONF_SHORT_PRESS, CONF_RIGHT): 2002,
|
|
|
|
(CONF_LONG_PRESS, CONF_RIGHT): 2001,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_RIGHT): 2004,
|
|
|
|
(CONF_SHORT_PRESS, CONF_BOTH_BUTTONS): 3002,
|
|
|
|
(CONF_LONG_PRESS, CONF_BOTH_BUTTONS): 3001,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_BOTH_BUTTONS): 3004,
|
|
|
|
}
|
|
|
|
|
2019-11-14 18:15:08 +00:00
|
|
|
AQARA_DOUBLE_WALL_SWITCH_WXKG02LM_MODEL = "lumi.sensor_86sw2"
|
|
|
|
AQARA_DOUBLE_WALL_SWITCH_WXKG02LM = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_LEFT): 1002,
|
|
|
|
(CONF_SHORT_PRESS, CONF_RIGHT): 2002,
|
|
|
|
(CONF_SHORT_PRESS, CONF_BOTH_BUTTONS): 3002,
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:56:28 +00:00
|
|
|
AQARA_MINI_SWITCH_MODEL = "lumi.remote.b1acn01"
|
|
|
|
AQARA_MINI_SWITCH = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_TURN_ON): 1004,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_ON): 1001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_ON): 1003,
|
|
|
|
}
|
|
|
|
|
|
|
|
AQARA_ROUND_SWITCH_MODEL = "lumi.sensor_switch"
|
|
|
|
AQARA_ROUND_SWITCH = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1000,
|
|
|
|
(CONF_SHORT_RELEASE, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_TURN_ON): 1004,
|
|
|
|
(CONF_TRIPLE_PRESS, CONF_TURN_ON): 1005,
|
|
|
|
(CONF_QUADRUPLE_PRESS, CONF_TURN_ON): 1006,
|
|
|
|
(CONF_QUINTUPLE_PRESS, CONF_TURN_ON): 1010,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_ON): 1001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_ON): 1003,
|
|
|
|
}
|
|
|
|
|
|
|
|
AQARA_SQUARE_SWITCH_MODEL = "lumi.sensor_switch.aq3"
|
|
|
|
AQARA_SQUARE_SWITCH = {
|
|
|
|
(CONF_SHORT_PRESS, CONF_TURN_ON): 1002,
|
|
|
|
(CONF_DOUBLE_PRESS, CONF_TURN_ON): 1004,
|
|
|
|
(CONF_LONG_PRESS, CONF_TURN_ON): 1001,
|
|
|
|
(CONF_LONG_RELEASE, CONF_TURN_ON): 1003,
|
|
|
|
(CONF_SHAKE, ""): 1007,
|
|
|
|
}
|
|
|
|
|
|
|
|
REMOTES = {
|
2019-11-01 22:06:29 +00:00
|
|
|
HUE_DIMMER_REMOTE_MODEL_GEN1: HUE_DIMMER_REMOTE,
|
|
|
|
HUE_DIMMER_REMOTE_MODEL_GEN2: HUE_DIMMER_REMOTE,
|
2019-09-10 23:56:28 +00:00
|
|
|
HUE_TAP_REMOTE_MODEL: HUE_TAP_REMOTE,
|
2019-10-02 20:12:59 +00:00
|
|
|
SYMFONISK_SOUND_CONTROLLER_MODEL: SYMFONISK_SOUND_CONTROLLER,
|
2019-09-10 23:56:28 +00:00
|
|
|
TRADFRI_ON_OFF_SWITCH_MODEL: TRADFRI_ON_OFF_SWITCH,
|
|
|
|
TRADFRI_OPEN_CLOSE_REMOTE_MODEL: TRADFRI_OPEN_CLOSE_REMOTE,
|
|
|
|
TRADFRI_REMOTE_MODEL: TRADFRI_REMOTE,
|
|
|
|
TRADFRI_WIRELESS_DIMMER_MODEL: TRADFRI_WIRELESS_DIMMER,
|
2019-11-01 21:29:34 +00:00
|
|
|
AQARA_CUBE_MODEL: AQARA_CUBE,
|
2019-09-10 23:56:28 +00:00
|
|
|
AQARA_DOUBLE_WALL_SWITCH_MODEL: AQARA_DOUBLE_WALL_SWITCH,
|
2019-11-14 18:15:08 +00:00
|
|
|
AQARA_DOUBLE_WALL_SWITCH_WXKG02LM_MODEL: AQARA_DOUBLE_WALL_SWITCH_WXKG02LM,
|
2019-09-10 23:56:28 +00:00
|
|
|
AQARA_MINI_SWITCH_MODEL: AQARA_MINI_SWITCH,
|
|
|
|
AQARA_ROUND_SWITCH_MODEL: AQARA_ROUND_SWITCH,
|
|
|
|
AQARA_SQUARE_SWITCH_MODEL: AQARA_SQUARE_SWITCH,
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:57:05 +00:00
|
|
|
TRIGGER_SCHEMA = TRIGGER_BASE_SCHEMA.extend(
|
|
|
|
{vol.Required(CONF_TYPE): str, vol.Required(CONF_SUBTYPE): str}
|
2019-09-10 23:56:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _get_deconz_event_from_device_id(hass, device_id):
|
|
|
|
"""Resolve deconz event from device id."""
|
|
|
|
deconz_config_entries = configured_gateways(hass)
|
|
|
|
for config_entry in deconz_config_entries.values():
|
|
|
|
|
|
|
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
|
|
|
for deconz_event in gateway.events:
|
|
|
|
|
|
|
|
if device_id == deconz_event.device_id:
|
|
|
|
return deconz_event
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2019-10-09 19:04:11 +00:00
|
|
|
async def async_validate_trigger_config(hass, config):
|
|
|
|
"""Validate config."""
|
|
|
|
config = TRIGGER_SCHEMA(config)
|
|
|
|
|
2019-09-10 23:56:28 +00:00
|
|
|
device_registry = await hass.helpers.device_registry.async_get_registry()
|
|
|
|
device = device_registry.async_get(config[CONF_DEVICE_ID])
|
|
|
|
|
|
|
|
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
|
|
|
|
2019-10-02 20:12:59 +00:00
|
|
|
if device.model not in REMOTES or trigger not in REMOTES[device.model]:
|
2019-09-10 23:56:28 +00:00
|
|
|
raise InvalidDeviceAutomationConfig
|
|
|
|
|
2019-10-09 19:04:11 +00:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
async def async_attach_trigger(hass, config, action, automation_info):
|
|
|
|
"""Listen for state changes based on configuration."""
|
|
|
|
device_registry = await hass.helpers.device_registry.async_get_registry()
|
|
|
|
device = device_registry.async_get(config[CONF_DEVICE_ID])
|
|
|
|
|
|
|
|
trigger = (config[CONF_TYPE], config[CONF_SUBTYPE])
|
|
|
|
|
2019-09-10 23:56:28 +00:00
|
|
|
trigger = REMOTES[device.model][trigger]
|
|
|
|
|
|
|
|
deconz_event = _get_deconz_event_from_device_id(hass, device.id)
|
|
|
|
if deconz_event is None:
|
|
|
|
raise InvalidDeviceAutomationConfig
|
|
|
|
|
|
|
|
event_id = deconz_event.serial
|
|
|
|
|
2019-10-07 20:09:48 +00:00
|
|
|
event_config = {
|
2019-10-25 20:40:05 +00:00
|
|
|
event.CONF_PLATFORM: "event",
|
2019-09-10 23:56:28 +00:00
|
|
|
event.CONF_EVENT_TYPE: CONF_DECONZ_EVENT,
|
|
|
|
event.CONF_EVENT_DATA: {CONF_UNIQUE_ID: event_id, CONF_EVENT: trigger},
|
|
|
|
}
|
|
|
|
|
2019-10-07 20:09:48 +00:00
|
|
|
event_config = event.TRIGGER_SCHEMA(event_config)
|
2019-09-24 21:57:05 +00:00
|
|
|
return await event.async_attach_trigger(
|
2019-10-07 20:09:48 +00:00
|
|
|
hass, event_config, action, automation_info, platform_type="device"
|
2019-09-24 21:57:05 +00:00
|
|
|
)
|
2019-09-10 23:56:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_get_triggers(hass, device_id):
|
|
|
|
"""List device triggers.
|
|
|
|
|
|
|
|
Make sure device is a supported remote model.
|
|
|
|
Retrieve the deconz event object matching device entry.
|
|
|
|
Generate device trigger list.
|
|
|
|
"""
|
|
|
|
device_registry = await hass.helpers.device_registry.async_get_registry()
|
|
|
|
device = device_registry.async_get(device_id)
|
|
|
|
|
|
|
|
if device.model not in REMOTES:
|
|
|
|
return
|
|
|
|
|
|
|
|
triggers = []
|
|
|
|
for trigger, subtype in REMOTES[device.model].keys():
|
|
|
|
triggers.append(
|
|
|
|
{
|
|
|
|
CONF_DEVICE_ID: device_id,
|
|
|
|
CONF_DOMAIN: DOMAIN,
|
|
|
|
CONF_PLATFORM: "device",
|
|
|
|
CONF_TYPE: trigger,
|
|
|
|
CONF_SUBTYPE: subtype,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return triggers
|