HA discovery: expire discovery topics after 30 minutes, re-publish them in regular intervals #79
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.
Hi,
this is a small improvement on the HA discovery implementation.
Right now, the discovery topics are "retain"ed. This is needed, so that HA still finds them after a restart.
However, it has the drawback, that these topics will never ever be deleted, e.g. when the parameters.json is updated, the device is renamed, etc.
In cases like that, users need to manually delete the leftover discovery topics.
This PR switches to MQTT v5, which allows setting an expiry timeout for publishes, and does just that:
This way, HA will always find the topics as long as ism7mqtt is running/was running recently, but when topics disappear, HA will pick that up after some time and remove the stale entities.
Again, feel free to do coding style changes if needed - not really a C# expert.