Reorganize trigger code (#38655)

This commit is contained in:
Phil Bruckner authored and GitHub committed 2020-08-17 11:54:56 -05:00
1 parent fca071742d
commit ca9dd0c833
51 files changed
+306 -194

No files matched your search

@@ -1,12 +1,12 @@
"""Provides device triggers for binary sensors."""
import voluptuous as vol
from homeassistant.components.automation import state as state_automation
from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
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_DEVICE_CLASS, CONF_ENTITY_ID, CONF_FOR, CONF_TYPE
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_registry import async_entries_for_device
@@ -197,16 +197,16 @@ async def async_attach_trigger(hass, config, action, automation_info):
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,
state_trigger.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"
)