Reorganize trigger code (#38655)

This commit is contained in:
Phil Bruckner 2020-08-17 11:54:56 -05:00 committed by GitHub
parent fca071742d
commit ca9dd0c833
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 306 additions and 194 deletions

View file

@ -3,10 +3,7 @@ from typing import Any, Dict, List
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
state as state_automation,
)
from homeassistant.components.automation import AutomationActionType
from homeassistant.components.device_automation.const import (
CONF_IS_OFF,
CONF_IS_ON,
@ -16,6 +13,7 @@ from homeassistant.components.device_automation.const import (
CONF_TURNED_OFF,
CONF_TURNED_ON,
)
from homeassistant.components.homeassistant.triggers import state as state_trigger
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_CONDITION,
@ -157,16 +155,16 @@ async def async_attach_trigger(
from_state = "on"
to_state = "off"
state_config = {
state_automation.CONF_PLATFORM: "state",
state_automation.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
state_automation.CONF_FROM: from_state,
state_automation.CONF_TO: to_state,
CONF_PLATFORM: "state",
state_trigger.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
state_trigger.CONF_FROM: from_state,
state_trigger.CONF_TO: to_state,
}
if CONF_FOR in config:
state_config[CONF_FOR] = config[CONF_FOR]
state_config = state_automation.TRIGGER_SCHEMA(state_config)
return await state_automation.async_attach_trigger(
state_config = state_trigger.TRIGGER_SCHEMA(state_config)
return await state_trigger.async_attach_trigger(
hass, state_config, action, automation_info, platform_type="device"
)