]> git.basschouten.com Git - openhab-addons.git/commitdiff
[wled] Fix: FX and Palettes channel StateDescriptionProvider handling (#17277)
authorStefan Triller <t2000@users.noreply.github.com>
Sun, 18 Aug 2024 15:27:33 +0000 (17:27 +0200)
committerGitHub <noreply@github.com>
Sun, 18 Aug 2024 15:27:33 +0000 (17:27 +0200)
* [wled] Fix: FX and Palettes channel StateDescriptionProvider handling

Fixes #17276

Signed-off-by: Stefan Triller <github@stefantriller.de>
bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/handlers/WLedSegmentHandler.java

index 3bb92de950357d5b704c3ec0b719fae13d82e8e6..015a7c2067d4e3e8767ca375633d30db595db7da 100644 (file)
@@ -33,6 +33,7 @@ import org.openhab.core.thing.ChannelUID;
 import org.openhab.core.thing.Thing;
 import org.openhab.core.thing.ThingStatus;
 import org.openhab.core.thing.ThingStatusDetail;
+import org.openhab.core.thing.ThingStatusInfo;
 import org.openhab.core.thing.binding.BaseThingHandler;
 import org.openhab.core.thing.binding.builder.ThingBuilder;
 import org.openhab.core.types.Command;
@@ -254,10 +255,7 @@ public class WLedSegmentHandler extends BaseThingHandler {
             WledApi localAPI = localBridgeHandler.api;
             if (localAPI != null) {
                 updateStatus(ThingStatus.ONLINE);
-                localBridgeHandler.stateDescriptionProvider
-                        .setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_FX), localAPI.getUpdatedFxList());
-                localBridgeHandler.stateDescriptionProvider.setStateOptions(
-                        new ChannelUID(getThing().getUID(), CHANNEL_PALETTES), localAPI.getUpdatedPaletteList());
+                updateStateDescriptionProviders();
                 if (!localBridgeHandler.hasWhite) {
                     logger.debug("WLED is not setup to use RGBW, so removing un-needed white channels");
                     removeWhiteChannels();
@@ -267,4 +265,31 @@ public class WLedSegmentHandler extends BaseThingHandler {
             }
         }
     }
+
+    private void updateStateDescriptionProviders() {
+        Bridge bridge = getBridge();
+        if (bridge != null) {
+            WLedBridgeHandler localBridgeHandler = (WLedBridgeHandler) bridge.getHandler();
+            if (localBridgeHandler != null) {
+                WledApi localAPI = localBridgeHandler.api;
+                if (localAPI != null) {
+                    localBridgeHandler.stateDescriptionProvider.setStateOptions(
+                            new ChannelUID(getThing().getUID(), CHANNEL_FX), localAPI.getUpdatedFxList());
+                    localBridgeHandler.stateDescriptionProvider.setStateOptions(
+                            new ChannelUID(getThing().getUID(), CHANNEL_PALETTES), localAPI.getUpdatedPaletteList());
+                }
+            }
+        }
+    }
+
+    @Override
+    public void bridgeStatusChanged(ThingStatusInfo bridgeStatusInfo) {
+        super.bridgeStatusChanged(bridgeStatusInfo);
+
+        if (ThingStatus.ONLINE.equals(bridgeStatusInfo.getStatus())) {
+            // if the handler has been started before the WLED controller is available, we have to fill the providers
+            // again once the bridge goes ONLINE
+            updateStateDescriptionProviders();
+        }
+    }
 }