]> git.basschouten.com Git - openhab-addons.git/commitdiff
[webthing] Fix item type for dynamic channel (#12738)
authorlolodomo <lg.hc@free.fr>
Sun, 15 May 2022 19:24:46 +0000 (21:24 +0200)
committerGitHub <noreply@github.com>
Sun, 15 May 2022 19:24:46 +0000 (21:24 +0200)
* [webthing] Fix item type for dynamic channel
* Review comments: use constants from CoreItemFactory

Related to #12712

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 c44e1c2205f36eec25c022d65814b8a7c3a37ba3..82f63ad9b89c8712e9ae1233dc443ff31d85f32f 100644 (file)
@@ -62,7 +62,7 @@ public class Channels {
         // inside the thing-types.xml file. A better solution would be to create the channel types
         // dynamically based on the WebThing description to make most of the meta data of a WebThing.
         // The goal of the WebThing meta data is to enable semantic interoperability for connected things
-        channelBuilder.withType(new ChannelTypeUID(BINDING_ID, itemType.getType()));
+        channelBuilder.withType(new ChannelTypeUID(BINDING_ID, itemType.getType().toLowerCase()));
         channelBuilder.withDescription(property.description);
         channelBuilder.withLabel(property.title);
         var defaultTag = itemType.getTag();
index efd19299bc96fc11264987226aafeead7e986765..7e1789e1cd6548aced7b14bd695aef380b8e9afa 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Locale;
 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;
 
 /**
  * The {@link TypeMapping} class defines the mapping of Item types <-> WebThing Property types.
@@ -31,12 +32,12 @@ public class TypeMapping {
 
     /**
      * maps a property type to an item type
-     * 
+     *
      * @param propertyMetadata the property meta data
      * @return the associated item type
      */
     public static ItemType toItemType(Property propertyMetadata) {
-        String type = "string";
+        String type = CoreItemFactory.STRING;
         @Nullable
         String tag = null;
 
@@ -48,46 +49,46 @@ public class TypeMapping {
             case "MotionProperty":
             case "OnOffProperty":
             case "PushedProperty":
-                type = "switch";
+                type = CoreItemFactory.SWITCH;
                 tag = "Switchable";
                 break;
             case "CurrentProperty":
             case "FrequencyProperty":
             case "InstantaneousPowerProperty":
             case "VoltageProperty":
-                type = "number";
+                type = CoreItemFactory.NUMBER;
                 break;
             case "HeatingCoolingProperty":
             case "ImageProperty":
             case "VideoProperty":
-                type = "string";
+                type = CoreItemFactory.STRING;
                 break;
             case "BrightnessProperty":
             case "HumidityProperty":
-                type = "dimmer";
+                type = CoreItemFactory.DIMMER;
                 break;
             case "ColorModeProperty":
-                type = "string";
+                type = CoreItemFactory.STRING;
                 tag = "lighting";
                 break;
             case "ColorProperty":
-                type = "color";
+                type = CoreItemFactory.COLOR;
                 tag = "Lighting";
                 break;
             case "ColorTemperatureProperty":
-                type = "dimmer";
+                type = CoreItemFactory.DIMMER;
                 tag = "Lighting";
                 break;
             case "OpenProperty":
-                type = "contact";
+                type = CoreItemFactory.CONTACT;
                 tag = "ContactSensor";
                 break;
             case "TargetTemperatureProperty":
-                type = "number";
+                type = CoreItemFactory.NUMBER;
                 tag = "TargetTemperature";
                 break;
             case "TemperatureProperty":
-                type = "number";
+                type = CoreItemFactory.NUMBER;
                 tag = "CurrentTemperature";
                 break;
             case "ThermostatModeProperty":
@@ -95,23 +96,23 @@ public class TypeMapping {
             case "LevelProperty":
                 if ((propertyMetadata.unit != null)
                         && propertyMetadata.unit.toLowerCase(Locale.ENGLISH).equals("percent")) {
-                    type = "dimmer";
+                    type = CoreItemFactory.DIMMER;
                 } else {
-                    type = "number";
+                    type = CoreItemFactory.NUMBER;
                 }
                 break;
             default:
                 switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) {
                     case "boolean":
-                        type = "switch";
+                        type = CoreItemFactory.SWITCH;
                         tag = "Switchable";
                         break;
                     case "integer":
                     case "number":
-                        type = "number";
+                        type = CoreItemFactory.NUMBER;
                         break;
                     default:
-                        type = "string";
+                        type = CoreItemFactory.STRING;
                         break;
                 }
                 break;