From 25a923be39f15d6ccec4282400fb8080896525f8 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 16 May 2022 19:21:22 +0200 Subject: [PATCH] [webthing] Cleanup semantic tags for dynamic channels (#12751) Related to #12262 Signed-off-by: Laurent Garnier --- .../webthing/internal/channel/Channels.java | 6 ++-- .../webthing/internal/link/TypeMapping.java | 34 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/channel/Channels.java b/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/channel/Channels.java index 82f63ad9b89..7ba4ebd34bd 100644 --- a/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/channel/Channels.java +++ b/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/channel/Channels.java @@ -65,9 +65,9 @@ public class Channels { channelBuilder.withType(new ChannelTypeUID(BINDING_ID, itemType.getType().toLowerCase())); channelBuilder.withDescription(property.description); channelBuilder.withLabel(property.title); - var defaultTag = itemType.getTag(); - if (defaultTag != null) { - channelBuilder.withDefaultTags(Set.of(defaultTag)); + Set defaultTags = itemType.getTags(); + if (!defaultTags.isEmpty()) { + channelBuilder.withDefaultTags(defaultTags); } return channelBuilder.build(); } diff --git a/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/link/TypeMapping.java b/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/link/TypeMapping.java index 7e1789e1cd6..d1ed43b60a3 100644 --- a/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/link/TypeMapping.java +++ b/bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/link/TypeMapping.java @@ -13,9 +13,9 @@ package org.openhab.binding.webthing.internal.link; import java.util.Locale; +import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.webthing.internal.client.dto.Property; import org.openhab.core.library.CoreItemFactory; @@ -38,8 +38,7 @@ public class TypeMapping { */ public static ItemType toItemType(Property propertyMetadata) { String type = CoreItemFactory.STRING; - @Nullable - String tag = null; + Set tags = Set.of(); switch (propertyMetadata.typeKeyword) { case "AlarmProperty": @@ -50,7 +49,6 @@ public class TypeMapping { case "OnOffProperty": case "PushedProperty": type = CoreItemFactory.SWITCH; - tag = "Switchable"; break; case "CurrentProperty": case "FrequencyProperty": @@ -64,32 +62,35 @@ public class TypeMapping { type = CoreItemFactory.STRING; break; case "BrightnessProperty": + type = CoreItemFactory.DIMMER; + tags = Set.of("Control", "Light"); + break; case "HumidityProperty": type = CoreItemFactory.DIMMER; + tags = Set.of("Measurement", "Humidity"); break; case "ColorModeProperty": type = CoreItemFactory.STRING; - tag = "lighting"; break; case "ColorProperty": type = CoreItemFactory.COLOR; - tag = "Lighting"; + tags = Set.of("Control", "Light"); break; case "ColorTemperatureProperty": type = CoreItemFactory.DIMMER; - tag = "Lighting"; + tags = Set.of("Control", "ColorTemperature"); break; case "OpenProperty": type = CoreItemFactory.CONTACT; - tag = "ContactSensor"; + tags = Set.of("OpenState"); break; case "TargetTemperatureProperty": type = CoreItemFactory.NUMBER; - tag = "TargetTemperature"; + tags = Set.of("Setpoint", "Temperature"); break; case "TemperatureProperty": type = CoreItemFactory.NUMBER; - tag = "CurrentTemperature"; + tags = Set.of("Measurement", "Temperature"); break; case "ThermostatModeProperty": break; @@ -105,7 +106,6 @@ public class TypeMapping { switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) { case "boolean": type = CoreItemFactory.SWITCH; - tag = "Switchable"; break; case "integer": case "number": @@ -118,7 +118,7 @@ public class TypeMapping { break; } - return new ItemType(type, tag); + return new ItemType(type, tags); } /** @@ -126,19 +126,19 @@ public class TypeMapping { */ public static class ItemType { private final String type; - private final @Nullable String tag; + private final Set tags; - ItemType(String type, @Nullable String tag) { + ItemType(String type, Set tags) { this.type = type; - this.tag = tag; + this.tags = tags; } public String getType() { return type; } - public @Nullable String getTag() { - return tag; + public Set getTags() { + return tags; } } }