Skip to content

Commit d158209

Browse files
authored
[wled] Fix: FX and Palettes channel StateDescriptionProvider handling (#17277)
* [wled] Fix: FX and Palettes channel StateDescriptionProvider handling Fixes #17276 Signed-off-by: Stefan Triller <[email protected]>
1 parent 04d87ad commit d158209

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/handlers/WLedSegmentHandler.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.openhab.core.thing.Thing;
3434
import org.openhab.core.thing.ThingStatus;
3535
import org.openhab.core.thing.ThingStatusDetail;
36+
import org.openhab.core.thing.ThingStatusInfo;
3637
import org.openhab.core.thing.binding.BaseThingHandler;
3738
import org.openhab.core.thing.binding.builder.ThingBuilder;
3839
import org.openhab.core.types.Command;
@@ -254,10 +255,7 @@ public void initialize() {
254255
WledApi localAPI = localBridgeHandler.api;
255256
if (localAPI != null) {
256257
updateStatus(ThingStatus.ONLINE);
257-
localBridgeHandler.stateDescriptionProvider
258-
.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_FX), localAPI.getUpdatedFxList());
259-
localBridgeHandler.stateDescriptionProvider.setStateOptions(
260-
new ChannelUID(getThing().getUID(), CHANNEL_PALETTES), localAPI.getUpdatedPaletteList());
258+
updateStateDescriptionProviders();
261259
if (!localBridgeHandler.hasWhite) {
262260
logger.debug("WLED is not setup to use RGBW, so removing un-needed white channels");
263261
removeWhiteChannels();
@@ -267,4 +265,31 @@ public void initialize() {
267265
}
268266
}
269267
}
268+
269+
private void updateStateDescriptionProviders() {
270+
Bridge bridge = getBridge();
271+
if (bridge != null) {
272+
WLedBridgeHandler localBridgeHandler = (WLedBridgeHandler) bridge.getHandler();
273+
if (localBridgeHandler != null) {
274+
WledApi localAPI = localBridgeHandler.api;
275+
if (localAPI != null) {
276+
localBridgeHandler.stateDescriptionProvider.setStateOptions(
277+
new ChannelUID(getThing().getUID(), CHANNEL_FX), localAPI.getUpdatedFxList());
278+
localBridgeHandler.stateDescriptionProvider.setStateOptions(
279+
new ChannelUID(getThing().getUID(), CHANNEL_PALETTES), localAPI.getUpdatedPaletteList());
280+
}
281+
}
282+
}
283+
}
284+
285+
@Override
286+
public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
287+
super.bridgeStatusChanged(bridgeStatusInfo);
288+
289+
if (ThingStatus.ONLINE.equals(bridgeStatusInfo.getStatus())) {
290+
// if the handler has been started before the WLED controller is available, we have to fill the providers
291+
// again once the bridge goes ONLINE
292+
updateStateDescriptionProviders();
293+
}
294+
}
270295
}

0 commit comments

Comments
 (0)