33
33
import org .openhab .core .thing .Thing ;
34
34
import org .openhab .core .thing .ThingStatus ;
35
35
import org .openhab .core .thing .ThingStatusDetail ;
36
+ import org .openhab .core .thing .ThingStatusInfo ;
36
37
import org .openhab .core .thing .binding .BaseThingHandler ;
37
38
import org .openhab .core .thing .binding .builder .ThingBuilder ;
38
39
import org .openhab .core .types .Command ;
@@ -254,10 +255,7 @@ public void initialize() {
254
255
WledApi localAPI = localBridgeHandler .api ;
255
256
if (localAPI != null ) {
256
257
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 ();
261
259
if (!localBridgeHandler .hasWhite ) {
262
260
logger .debug ("WLED is not setup to use RGBW, so removing un-needed white channels" );
263
261
removeWhiteChannels ();
@@ -267,4 +265,31 @@ public void initialize() {
267
265
}
268
266
}
269
267
}
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
+ }
270
295
}
0 commit comments