YAML config: add "description" field to channel for things (#4795)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>pull/4718/head
parent
c4c2c4c431
commit
d6fb61d0c7
|
@ -36,6 +36,7 @@ public class YamlChannelDTO {
|
|||
public String itemType;
|
||||
public String itemDimension;
|
||||
public String label;
|
||||
public String description;
|
||||
public Map<@NonNull String, @NonNull Object> config;
|
||||
|
||||
public YamlChannelDTO() {
|
||||
|
@ -99,7 +100,7 @@ public class YamlChannelDTO {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type, getKind(), getItemType(), label);
|
||||
return Objects.hash(type, getKind(), getItemType(), label, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,6 +113,7 @@ public class YamlChannelDTO {
|
|||
YamlChannelDTO other = (YamlChannelDTO) obj;
|
||||
return Objects.equals(type, other.type) && getKind() == other.getKind()
|
||||
&& Objects.equals(getItemType(), other.getItemType()) && Objects.equals(label, other.label)
|
||||
&& Objects.equals(description, other.description)
|
||||
&& YamlElementUtils.equalsConfig(config, other.config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -380,6 +380,7 @@ public class YamlThingProvider extends AbstractProvider<Thing>
|
|||
ChannelKind kind = channelDto.getKind();
|
||||
String itemType = channelDto.getItemType();
|
||||
String label = channelDto.label;
|
||||
String description = channelDto.description;
|
||||
AutoUpdatePolicy autoUpdatePolicy = null;
|
||||
Configuration configuration = new Configuration(channelDto.config);
|
||||
if (channelDto.type != null) {
|
||||
|
@ -392,6 +393,9 @@ public class YamlThingProvider extends AbstractProvider<Thing>
|
|||
if (label == null) {
|
||||
label = channelType.getLabel();
|
||||
}
|
||||
if (description == null) {
|
||||
description = channelType.getDescription();
|
||||
}
|
||||
autoUpdatePolicy = channelType.getAutoUpdatePolicy();
|
||||
URI descUriO = channelType.getConfigDescriptionURI();
|
||||
if (descUriO != null) {
|
||||
|
@ -403,9 +407,15 @@ public class YamlThingProvider extends AbstractProvider<Thing>
|
|||
}
|
||||
}
|
||||
|
||||
Channel channel = ChannelBuilder.create(new ChannelUID(thingUID, channelId), itemType).withKind(kind)
|
||||
.withConfiguration(configuration).withType(channelTypeUID).withLabel(label)
|
||||
.withAutoUpdatePolicy(autoUpdatePolicy).build();
|
||||
ChannelBuilder builder = ChannelBuilder.create(new ChannelUID(thingUID, channelId), itemType).withKind(kind)
|
||||
.withConfiguration(configuration).withType(channelTypeUID).withAutoUpdatePolicy(autoUpdatePolicy);
|
||||
if (label != null) {
|
||||
builder.withLabel(label);
|
||||
}
|
||||
if (description != null) {
|
||||
builder.withDescription(description);
|
||||
}
|
||||
Channel channel = builder.build();
|
||||
channels.add(channel);
|
||||
addedChannelIds.add(channelId);
|
||||
});
|
||||
|
|
|
@ -118,12 +118,15 @@ public class YamlThingFileConverter extends AbstractThingFileGenerator {
|
|||
ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID, localeProvider.getLocale());
|
||||
dto.label = channelType != null && channelType.getLabel().equals(channel.getLabel()) ? null
|
||||
: channel.getLabel();
|
||||
String descr = channelType != null ? channelType.getDescription() : null;
|
||||
dto.description = descr != null && descr.equals(channel.getDescription()) ? null : channel.getDescription();
|
||||
} else {
|
||||
dto.kind = channel.getKind() == ChannelKind.STATE ? null : "trigger";
|
||||
String itemType = channel.getAcceptedItemType();
|
||||
dto.itemType = itemType != null ? ItemUtil.getMainItemType(itemType) : null;
|
||||
dto.itemDimension = ItemUtil.getItemTypeExtension(itemType);
|
||||
dto.label = channel.getLabel();
|
||||
dto.description = channel.getDescription();
|
||||
}
|
||||
|
||||
Map<String, Object> config = new LinkedHashMap<>();
|
||||
|
|
|
@ -96,6 +96,10 @@ public class YamlChannelDTOTest {
|
|||
ch2.label = "A label";
|
||||
assertTrue(ch1.equals(ch2));
|
||||
|
||||
ch1.description = "A description";
|
||||
ch2.description = "A description";
|
||||
assertTrue(ch1.equals(ch2));
|
||||
|
||||
ch1.config = Map.of("param1", "value", "param2", 50, "param3", true, "param4", List.of("val 1", "val 2"));
|
||||
ch2.config = Map.of("param1", "value", "param2", 50, "param3", true, "param4", List.of("val 1", "val 2"));
|
||||
assertTrue(ch1.equals(ch2));
|
||||
|
@ -218,6 +222,31 @@ public class YamlChannelDTOTest {
|
|||
assertTrue(ch1.equals(ch2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsWithDescription() throws IOException {
|
||||
YamlChannelDTO ch1 = new YamlChannelDTO();
|
||||
YamlChannelDTO ch2 = new YamlChannelDTO();
|
||||
|
||||
ch1.itemType = "String";
|
||||
ch2.itemType = "String";
|
||||
|
||||
ch1.description = null;
|
||||
ch2.description = null;
|
||||
assertTrue(ch1.equals(ch2));
|
||||
ch1.description = "A description";
|
||||
ch2.description = null;
|
||||
assertFalse(ch1.equals(ch2));
|
||||
ch1.description = null;
|
||||
ch2.description = "A description";
|
||||
assertFalse(ch1.equals(ch2));
|
||||
ch1.description = "A description";
|
||||
ch2.description = "A different description";
|
||||
assertFalse(ch1.equals(ch2));
|
||||
ch1.description = "A description";
|
||||
ch2.description = "A description";
|
||||
assertTrue(ch1.equals(ch2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsWithConfigurations() throws IOException {
|
||||
YamlChannelDTO ch1 = new YamlChannelDTO();
|
||||
|
|
Loading…
Reference in New Issue