2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.webthing.internal.link;
15 import java.util.Locale;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.webthing.internal.client.dto.Property;
20 import org.openhab.core.library.CoreItemFactory;
23 * The {@link TypeMapping} class defines the mapping of Item types <-> WebThing Property types.
25 * Please consider that changes of 'Item types <-> WebThing Property types' mapping will break the
26 * compatibility to former releases
28 * @author Gregor Roth - Initial contribution
31 public class TypeMapping {
34 * maps a property type to an item type
36 * @param propertyMetadata the property meta data
37 * @return the associated item type
39 public static ItemType toItemType(Property propertyMetadata) {
40 String type = CoreItemFactory.STRING;
41 Set<String> tags = Set.of();
43 switch (propertyMetadata.typeKeyword) {
45 case "BooleanProperty":
47 case "LockedProperty":
48 case "MotionProperty":
50 case "PushedProperty":
51 type = CoreItemFactory.SWITCH;
53 case "CurrentProperty":
54 case "FrequencyProperty":
55 case "InstantaneousPowerProperty":
56 case "VoltageProperty":
57 type = CoreItemFactory.NUMBER;
59 case "HeatingCoolingProperty":
62 type = CoreItemFactory.STRING;
64 case "BrightnessProperty":
65 type = CoreItemFactory.DIMMER;
66 tags = Set.of("Control", "Light");
68 case "HumidityProperty":
69 type = CoreItemFactory.DIMMER;
70 tags = Set.of("Measurement", "Humidity");
72 case "ColorModeProperty":
73 type = CoreItemFactory.STRING;
76 type = CoreItemFactory.COLOR;
77 tags = Set.of("Control", "Light");
79 case "ColorTemperatureProperty":
80 type = CoreItemFactory.DIMMER;
81 tags = Set.of("Control", "ColorTemperature");
84 type = CoreItemFactory.CONTACT;
85 tags = Set.of("OpenState");
87 case "TargetTemperatureProperty":
88 type = CoreItemFactory.NUMBER;
89 tags = Set.of("Setpoint", "Temperature");
91 case "TemperatureProperty":
92 type = CoreItemFactory.NUMBER;
93 tags = Set.of("Measurement", "Temperature");
95 case "ThermostatModeProperty":
98 if ((propertyMetadata.unit != null)
99 && propertyMetadata.unit.toLowerCase(Locale.ENGLISH).equals("percent")) {
100 type = CoreItemFactory.DIMMER;
102 type = CoreItemFactory.NUMBER;
106 switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) {
108 type = CoreItemFactory.SWITCH;
112 type = CoreItemFactory.NUMBER;
115 type = CoreItemFactory.STRING;
121 return new ItemType(type, tags);
125 * The item type description
127 public static class ItemType {
128 private final String type;
129 private final Set<String> tags;
131 ItemType(String type, Set<String> tags) {
136 public String getType() {
140 public Set<String> getTags() {