mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 15:08:10 +01:00
Add wait_until action (#440)
This commit is contained in:
parent
10cc11bab1
commit
41d637affe
3 changed files with 28 additions and 1 deletions
|
@ -5,7 +5,7 @@ import voluptuous as vol
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ABOVE, CONF_ACTION_ID, CONF_AND, CONF_AUTOMATION_ID, \
|
from esphome.const import CONF_ABOVE, CONF_ACTION_ID, CONF_AND, CONF_AUTOMATION_ID, \
|
||||||
CONF_BELOW, CONF_CONDITION, CONF_CONDITION_ID, CONF_DELAY, CONF_ELSE, CONF_ID, CONF_IF, \
|
CONF_BELOW, CONF_CONDITION, CONF_CONDITION_ID, CONF_DELAY, CONF_ELSE, CONF_ID, CONF_IF, \
|
||||||
CONF_LAMBDA, CONF_OR, CONF_RANGE, CONF_THEN, CONF_TRIGGER_ID, CONF_WHILE
|
CONF_LAMBDA, CONF_OR, CONF_RANGE, CONF_THEN, CONF_TRIGGER_ID, CONF_WHILE, CONF_WAIT_UNTIL
|
||||||
from esphome.core import CORE
|
from esphome.core import CORE
|
||||||
from esphome.cpp_generator import Pvariable, TemplateArguments, add, get_variable, \
|
from esphome.cpp_generator import Pvariable, TemplateArguments, add, get_variable, \
|
||||||
process_lambda, templatable
|
process_lambda, templatable
|
||||||
|
@ -102,6 +102,7 @@ DelayAction = esphome_ns.class_('DelayAction', Action, Component)
|
||||||
LambdaAction = esphome_ns.class_('LambdaAction', Action)
|
LambdaAction = esphome_ns.class_('LambdaAction', Action)
|
||||||
IfAction = esphome_ns.class_('IfAction', Action)
|
IfAction = esphome_ns.class_('IfAction', Action)
|
||||||
WhileAction = esphome_ns.class_('WhileAction', Action)
|
WhileAction = esphome_ns.class_('WhileAction', Action)
|
||||||
|
WaitUntilAction = esphome_ns.class_('WaitUntilAction', Action, Component)
|
||||||
UpdateComponentAction = esphome_ns.class_('UpdateComponentAction', Action)
|
UpdateComponentAction = esphome_ns.class_('UpdateComponentAction', Action)
|
||||||
Automation = esphome_ns.class_('Automation')
|
Automation = esphome_ns.class_('Automation')
|
||||||
|
|
||||||
|
@ -268,6 +269,29 @@ def while_action_to_code(config, action_id, arg_type, template_arg):
|
||||||
yield action
|
yield action
|
||||||
|
|
||||||
|
|
||||||
|
def validate_wait_until(value):
|
||||||
|
schema = vol.Schema({
|
||||||
|
vol.Required(CONF_CONDITION): validate_recursive_condition
|
||||||
|
})
|
||||||
|
if isinstance(value, dict) and CONF_CONDITION in value:
|
||||||
|
return schema(value)
|
||||||
|
return validate_wait_until({CONF_CONDITION: value})
|
||||||
|
|
||||||
|
|
||||||
|
WAIT_UNTIL_ACTION_SCHEMA = validate_wait_until
|
||||||
|
|
||||||
|
|
||||||
|
@ACTION_REGISTRY.register(CONF_WAIT_UNTIL, WAIT_UNTIL_ACTION_SCHEMA)
|
||||||
|
def wait_until_action_to_code(config, action_id, arg_type, template_arg):
|
||||||
|
for conditions in build_conditions(config[CONF_CONDITION], arg_type):
|
||||||
|
yield None
|
||||||
|
rhs = WaitUntilAction.new(template_arg, conditions)
|
||||||
|
type = WaitUntilAction.template(template_arg)
|
||||||
|
action = Pvariable(action_id, rhs, type=type)
|
||||||
|
add(App.register_component(action))
|
||||||
|
yield action
|
||||||
|
|
||||||
|
|
||||||
LAMBDA_ACTION_SCHEMA = cv.lambda_
|
LAMBDA_ACTION_SCHEMA = cv.lambda_
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ CONF_BELOW = 'below'
|
||||||
CONF_ON = 'on'
|
CONF_ON = 'on'
|
||||||
CONF_IF = 'if'
|
CONF_IF = 'if'
|
||||||
CONF_WHILE = 'while'
|
CONF_WHILE = 'while'
|
||||||
|
CONF_WAIT_UNTIL = 'wait_until'
|
||||||
CONF_THEN = 'then'
|
CONF_THEN = 'then'
|
||||||
CONF_BINARY = 'binary'
|
CONF_BINARY = 'binary'
|
||||||
CONF_WHITE = 'white'
|
CONF_WHITE = 'white'
|
||||||
|
|
|
@ -194,6 +194,8 @@ sensor:
|
||||||
then:
|
then:
|
||||||
- lambda: >-
|
- lambda: >-
|
||||||
ESP_LOGD("main", "Got value range %f", x);
|
ESP_LOGD("main", "Got value range %f", x);
|
||||||
|
- wait_until:
|
||||||
|
binary_sensor.is_on: binary_sensor1
|
||||||
on_raw_value:
|
on_raw_value:
|
||||||
- lambda: >-
|
- lambda: >-
|
||||||
ESP_LOGD("main", "Got raw value %f", x);
|
ESP_LOGD("main", "Got raw value %f", x);
|
||||||
|
|
Loading…
Reference in a new issue