Add device automation action (#26455)

* Add support for device actions, with light as example.

* Add translation; return list
This commit is contained in:
Erik Montnemery authored and Paulus Schoutsen committed 2019-09-05 16:26:22 -07:00
1 parent 23fdc04554
commit b1c2a5fa08
8 files changed
+274 -2

No files matched your search

@@ -20,6 +20,9 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup(hass, config):
"""Set up device automation."""
hass.components.websocket_api.async_register_command(
websocket_device_automation_list_actions
)
hass.components.websocket_api.async_register_command(
websocket_device_automation_list_conditions
)
@@ -93,6 +96,20 @@ async def _async_get_device_automations(hass, fname, device_id):
return automations
@websocket_api.async_response
@websocket_api.websocket_command(
{
vol.Required("type"): "device_automation/action/list",
vol.Required("device_id"): str,
}
)
async def websocket_device_automation_list_actions(hass, connection, msg):
"""Handle request for device actions."""
device_id = msg["device_id"]
actions = await _async_get_device_automations(hass, "async_get_actions", device_id)
connection.send_result(msg["id"], actions)
@websocket_api.async_response
@websocket_api.websocket_command(
{
@@ -1,5 +1,6 @@
"""Constants for device automations."""
CONF_IS_OFF = "is_off"
CONF_IS_ON = "is_on"
CONF_TOGGLE = "toggle"
CONF_TURN_OFF = "turn_off"
CONF_TURN_ON = "turn_on"