-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[mqtt] Availability Topics are not subscribed to on Restart #9850
Labels
bug
An unexpected problem or unintended behavior of an add-on
Comments
albrechtf
added
the
bug
An unexpected problem or unintended behavior of an add-on
label
Jan 17, 2021
albrechtf
added a commit
to albrechtf/openhab-addons
that referenced
this issue
Jan 17, 2021
Signed-off-by: Florian Albrecht <[email protected]> Fixes openhab#9850
albrechtf
added a commit
to albrechtf/openhab-addons
that referenced
this issue
Jan 17, 2021
Signed-off-by: Florian Albrecht <[email protected]> Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]>
albrechtf
added a commit
to albrechtf/openhab-addons
that referenced
this issue
Jan 17, 2021
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]>
NickWaterton
pushed a commit
to NickWaterton/openhab-addons
that referenced
this issue
Dec 30, 2021
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]> Signed-off-by: Nick Waterton <[email protected]>
mischmidt83
pushed a commit
to mischmidt83/openhab-addons
that referenced
this issue
Jan 9, 2022
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]> Signed-off-by: Michael Schmidt <[email protected]>
nemerdaud
pushed a commit
to nemerdaud/openhab-addons
that referenced
this issue
Jan 28, 2022
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]>
marcfischerboschio
pushed a commit
to bosch-io/openhab-addons
that referenced
this issue
May 5, 2022
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]>
andan67
pushed a commit
to andan67/openhab-addons
that referenced
this issue
Nov 6, 2022
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]>
andrasU
pushed a commit
to andrasU/openhab-addons
that referenced
this issue
Nov 12, 2022
Fixes openhab#9850 Signed-off-by: Florian Albrecht <[email protected]> Signed-off-by: Andras Uhrin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
When configuring an Availability Topic for a Generic MQTT Thing and e.g. unplugging that thing, I expect openHAB to report this Thing as "OFFLINE" even after a restart of openHAB.
Current Behavior
With openHAB 3.0 (and also with previous versions), the availability topics are not correctly subscribed to, so that my device is reported as ONLINE although it is not available.
I traced this down to a potential "race condition", combined with, ahem, not ideal design in classes
AbstractMQTTThingHandler
andGenericMQTTThingHandler
. When starting up in normal speed, the following things happen (among other, non-MQTT related things), in this order:GenericMQTTThingHandler.initialize()
), and Availability Topic ChannelState is prepared (inAbstractMQTTThingHandler.addAvailabilityTopic()
). As no MQTT connection is yet available, nothing else happens. The ChannelStates would be started byAbstractMQTTThingHandler.bridgeStatusChanged()
as soon as connection is available.AbstractMQTTThingHandler.bridgeStatusChanged()
, which callsstop()
, which removes all ChannelStates for the Availability Topics!AbstractMQTTThingHandler.bridgeStatusChanged()
, which tries to start the ChannelStates of the Availability Topics, but the Map is now empty...Note that this bug in principle also applies when the Bridge itself REALLY turns OFFLINE, then ONLINE later. Afterwards, no (valid) Availability info would be present for Generic MQTT Things.
Here is the output of some log entries I temporarily added to the code, to prove this OFFLINE-ONLINE order on startup:
Possible Solution
There are at least two possible fixes for this:
GenericMQTTThingHandler.start()
. This is not completely clean, as it makes many assumptions about the concrete implementation inAbstractMQTTThingHandler
, but I already tried this solution, and it worked for me. There are some corner cases where a failure in subscribing to the availability topics may not be reported correctly.GenericMQTTThingHandler
andAbstractMQTTThingHandler
. Logic should be symmetrical (creation and removal of availability topic in same class), and currently, it is highly assymetrical. Also, all the explicit calls ofstop()
, along with the implicit calls from the framework, look very unclean. This would be a rather huge rework of both classes - nevertheless, may be worth the effort.Note that there are no Unit Tests for Availability Topics at all yet.
Steps to Reproduce (for Bugs)
Race-condition variant:
Slow-mo variant:
Your Environment
The text was updated successfully, but these errors were encountered: