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