mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
File format generator: do not change order of thing channels (#4636)
Keep original order of channels Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
+2
-18
@@ -174,32 +174,16 @@ public abstract class AbstractThingFileGenerator implements ThingFileGenerator {
|
||||
* Get non default channels.
|
||||
* It includes extensible channels and channels with a non default configuration.
|
||||
*
|
||||
* Resulting channels are sorted in such a way that channels without channel type are after channels
|
||||
* with a channel type. Sort is done first on the channel type and then on the channel UID.
|
||||
*
|
||||
* @param thing the thing
|
||||
* @return the sorted list of channels
|
||||
* @return the list of channels
|
||||
*/
|
||||
protected List<Channel> getNonDefaultChannels(Thing thing) {
|
||||
ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
|
||||
List<String> ids = thingType != null ? thingType.getExtensibleChannelTypeIds() : List.of();
|
||||
List<Channel> channels = thing
|
||||
return thing
|
||||
.getChannels().stream().filter(ch -> ch.getChannelTypeUID() == null
|
||||
|| ids.contains(ch.getChannelTypeUID().getId()) || channelWithNonDefaultConfig(ch))
|
||||
.collect(Collectors.toList());
|
||||
return channels.stream().sorted((ch1, ch2) -> {
|
||||
ChannelTypeUID typeUID1 = ch1.getChannelTypeUID();
|
||||
ChannelTypeUID typeUID2 = ch2.getChannelTypeUID();
|
||||
if (typeUID1 != null && typeUID2 == null) {
|
||||
return -1;
|
||||
} else if (typeUID1 == null && typeUID2 != null) {
|
||||
return 1;
|
||||
} else if (typeUID1 != null && typeUID2 != null && !typeUID1.equals(typeUID2)) {
|
||||
return typeUID1.getAsString().compareTo(typeUID2.getAsString());
|
||||
} else {
|
||||
return ch1.getUID().getAsString().compareTo(ch2.getUID().getAsString());
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean channelWithNonDefaultConfig(Channel channel) {
|
||||
|
||||
Reference in New Issue
Block a user