Add support for for to binary_sensor, light and switch device triggers (#26658)
* Add support for `for` to binary_sensor, light and switch device triggers * Add WS API device_automation/trigger/capabilities
This commit is contained in:
1 parent
d8c6b281b8
commit
65ce3b49c1
21 files changed
+495
-42
No files matched your search
@@ -7,7 +7,7 @@ from homeassistant.components.device_automation.const import (
|
||||
CONF_TURNED_OFF,
|
||||
CONF_TURNED_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, CONF_ENTITY_ID, CONF_TYPE
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS, CONF_ENTITY_ID, CONF_FOR, CONF_TYPE
|
||||
from homeassistant.helpers.entity_registry import async_entries_for_device
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
@@ -175,13 +175,13 @@ TRIGGER_SCHEMA = TRIGGER_BASE_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_ENTITY_ID): cv.entity_id,
|
||||
vol.Required(CONF_TYPE): vol.In(TURNED_OFF + TURNED_ON),
|
||||
vol.Optional(CONF_FOR): cv.positive_time_period_dict,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_attach_trigger(hass, config, action, automation_info):
|
||||
"""Listen for state changes based on configuration."""
|
||||
config = TRIGGER_SCHEMA(config)
|
||||
trigger_type = config[CONF_TYPE]
|
||||
if trigger_type in TURNED_ON:
|
||||
from_state = "off"
|
||||
@@ -195,6 +195,8 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
||||
state_automation.CONF_FROM: from_state,
|
||||
state_automation.CONF_TO: to_state,
|
||||
}
|
||||
if "for" in config:
|
||||
state_config["for"] = config["for"]
|
||||
|
||||
return await state_automation.async_attach_trigger(
|
||||
hass, state_config, action, automation_info, platform_type="device"
|
||||
@@ -236,3 +238,12 @@ async def async_get_triggers(hass, device_id):
|
||||
)
|
||||
|
||||
return triggers
|
||||
|
||||
|
||||
async def async_get_trigger_capabilities(hass, trigger):
|
||||
"""List trigger capabilities."""
|
||||
return {
|
||||
"extra_fields": vol.Schema(
|
||||
{vol.Optional(CONF_FOR): cv.positive_time_period_dict}
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user