Skip to content

Commit

Permalink
[wled] add configuration to sort state options of channels effects an…
Browse files Browse the repository at this point in the history
…d palettes (openhab#11785)

Signed-off-by: Sascha Volkenandt <[email protected]>
Signed-off-by: Michael Schmidt <[email protected]>
lordjaxom authored and mischmidt83 committed Jan 9, 2022
1 parent e37a139 commit 0ca49af
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -25,4 +25,6 @@ public class WLedConfiguration {
public int pollTime;
public int segmentIndex;
public int saturationThreshold;
public boolean sortEffects = false;
public boolean sortPalettes = false;
}
Original file line number Diff line number Diff line change
@@ -305,6 +305,7 @@ public void dispose() {
future.cancel(true);
pollingFuture = null;
}
api = null; // re-initialize api after configuration change
}

@Override
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
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 @@ protected void getUpdatedFxList() {
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 @@ protected void getUpdatedPaletteList() {
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);
}
Original file line number Diff line number Diff line change
@@ -57,6 +57,18 @@
</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>

0 comments on commit 0ca49af

Please sign in to comment.