Script mode fix (#1238)

This commit is contained in:
Jesse Hills 2020-08-07 03:08:48 +12:00 committed by GitHub
parent 009cea1abf
commit fd6ac529fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View file

@ -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))

View file

@ -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;
} }

View file

@ -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: