mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 21:10:25 +00:00
Reorganize trigger code (#38655)
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
"""Provides device triggers for sensors."""
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.components.automation.numeric_state as numeric_state_automation
|
||||
from homeassistant.components.device_automation import TRIGGER_BASE_SCHEMA
|
||||
from homeassistant.components.device_automation.exceptions import (
|
||||
InvalidDeviceAutomationConfig,
|
||||
)
|
||||
from homeassistant.components.homeassistant.triggers import (
|
||||
numeric_state as numeric_state_trigger,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
@@ -100,18 +102,18 @@ TRIGGER_SCHEMA = vol.All(
|
||||
async def async_attach_trigger(hass, config, action, automation_info):
|
||||
"""Listen for state changes based on configuration."""
|
||||
numeric_state_config = {
|
||||
numeric_state_automation.CONF_PLATFORM: "numeric_state",
|
||||
numeric_state_automation.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
|
||||
numeric_state_trigger.CONF_PLATFORM: "numeric_state",
|
||||
numeric_state_trigger.CONF_ENTITY_ID: config[CONF_ENTITY_ID],
|
||||
}
|
||||
if CONF_ABOVE in config:
|
||||
numeric_state_config[numeric_state_automation.CONF_ABOVE] = config[CONF_ABOVE]
|
||||
numeric_state_config[numeric_state_trigger.CONF_ABOVE] = config[CONF_ABOVE]
|
||||
if CONF_BELOW in config:
|
||||
numeric_state_config[numeric_state_automation.CONF_BELOW] = config[CONF_BELOW]
|
||||
numeric_state_config[numeric_state_trigger.CONF_BELOW] = config[CONF_BELOW]
|
||||
if CONF_FOR in config:
|
||||
numeric_state_config[CONF_FOR] = config[CONF_FOR]
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user