2 * Copyright (c) 2010-2022 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;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
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;
44 switch (propertyMetadata.typeKeyword) {
46 case "BooleanProperty":
48 case "LockedProperty":
49 case "MotionProperty":
51 case "PushedProperty":
52 type = CoreItemFactory.SWITCH;
55 case "CurrentProperty":
56 case "FrequencyProperty":
57 case "InstantaneousPowerProperty":
58 case "VoltageProperty":
59 type = CoreItemFactory.NUMBER;
61 case "HeatingCoolingProperty":
64 type = CoreItemFactory.STRING;
66 case "BrightnessProperty":
67 case "HumidityProperty":
68 type = CoreItemFactory.DIMMER;
70 case "ColorModeProperty":
71 type = CoreItemFactory.STRING;
75 type = CoreItemFactory.COLOR;
78 case "ColorTemperatureProperty":
79 type = CoreItemFactory.DIMMER;
83 type = CoreItemFactory.CONTACT;
84 tag = "ContactSensor";
86 case "TargetTemperatureProperty":
87 type = CoreItemFactory.NUMBER;
88 tag = "TargetTemperature";
90 case "TemperatureProperty":
91 type = CoreItemFactory.NUMBER;
92 tag = "CurrentTemperature";
94 case "ThermostatModeProperty":
97 if ((propertyMetadata.unit != null)
98 && propertyMetadata.unit.toLowerCase(Locale.ENGLISH).equals("percent")) {
99 type = CoreItemFactory.DIMMER;
101 type = CoreItemFactory.NUMBER;
105 switch (propertyMetadata.type.toLowerCase(Locale.ENGLISH)) {
107 type = CoreItemFactory.SWITCH;
112 type = CoreItemFactory.NUMBER;
115 type = CoreItemFactory.STRING;
121 return new ItemType(type, tag);
125 * The item type description
127 public static class ItemType {
128 private final String type;
129 private final @Nullable String tag;
131 ItemType(String type, @Nullable String tag) {
136 public String getType() {
140 public @Nullable String getTag() {