-
-
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] Fix availability topics subscription after Brige Restart #9851
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,9 @@ public GenericMQTTThingHandler(Thing thing, MqttChannelStateDescriptionProvider | |
*/ | ||
@Override | ||
protected CompletableFuture<@Nullable Void> start(MqttBrokerConnection connection) { | ||
// availability topics are also started asynchronously, so no problem here | ||
clearAllAvailabilityTopics(); | ||
initializeAvailabilityTopicsFromConfig(); | ||
return channelStateByChannelUID.values().stream().map(c -> c.start(connection, scheduler, 0)) | ||
.collect(FutureCollector.allOf()).thenRun(this::calculateThingStatus); | ||
} | ||
|
@@ -142,15 +145,7 @@ protected ChannelState createChannelState(ChannelConfig channelConfig, ChannelUI | |
|
||
@Override | ||
public void initialize() { | ||
GenericThingConfiguration config = getConfigAs(GenericThingConfiguration.class); | ||
|
||
String availabilityTopic = config.availabilityTopic; | ||
|
||
if (availabilityTopic != null) { | ||
addAvailabilityTopic(availabilityTopic, config.payloadAvailable, config.payloadNotAvailable); | ||
} else { | ||
clearAllAvailabilityTopics(); | ||
} | ||
initializeAvailabilityTopicsFromConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can tell, due to your changes in You should also make changes in AbstractMQTTThingHandler.bridgeStatusChanged to make sure that the handler isn't offline due to config errors before it tries initializing a connection. |
||
|
||
List<ChannelUID> configErrors = new ArrayList<>(); | ||
for (Channel channel : thing.getChannels()) { | ||
|
@@ -194,4 +189,16 @@ protected void updateThingStatus(boolean messageReceived, Optional<Boolean> avai | |
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE); | ||
} | ||
} | ||
|
||
private void initializeAvailabilityTopicsFromConfig() { | ||
GenericThingConfiguration config = getConfigAs(GenericThingConfiguration.class); | ||
|
||
String availabilityTopic = config.availabilityTopic; | ||
|
||
if (availabilityTopic != null) { | ||
addAvailabilityTopic(availabilityTopic, config.payloadAvailable, config.payloadNotAvailable); | ||
} else { | ||
clearAllAvailabilityTopics(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if you made sure that the offline status would include the exception message, just like it did before.