[tuya] Order Channels using DP order in schemas (#18657)

Signed-off-by: Mike Jagdis <mjagdis@eris-associates.co.uk>
This commit is contained in:
mjagdis
2025-05-16 13:54:46 +02:00
committed by GitHub
parent cc69f5bec6
commit 465b984b11
2 changed files with 7 additions and 3 deletions
@@ -16,6 +16,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@@ -72,7 +73,8 @@ public class TuyaBindingConstants {
try (InputStreamReader reader = new InputStreamReader(resource)) {
Gson gson = new Gson();
Type schemaListType = TypeToken.getParameterized(Map.class, String.class, SchemaDp.class).getType();
Type schemaListType = TypeToken.getParameterized(LinkedHashMap.class, String.class, SchemaDp.class)
.getType();
Type schemaType = TypeToken.getParameterized(Map.class, String.class, schemaListType).getType();
return Objects.requireNonNull(gson.fromJson(reader, schemaType));
} catch (IOException e) {
@@ -25,6 +25,7 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -432,7 +433,8 @@ public class TuyaDeviceHandler extends BaseThingHandler implements DeviceInfoSub
if (schema == null) {
if (!schemaDps.isEmpty()) {
// fallback to retrieved schema
schema = schemaDps.stream().collect(Collectors.toMap(s -> s.code, s -> s));
schema = schemaDps.stream()
.collect(Collectors.toMap(s -> s.code, s -> s, (e1, e2) -> e1, LinkedHashMap::new));
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"No channels added and schema not found.");
@@ -479,7 +481,7 @@ public class TuyaDeviceHandler extends BaseThingHandler implements DeviceInfoSub
return;
}
Map<String, Channel> channels = new HashMap<>(schema.entrySet().stream().map(e -> {
Map<String, Channel> channels = new LinkedHashMap<>(schema.entrySet().stream().map(e -> {
String channelId = e.getKey();
SchemaDp schemaDp = e.getValue();