Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Feature] Add command SwitchText to change switches names in JSON #9691

Closed
wants to merge 1 commit into from
Closed

Conversation

barbudor
Copy link
Contributor

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 reserved
into Settings.text_pool.
When a binary with USE_SWITCHTEXT is loaded for the 1st time, each SET_SWITCH_TXT<n> text setting is a zero-length
string. 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 use
the custom name.
If a binary without USE_SWITCHTEXT is loaded after some SwitchText<n> have been defined, they remains as-is in the
text setting pool and JSON messages revert to legacy "Switchn" names.
SwitchText command syntax is similar to the StateText command:

  • SwitchText : returns all 8 SwitchText values
  • SwitchText<x> : returns the matching SwitchTextvalue (where <x> is a number between 1 and 8)
  • SwitchText<x> <text> : defines <text> as the new name for "Switchx"

Checklist:

  • The pull request is done against the latest dev branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR.
  • The code change is tested and works on Tasmota core ESP8266 V.2.7.4.5
  • The code change is tested and works on core ESP32 V.1.12.2
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

…ON (dependant on `USE_SWITCHTEXT`)

New feature intriduce new command `SwitchText`to replace the default "Switch*n*" 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 reserved
into `Settings.text_pool`.
When a binary with `USE_SWITCHTEXT` is loaded for the 1st time, each `SET_SWITCH_TXT*n*` text setting is a zero-length
string. The JSON messages then use the default "Switch*n*" name.
Once `SwitchText*n*`has been used to defined a name, it is saved in the settings and further JSON messages will use
the custom name.
If a binary without `USE_SWITCHTEXT` is loaded after some `SwitchText*n*` have been defined, they remains as-is in the
text setting pool and JSON Messages revert to legacy "Switch*n*" names.
`SwitchText` command syntaxes are similar to `StateText` command:
- `SwitchText` : returns all 8 `SwitchText` values
- `SwitchText*<x>*` : returns the matching `SwitchText`value (where *<x>* is a number between 1 and 8)
- `SwitchText*<x>* *<text>* : defines *<text>* as the new name for`"Switch*x*"
@barbudor
Copy link
Contributor Author

A little demo of the JSON when using this feature with 8 switches defined :

20:08:23 MQT: tele/dev-4119/SENSOR = {"Time":"2020-10-31T20:08:23+01:00","Charging":"ON","Charged":"ON","FrontDoorOpen":"ON","RearDoorOpen":"ON","FridgeDoorOpen":"ON","FreezerDorrOpen":"ON","GarageDoorOpen":"ON","YetAnotherStupidSwitchText":"OFF"}

@arendst
Copy link
Owner

arendst commented Nov 1, 2020

Nice thx. Will soon merge after my chk

arendst added a commit that referenced this pull request Nov 1, 2020
Add command ``SwitchText`` to change JSON switch names by barbudor (#9691)
@arendst
Copy link
Owner

arendst commented Nov 1, 2020

Thx. Implemented my way.

@arendst arendst closed this Nov 1, 2020
@barbudor
Copy link
Contributor Author

barbudor commented Nov 1, 2020

Thanks @arendst
Was the main reason for doing "your way" being that I didn't make the changes in the most appropriate place ?
Regards

@arendst
Copy link
Owner

arendst commented Nov 1, 2020

You almost had the most appropriate way ;-) but there were a few functions not needed. Also by consolidating the name decision in one function made both status and rule code less explosive.

Thx for your idea.

@barbudor barbudor deleted the pr-switchtext branch November 1, 2020 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants