[tuya] Get channel labels from schema label or map from schema code (#18654)

Signed-off-by: Mike Jagdis <mjagdis@eris-associates.co.uk>
This commit is contained in:
mjagdis
2025-05-06 18:37:08 +02:00
committed by GitHub
parent 6fec9470e9
commit 74ebf90f77
3 changed files with 17 additions and 2 deletions
@@ -36,6 +36,7 @@ public class DeviceSchema {
public static class Description {
public String code = "";
public int dp_id = 0;
public String label = "";
public String type = "";
public String values = "";
@@ -70,6 +70,7 @@ import org.openhab.core.types.CommandOption;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.State;
import org.openhab.core.types.UnDefType;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -507,8 +508,20 @@ public class TuyaDeviceHandler extends BaseThingHandler implements DeviceInfoSub
return Map.entry("", ChannelBuilder.create(channelUID).build());
}
return Map.entry(channelId, callback.createChannelBuilder(channelUID, channeltypeUID).withLabel(channelId)
.withConfiguration(new Configuration(configuration)).build());
if (schemaDp.label.isEmpty()) {
schemaDp.label = schemaDp.code;
String label = StringUtils.capitalizeByWhitespace(schemaDp.code.replaceAll("_", " "));
if (label != null) {
label = label.trim();
if (!label.isEmpty()) {
schemaDp.label = label;
}
}
}
return Map.entry(channelId, callback.createChannelBuilder(channelUID, channeltypeUID)
.withLabel(schemaDp.label).withConfiguration(new Configuration(configuration)).build());
}).filter(c -> !c.getKey().isEmpty()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
List<String> channelSuffixes = List.of("", "_1", "_2");
@@ -39,6 +39,7 @@ public class SchemaDp {
public int id = 0;
public String code = "";
public String type = "";
public String label = "";
public @Nullable Double min;
public @Nullable Double max;
public @Nullable List<String> range;