mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Script mode fix (#1238)
This commit is contained in:
parent
5da9b2ede7
commit
dc4a88029c
3 changed files with 20 additions and 7 deletions
|
@ -18,14 +18,14 @@ ParallelScript = script_ns.class_('ParallelScript', Script)
|
|||
|
||||
CONF_SINGLE = 'single'
|
||||
CONF_RESTART = 'restart'
|
||||
CONF_QUEUE = 'queue'
|
||||
CONF_QUEUED = 'queued'
|
||||
CONF_PARALLEL = 'parallel'
|
||||
CONF_MAX_RUNS = 'max_runs'
|
||||
|
||||
SCRIPT_MODES = {
|
||||
CONF_SINGLE: SingleScript,
|
||||
CONF_RESTART: RestartScript,
|
||||
CONF_QUEUE: QueueingScript,
|
||||
CONF_QUEUED: QueueingScript,
|
||||
CONF_PARALLEL: ParallelScript,
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ SCRIPT_MODES = {
|
|||
def check_max_runs(value):
|
||||
if CONF_MAX_RUNS not in value:
|
||||
return value
|
||||
if value[CONF_MODE] not in [CONF_QUEUE, CONF_PARALLEL]:
|
||||
if value[CONF_MODE] not in [CONF_QUEUED, CONF_PARALLEL]:
|
||||
raise cv.Invalid("The option 'max_runs' is only valid in 'queue' and 'parallel' mode.",
|
||||
path=[CONF_MAX_RUNS])
|
||||
return value
|
||||
|
@ -65,7 +65,7 @@ def to_code(config):
|
|||
if CONF_MAX_RUNS in conf:
|
||||
cg.add(trigger.set_max_runs(conf[CONF_MAX_RUNS]))
|
||||
|
||||
if conf[CONF_MODE] == CONF_QUEUE:
|
||||
if conf[CONF_MODE] == CONF_QUEUED:
|
||||
yield cg.register_component(trigger, conf)
|
||||
|
||||
triggers.append((trigger, conf))
|
||||
|
|
|
@ -33,7 +33,7 @@ void QueueingScript::execute() {
|
|||
return;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Script '%s' queueing new instance (mode: queue)", this->name_.c_str());
|
||||
ESP_LOGD(TAG, "Script '%s' queueing new instance (mode: queued)", this->name_.c_str());
|
||||
this->num_runs_++;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -292,6 +292,21 @@ text_sensor:
|
|||
|
||||
script:
|
||||
- id: my_script
|
||||
mode: single
|
||||
then:
|
||||
- lambda: 'ESP_LOGD("main", "Hello World!");'
|
||||
- id: my_script_queued
|
||||
mode: queued
|
||||
max_runs: 2
|
||||
then:
|
||||
- lambda: 'ESP_LOGD("main", "Hello World!");'
|
||||
- id: my_script_parallel
|
||||
mode: parallel
|
||||
max_runs: 2
|
||||
then:
|
||||
- lambda: 'ESP_LOGD("main", "Hello World!");'
|
||||
- id: my_script_restart
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: 'ESP_LOGD("main", "Hello World!");'
|
||||
|
||||
|
@ -316,5 +331,3 @@ interval:
|
|||
- logger.log: "Interval Run"
|
||||
|
||||
display:
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue