This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -4,36 +4,45 @@ import voluptuous as vol
import homeassistant.components.automation.state as state
from homeassistant.core import split_entity_id
from homeassistant.const import (
CONF_DEVICE_ID, CONF_DOMAIN, CONF_ENTITY_ID, CONF_PLATFORM, CONF_TYPE)
CONF_DEVICE_ID,
CONF_DOMAIN,
CONF_ENTITY_ID,
CONF_PLATFORM,
CONF_TYPE,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_registry import async_entries_for_device
from . import DOMAIN
CONF_TURN_OFF = 'turn_off'
CONF_TURN_ON = 'turn_on'
CONF_TURN_OFF = "turn_off"
CONF_TURN_ON = "turn_on"
ENTITY_TRIGGERS = [
{
# Trigger when light is turned on
CONF_PLATFORM: 'device',
CONF_PLATFORM: "device",
CONF_DOMAIN: DOMAIN,
CONF_TYPE: CONF_TURN_OFF,
},
{
# Trigger when light is turned off
CONF_PLATFORM: 'device',
CONF_PLATFORM: "device",
CONF_DOMAIN: DOMAIN,
CONF_TYPE: CONF_TURN_ON,
},
]
TRIGGER_SCHEMA = vol.All(vol.Schema({
vol.Required(CONF_PLATFORM): 'device',
vol.Optional(CONF_DEVICE_ID): str,
vol.Required(CONF_DOMAIN): DOMAIN,
vol.Required(CONF_ENTITY_ID): cv.entity_id,
vol.Required(CONF_TYPE): str,
}))
TRIGGER_SCHEMA = vol.All(
vol.Schema(
{
vol.Required(CONF_PLATFORM): "device",
vol.Optional(CONF_DEVICE_ID): str,
vol.Required(CONF_DOMAIN): DOMAIN,
vol.Required(CONF_ENTITY_ID): cv.entity_id,
vol.Required(CONF_TYPE): str,
}
)
)
def _is_domain(entity, domain):
@ -44,19 +53,18 @@ async def async_attach_trigger(hass, config, action, automation_info):
"""Listen for state changes based on configuration."""
trigger_type = config.get(CONF_TYPE)
if trigger_type == CONF_TURN_ON:
from_state = 'off'
to_state = 'on'
from_state = "off"
to_state = "on"
else:
from_state = 'on'
to_state = 'off'
from_state = "on"
to_state = "off"
state_config = {
state.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
state.CONF_FROM: from_state,
state.CONF_TO: to_state
state.CONF_TO: to_state,
}
return await state.async_trigger(hass, state_config, action,
automation_info)
return await state.async_trigger(hass, state_config, action, automation_info)
async def async_trigger(hass, config, action, automation_info):