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,12 +3,12 @@ from typing import List
import voluptuous as vol
from homeassistant.components.automation import (
AutomationActionType,
numeric_state as numeric_state_automation,
state as state_automation,
)
from homeassistant.components.automation import AutomationActionType
from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
from homeassistant.components.homeassistant.triggers import (
numeric_state as numeric_state_trigger,
state as state_trigger,
)
from homeassistant.const import (
ATTR_SUPPORTED_FEATURES,
CONF_ABOVE,
@ -18,6 +18,7 @@ from homeassistant.const import (
CONF_ENTITY_ID,
CONF_PLATFORM,
CONF_TYPE,
CONF_VALUE_TEMPLATE,
STATE_CLOSED,
STATE_CLOSING,
STATE_OPEN,
@ -182,12 +183,12 @@ async def async_attach_trigger(
to_state = STATE_CLOSING
state_config = {
state_automation.CONF_PLATFORM: "state",
CONF_PLATFORM: "state",
CONF_ENTITY_ID: config[CONF_ENTITY_ID],
state_automation.CONF_TO: to_state,
state_trigger.CONF_TO: to_state,
}
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"
)
@ -200,13 +201,13 @@ async def async_attach_trigger(
value_template = f"{{{{ state.attributes.{position} }}}}"
numeric_state_config = {
numeric_state_automation.CONF_PLATFORM: "numeric_state",
numeric_state_automation.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
numeric_state_automation.CONF_BELOW: max_pos,
numeric_state_automation.CONF_ABOVE: min_pos,
numeric_state_automation.CONF_VALUE_TEMPLATE: value_template,
CONF_PLATFORM: "numeric_state",
CONF_ENTITY_ID: config[CONF_ENTITY_ID],
CONF_BELOW: max_pos,
CONF_ABOVE: min_pos,
CONF_VALUE_TEMPLATE: value_template,
}
numeric_state_config = numeric_state_automation.TRIGGER_SCHEMA(numeric_state_config)
return await numeric_state_automation.async_attach_trigger(
numeric_state_config = numeric_state_trigger.TRIGGER_SCHEMA(numeric_state_config)
return await numeric_state_trigger.async_attach_trigger(
hass, numeric_state_config, action, automation_info, platform_type="device"
)