[New Feature] Add command SwitchText
to change switches names in JSON
#9691
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.
Description:
New feature introduce a new command
SwitchText
to replace the default "Switchn" name in the JSON messages by a custom meaningful text. Usefull when "Switch" inputs are used as general purpose digital input sensor (such door state, battery charging status...)The command and associated code is inserted only if
USE_SWITCHTEXT
is defined.When
USE_SWITCHTEXT
is not defined the only impact is 8 (MAX_SWITCHES
) zero-length strings are reservedinto
Settings.text_pool
.When a binary with
USE_SWITCHTEXT
is loaded for the 1st time, eachSET_SWITCH_TXT<n>
text setting is a zero-lengthstring. The JSON messages then use the default "Switchn" name.
Once
SwitchText<n>
has been used to defined a name, it is saved in the settings and further JSON messages will usethe custom name.
If a binary without
USE_SWITCHTEXT
is loaded after someSwitchText<n>
have been defined, they remains as-is in thetext setting pool and JSON messages revert to legacy "Switchn" names.
SwitchText
command syntax is similar to theStateText
command:SwitchText
: returns all 8SwitchText
valuesSwitchText<x>
: returns the matchingSwitchText
value (where <x> is a number between 1 and 8)SwitchText<x> <text>
: defines <text> as the new name for "Switchx"Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass