Add option to set retained config to /set topic #677
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.
It's useful when:
Example:
I'm using this library in a ESP32 connected to a Controllino Maxi via Serial, they communicate with Json payloads, ESP32 stores the state of Controllino as "virtual" state.
ESP32 "virtual" state does not matter, it's there only for code convenience, Controllino will always override it.
Controllino has many things controlled, it can change the state of controlled devices
ESP32 will configure it's name and nodes in setup() and will act as a bidirectional forwarder of states in loop().
I don't need the state to be restored upon power loss or reboot because:
I want the /set topic to be always aligned with the current state of Controllino, since the /set topic is only set when a "Homie Controller" wants to change the state of Controllino remotely I'm using
overwriteSetter(true)
method to override it when Controllino state changes on its own.If ESP32 reboots (for whatever reason) it will automatically read the retained /set state ond forward it to Controllino, it can be avoided if /set topic is not retained, so I added
setSetRetained(bool retain)
method to SendingPromise.To use this setup I created a custom HomieNode derived class that, among other things, stores
bool setTopicState
and this send method (very simplified and ugly version) that sends the new state to MQTTClearly the callBack method must be modified to ignore the callback if /set is ==
bool setTopicState
An ugly simplifed example: