2 * Copyright (c) 2010-2020 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.io.neeo.internal.models;
15 import java.util.Objects;
17 import org.apache.commons.lang.StringUtils;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.core.thing.type.ChannelType;
23 * Defines the various NEEO capability types
25 * @author Tim Roberts - Initial Contribution
28 public enum NeeoCapabilityType {
29 /** Represents the NEEO BUTTON capability */
31 /** Represents the NEEO SWITCH capability */
33 /** Represents the NEEO SLIDER capability */
35 /** Represents the NEEO SENSOR capability */
37 /** Represents the NEEO TEXT LABEL capability */
38 TEXTLABEL("textlabel"),
39 /** Represents the NEEO IMAGE URL capability */
41 /** Represents the NEEO directory capability */
42 DIRECTORY("directory"),
44 /** Represents the NEEO CUSTOM SENSOR capability */
45 SENSOR_CUSTOM("custom"),
46 /** Represents the NEEO RANGE SENSOR capability */
47 SENSOR_RANGE("range"),
48 /** Represents the NEEO BINARY SENSOR capability */
49 SENSOR_BINARY("binary"),
50 /** Represents the NEEO POWER SENSOR capability */
51 SENSOR_POWER("power"),
52 /** Represents no capability (and should be excluded) */
55 /** The text value of the enum */
56 private final String text;
59 * Constructs the NeeoCapabilityType using the specified text
61 * @param text the text
63 private NeeoCapabilityType(final String text) {
64 Objects.requireNonNull(text, "text is required");
69 * Parses the text into a NeeoCapabilityType enum (ignoring case)
71 * @param text the text to parse
72 * @return the NeeoCapabilityType type
74 public static NeeoCapabilityType parse(final String text) {
75 if (StringUtils.isEmpty(text)) {
78 for (NeeoCapabilityType enm : NeeoCapabilityType.values()) {
79 if (StringUtils.equalsIgnoreCase(text, enm.text)) {
88 * Guess the {@link NeeoCapabilityType} for the given {@link ChannelType}
90 * @param channelType the possibly null channel type
91 * @return the best guess {@link NeeoCapabilityType}
93 public static NeeoCapabilityType guessType(@Nullable ChannelType channelType) {
94 if (channelType == null || StringUtils.isEmpty(channelType.getItemType())) {
95 return NeeoCapabilityType.EXCLUDE;
98 switch (channelType.getItemType().toLowerCase()) {
101 case "rollershutter":
102 return NeeoCapabilityType.SWITCH;
107 return NeeoCapabilityType.TEXTLABEL;
110 return NeeoCapabilityType.SLIDER;
112 return NeeoCapabilityType.EXCLUDE;
117 public String toString() {