[webthing] Cleanup semantic tags for dynamic channels (#12751)

Related to #12262

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2022-05-16 19:21:22 +02:00 committed by GitHub
parent 5eaddd1af1
commit 25a923be39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 20 deletions

View File

@ -65,9 +65,9 @@ public class Channels {
channelBuilder.withType(new ChannelTypeUID(BINDING_ID, itemType.getType().toLowerCase())); 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(); Set<String> defaultTags = itemType.getTags();
if (defaultTag != null) { if (!defaultTags.isEmpty()) {
channelBuilder.withDefaultTags(Set.of(defaultTag)); channelBuilder.withDefaultTags(defaultTags);
} }
return channelBuilder.build(); return channelBuilder.build();
} }

View File

@ -13,9 +13,9 @@
package org.openhab.binding.webthing.internal.link; package org.openhab.binding.webthing.internal.link;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.NonNullByDefault;
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; import org.openhab.core.library.CoreItemFactory;
@ -38,8 +38,7 @@ public class TypeMapping {
*/ */
public static ItemType toItemType(Property propertyMetadata) { public static ItemType toItemType(Property propertyMetadata) {
String type = CoreItemFactory.STRING; String type = CoreItemFactory.STRING;
@Nullable Set<String> tags = Set.of();
String tag = null;
switch (propertyMetadata.typeKeyword) { switch (propertyMetadata.typeKeyword) {
case "AlarmProperty": case "AlarmProperty":
@ -50,7 +49,6 @@ public class TypeMapping {
case "OnOffProperty": case "OnOffProperty":
case "PushedProperty": case "PushedProperty":
type = CoreItemFactory.SWITCH; type = CoreItemFactory.SWITCH;
tag = "Switchable";
break; break;
case "CurrentProperty": case "CurrentProperty":
case "FrequencyProperty": case "FrequencyProperty":
@ -64,32 +62,35 @@ public class TypeMapping {
type = CoreItemFactory.STRING; type = CoreItemFactory.STRING;
break; break;
case "BrightnessProperty": case "BrightnessProperty":
type = CoreItemFactory.DIMMER;
tags = Set.of("Control", "Light");
break;
case "HumidityProperty": case "HumidityProperty":
type = CoreItemFactory.DIMMER; type = CoreItemFactory.DIMMER;
tags = Set.of("Measurement", "Humidity");
break; break;
case "ColorModeProperty": case "ColorModeProperty":
type = CoreItemFactory.STRING; type = CoreItemFactory.STRING;
tag = "lighting";
break; break;
case "ColorProperty": case "ColorProperty":
type = CoreItemFactory.COLOR; type = CoreItemFactory.COLOR;
tag = "Lighting"; tags = Set.of("Control", "Light");
break; break;
case "ColorTemperatureProperty": case "ColorTemperatureProperty":
type = CoreItemFactory.DIMMER; type = CoreItemFactory.DIMMER;
tag = "Lighting"; tags = Set.of("Control", "ColorTemperature");
break; break;
case "OpenProperty": case "OpenProperty":
type = CoreItemFactory.CONTACT; type = CoreItemFactory.CONTACT;
tag = "ContactSensor"; tags = Set.of("OpenState");
break; break;
case "TargetTemperatureProperty": case "TargetTemperatureProperty":
type = CoreItemFactory.NUMBER; type = CoreItemFactory.NUMBER;
tag = "TargetTemperature"; tags = Set.of("Setpoint", "Temperature");
break; break;
case "TemperatureProperty": case "TemperatureProperty":
type = CoreItemFactory.NUMBER; type = CoreItemFactory.NUMBER;
tag = "CurrentTemperature"; tags = Set.of("Measurement", "Temperature");
break; break;
case "ThermostatModeProperty": case "ThermostatModeProperty":
break; break;
@ -105,7 +106,6 @@ public class TypeMapping {
switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) { switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) {
case "boolean": case "boolean":
type = CoreItemFactory.SWITCH; type = CoreItemFactory.SWITCH;
tag = "Switchable";
break; break;
case "integer": case "integer":
case "number": case "number":
@ -118,7 +118,7 @@ public class TypeMapping {
break; break;
} }
return new ItemType(type, tag); return new ItemType(type, tags);
} }
/** /**
@ -126,19 +126,19 @@ public class TypeMapping {
*/ */
public static class ItemType { public static class ItemType {
private final String type; 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.type = type;
this.tag = tag; this.tags = tags;
} }
public String getType() { public String getType() {
return type; return type;
} }
public @Nullable String getTag() { public Set<String> getTags() {
return tag; return tags;
} }
} }
} }