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:
lolodomo
2025-03-09 15:12:29 +01:00
committed by GitHub
parent 3af47e9c30
commit 8efa024632
@@ -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) {