Command scheduling, event handling improvements #649
+186
−46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the second part of my PR (#631), which was previously reverted to remove changes unrelated to PC port.
This PR adds the following features:
schedule
command, which allows to run another command at a set interval. Any supported command can be executed. It has the following syntax:schedule set <id> <period(ms) <cmd...>
- add/update a scheduled taskid
is a user-chosen integer identifier of the taskperiod
is the interval in millisecondscmd
is the command to run; it can consist of multiple space-separated wordsschedule del <id>
- remove a previously scheduled taskschedule start <id>
- start (enable) a previously scheduled task (enabled by default)schedule stop <id>
- stop (disable) a previously scheduled task, without removing it%var%
tags in commands of objects'"action"
field with a value from the event JSON. For example, this jsonl:will update the label's text whenever the slider emits a
changed
event. Any supported command can be executed, and any value from the JSON event can be used in substitution.NOTE: That feature is disabled by default on non-PC builds, not to impact performance/memory usage on ESP32/Arduino builds. In particular, it requires deserialization of the JSON event prior to publishing, as well as running
std::string::replace()
a few times. It can be enabled usingHASP_USE_EVENT_DATA_SUBST=1
."action"
on all types of controls - previously, only a few controls allowed to run commands on events (script_event_handler()
). Now, all controls callevent_send_object_data()
only, which then callsscript_event_handler()
.If there is an
"action"
tag on the object, the command is executed and MQTT message is not published.An example can be seen above (with the slider).
"action"
tag of an object has an additional property"pub": true
, the action command is ran AND a message is published to MQTT.This property defaults to
false
, which matches the behavior from previous versions.Example:
This slider's events will be published to MQTT, additionally the
changed
event will run a command.I have one more "feature" that was left out of #631, that is setting LVGL max framerate. If you want, I can add it to this PR, otherwise I will probably create another one.