]> git.basschouten.com Git - openhab-addons.git/commitdiff
[webthing] Cleanup semantic tags for dynamic channels (#12751)
authorlolodomo <lg.hc@free.fr>
Mon, 16 May 2022 17:21:22 +0000 (19:21 +0200)
committerGitHub <noreply@github.com>
Mon, 16 May 2022 17:21:22 +0000 (19:21 +0200)
Related to #12262

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/channel/Channels.java
bundles/org.openhab.binding.webthing/src/main/java/org/openhab/binding/webthing/internal/link/TypeMapping.java

index 82f63ad9b89c8712e9ae1233dc443ff31d85f32f..7ba4ebd34bd61ed8a373a5a2b10c2772b78c5ed8 100644 (file)
@@ -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<String> defaultTags = itemType.getTags();
+        if (!defaultTags.isEmpty()) {
+            channelBuilder.withDefaultTags(defaultTags);
         }
         return channelBuilder.build();
     }
index 7e1789e1cd6548aced7b14bd695aef380b8e9afa..d1ed43b60a3b611129d5d03a026bdb9e7ec53f29 100644 (file)
@@ -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<String> 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<String> tags;
 
-        ItemType(String type, @Nullable String tag) {
+        ItemType(String type, Set<String> tags) {
             this.type = type;
-            this.tag = tag;
+            this.tags = tags;
         }
 
         public String getType() {
             return type;
         }
 
-        public @Nullable String getTag() {
-            return tag;
+        public Set<String> getTags() {
+            return tags;
         }
     }
 }