mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +01:00
[webthing] Fix item type for dynamic channel (#12738)
* [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>
This commit is contained in:
parent
7dae2b01ec
commit
715fe34daa
@ -62,7 +62,7 @@ public class Channels {
|
|||||||
// inside the thing-types.xml file. A better solution would be to create the channel types
|
// 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.
|
// 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
|
// 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.withDescription(property.description);
|
||||||
channelBuilder.withLabel(property.title);
|
channelBuilder.withLabel(property.title);
|
||||||
var defaultTag = itemType.getTag();
|
var defaultTag = itemType.getTag();
|
||||||
|
@ -17,6 +17,7 @@ import java.util.Locale;
|
|||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.webthing.internal.client.dto.Property;
|
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.
|
* 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
|
* maps a property type to an item type
|
||||||
*
|
*
|
||||||
* @param propertyMetadata the property meta data
|
* @param propertyMetadata the property meta data
|
||||||
* @return the associated item type
|
* @return the associated item type
|
||||||
*/
|
*/
|
||||||
public static ItemType toItemType(Property propertyMetadata) {
|
public static ItemType toItemType(Property propertyMetadata) {
|
||||||
String type = "string";
|
String type = CoreItemFactory.STRING;
|
||||||
@Nullable
|
@Nullable
|
||||||
String tag = null;
|
String tag = null;
|
||||||
|
|
||||||
@ -48,46 +49,46 @@ public class TypeMapping {
|
|||||||
case "MotionProperty":
|
case "MotionProperty":
|
||||||
case "OnOffProperty":
|
case "OnOffProperty":
|
||||||
case "PushedProperty":
|
case "PushedProperty":
|
||||||
type = "switch";
|
type = CoreItemFactory.SWITCH;
|
||||||
tag = "Switchable";
|
tag = "Switchable";
|
||||||
break;
|
break;
|
||||||
case "CurrentProperty":
|
case "CurrentProperty":
|
||||||
case "FrequencyProperty":
|
case "FrequencyProperty":
|
||||||
case "InstantaneousPowerProperty":
|
case "InstantaneousPowerProperty":
|
||||||
case "VoltageProperty":
|
case "VoltageProperty":
|
||||||
type = "number";
|
type = CoreItemFactory.NUMBER;
|
||||||
break;
|
break;
|
||||||
case "HeatingCoolingProperty":
|
case "HeatingCoolingProperty":
|
||||||
case "ImageProperty":
|
case "ImageProperty":
|
||||||
case "VideoProperty":
|
case "VideoProperty":
|
||||||
type = "string";
|
type = CoreItemFactory.STRING;
|
||||||
break;
|
break;
|
||||||
case "BrightnessProperty":
|
case "BrightnessProperty":
|
||||||
case "HumidityProperty":
|
case "HumidityProperty":
|
||||||
type = "dimmer";
|
type = CoreItemFactory.DIMMER;
|
||||||
break;
|
break;
|
||||||
case "ColorModeProperty":
|
case "ColorModeProperty":
|
||||||
type = "string";
|
type = CoreItemFactory.STRING;
|
||||||
tag = "lighting";
|
tag = "lighting";
|
||||||
break;
|
break;
|
||||||
case "ColorProperty":
|
case "ColorProperty":
|
||||||
type = "color";
|
type = CoreItemFactory.COLOR;
|
||||||
tag = "Lighting";
|
tag = "Lighting";
|
||||||
break;
|
break;
|
||||||
case "ColorTemperatureProperty":
|
case "ColorTemperatureProperty":
|
||||||
type = "dimmer";
|
type = CoreItemFactory.DIMMER;
|
||||||
tag = "Lighting";
|
tag = "Lighting";
|
||||||
break;
|
break;
|
||||||
case "OpenProperty":
|
case "OpenProperty":
|
||||||
type = "contact";
|
type = CoreItemFactory.CONTACT;
|
||||||
tag = "ContactSensor";
|
tag = "ContactSensor";
|
||||||
break;
|
break;
|
||||||
case "TargetTemperatureProperty":
|
case "TargetTemperatureProperty":
|
||||||
type = "number";
|
type = CoreItemFactory.NUMBER;
|
||||||
tag = "TargetTemperature";
|
tag = "TargetTemperature";
|
||||||
break;
|
break;
|
||||||
case "TemperatureProperty":
|
case "TemperatureProperty":
|
||||||
type = "number";
|
type = CoreItemFactory.NUMBER;
|
||||||
tag = "CurrentTemperature";
|
tag = "CurrentTemperature";
|
||||||
break;
|
break;
|
||||||
case "ThermostatModeProperty":
|
case "ThermostatModeProperty":
|
||||||
@ -95,23 +96,23 @@ public class TypeMapping {
|
|||||||
case "LevelProperty":
|
case "LevelProperty":
|
||||||
if ((propertyMetadata.unit != null)
|
if ((propertyMetadata.unit != null)
|
||||||
&& propertyMetadata.unit.toLowerCase(Locale.ENGLISH).equals("percent")) {
|
&& propertyMetadata.unit.toLowerCase(Locale.ENGLISH).equals("percent")) {
|
||||||
type = "dimmer";
|
type = CoreItemFactory.DIMMER;
|
||||||
} else {
|
} else {
|
||||||
type = "number";
|
type = CoreItemFactory.NUMBER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) {
|
switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) {
|
||||||
case "boolean":
|
case "boolean":
|
||||||
type = "switch";
|
type = CoreItemFactory.SWITCH;
|
||||||
tag = "Switchable";
|
tag = "Switchable";
|
||||||
break;
|
break;
|
||||||
case "integer":
|
case "integer":
|
||||||
case "number":
|
case "number":
|
||||||
type = "number";
|
type = CoreItemFactory.NUMBER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
type = "string";
|
type = CoreItemFactory.STRING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user