[wled] add configuration to sort state options of channels effects and palettes (#11785)

Signed-off-by: Sascha Volkenandt <sascha@akv-soft.de>
pull/11750/head
lordjaxom 2021-12-15 11:36:17 +01:00 committed by GitHub
parent 88d74b72ea
commit a1e84cff73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

View File

@ -25,4 +25,6 @@ public class WLedConfiguration {
public int pollTime; public int pollTime;
public int segmentIndex; public int segmentIndex;
public int saturationThreshold; public int saturationThreshold;
public boolean sortEffects = false;
public boolean sortPalettes = false;
} }

View File

@ -305,6 +305,7 @@ public class WLedHandler extends BaseThingHandler {
future.cancel(true); future.cancel(true);
pollingFuture = null; pollingFuture = null;
} }
api = null; // re-initialize api after configuration change
} }
@Override @Override

View File

@ -17,6 +17,7 @@ import static org.openhab.binding.wled.internal.WLedBindingConstants.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -230,6 +231,9 @@ public class WledApiV084 implements WledApi {
for (String value : state.jsonResponse.effects) { for (String value : state.jsonResponse.effects) {
fxOptions.add(new StateOption(Integer.toString(counter++), value)); 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), handler.stateDescriptionProvider.setStateOptions(new ChannelUID(handler.getThing().getUID(), CHANNEL_FX),
fxOptions); fxOptions);
} }
@ -240,6 +244,9 @@ public class WledApiV084 implements WledApi {
for (String value : state.jsonResponse.palettes) { for (String value : state.jsonResponse.palettes) {
palleteOptions.add(new StateOption(Integer.toString(counter++), value)); 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), handler.stateDescriptionProvider.setStateOptions(new ChannelUID(handler.getThing().getUID(), CHANNEL_PALETTES),
palleteOptions); palleteOptions);
} }

View File

@ -57,6 +57,18 @@
</description> </description>
<default>0</default> <default>0</default>
</parameter> </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> </config-description>
</thing-type> </thing-type>