]> git.basschouten.com Git - openhab-addons.git/commitdiff
[wled] add configuration to sort state options of channels effects and palettes ...
authorlordjaxom <sascha@akv-soft.de>
Wed, 15 Dec 2021 10:36:17 +0000 (11:36 +0100)
committerGitHub <noreply@github.com>
Wed, 15 Dec 2021 10:36:17 +0000 (11:36 +0100)
Signed-off-by: Sascha Volkenandt <sascha@akv-soft.de>
bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/WLedConfiguration.java
bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/WLedHandler.java
bundles/org.openhab.binding.wled/src/main/java/org/openhab/binding/wled/internal/api/WledApiV084.java
bundles/org.openhab.binding.wled/src/main/resources/OH-INF/thing/thing-types.xml

index 04d8d7b855121402605b335f9b7db7745f8612fd..2721dc5dfc4d0984abfdd7f87e80b525eba88f14 100644 (file)
@@ -25,4 +25,6 @@ public class WLedConfiguration {
     public int pollTime;
     public int segmentIndex;
     public int saturationThreshold;
+    public boolean sortEffects = false;
+    public boolean sortPalettes = false;
 }
index 7088441bcbc1d98fd0ea62aa6e06e3f24dd5c888..9a77d7fddff01afb72c074754a651ee6f5981400 100644 (file)
@@ -305,6 +305,7 @@ public class WLedHandler extends BaseThingHandler {
             future.cancel(true);
             pollingFuture = null;
         }
+        api = null; // re-initialize api after configuration change
     }
 
     @Override
index 2053928e67823a37be130d6b98fa526563bf1ede..4d3245af4cc366b8fa5df8fd1b9185a3b1551c9d 100644 (file)
@@ -17,6 +17,7 @@ import static org.openhab.binding.wled.internal.WLedBindingConstants.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -230,6 +231,9 @@ public class WledApiV084 implements WledApi {
         for (String value : state.jsonResponse.effects) {
             fxOptions.add(new StateOption(Integer.toString(counter++), value));
         }
+        if (handler.config.sortEffects) {
+            fxOptions.sort(Comparator.comparing(o -> o.getValue().equals("0") ? "" : o.getLabel()));
+        }
         handler.stateDescriptionProvider.setStateOptions(new ChannelUID(handler.getThing().getUID(), CHANNEL_FX),
                 fxOptions);
     }
@@ -240,6 +244,9 @@ public class WledApiV084 implements WledApi {
         for (String value : state.jsonResponse.palettes) {
             palleteOptions.add(new StateOption(Integer.toString(counter++), value));
         }
+        if (handler.config.sortPalettes) {
+            palleteOptions.sort(Comparator.comparing(o -> o.getValue().equals("0") ? "" : o.getLabel()));
+        }
         handler.stateDescriptionProvider.setStateOptions(new ChannelUID(handler.getThing().getUID(), CHANNEL_PALETTES),
                 palleteOptions);
     }
index 1d565066ff4d4afd0c2543cd709af66a59f0895d..e97550b41db0f9cd2851135be0000f48e9036a30 100644 (file)
                                </description>
                                <default>0</default>
                        </parameter>
+                       <parameter name="sortEffects" type="boolean">
+                               <label>Sort Effects</label>
+                               <description>If set, will sort the state options of the effects channel alphabetically while keeping the first
+                                       option (Solid) at the top.</description>
+                               <default>false</default>
+                       </parameter>
+                       <parameter name="sortPalettes" type="boolean">
+                               <label>Sort Palettes</label>
+                               <description>If set, will sort the state options of the palettes channel alphabetically while keeping the first
+                                       option (Default) at the top.</description>
+                               <default>false</default>
+                       </parameter>
                </config-description>
        </thing-type>