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 <sascha@akv-soft.de>
  • Loading branch information
lordjaxom authored and Nemer_Daud committed Jan 28, 2022
1 parent 0173e10 commit 8080bb0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -305,6 +305,7 @@ public void dispose() {
future.cancel(true);
pollingFuture = null;
}
api = null; // re-initialize api after configuration change
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit 8080bb0

Please sign in to comment.