mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[wled] add configuration to sort state options of channels effects and palettes (#11785)
Signed-off-by: Sascha Volkenandt <sascha@akv-soft.de>
This commit is contained in:
parent
88d74b72ea
commit
a1e84cff73
@ -25,4 +25,6 @@ public class WLedConfiguration {
|
||||
public int pollTime;
|
||||
public int segmentIndex;
|
||||
public int saturationThreshold;
|
||||
public boolean sortEffects = false;
|
||||
public boolean sortPalettes = false;
|
||||
}
|
||||
|
@ -305,6 +305,7 @@ public class WLedHandler extends BaseThingHandler {
|
||||
future.cancel(true);
|
||||
pollingFuture = null;
|
||||
}
|
||||
api = null; // re-initialize api after configuration change
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user