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.io.neeo.internal.models;
15 import java.util.Objects;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.thing.type.ChannelType;
22 * Defines the various NEEO capability types
24 * @author Tim Roberts - Initial Contribution
27 public enum NeeoCapabilityType {
28 /** Represents the NEEO BUTTON capability */
30 /** Represents the NEEO SWITCH capability */
32 /** Represents the NEEO SLIDER capability */
34 /** Represents the NEEO SENSOR capability */
36 /** Represents the NEEO TEXT LABEL capability */
37 TEXTLABEL("textlabel"),
38 /** Represents the NEEO IMAGE URL capability */
40 /** Represents the NEEO directory capability */
41 DIRECTORY("directory"),
43 /** Represents the NEEO CUSTOM SENSOR capability */
44 SENSOR_CUSTOM("custom"),
45 /** Represents the NEEO RANGE SENSOR capability */
46 SENSOR_RANGE("range"),
47 /** Represents the NEEO BINARY SENSOR capability */
48 SENSOR_BINARY("binary"),
49 /** Represents the NEEO POWER SENSOR capability */
50 SENSOR_POWER("power"),
51 /** Represents no capability (and should be excluded) */
54 /** The text value of the enum */
55 private final String text;
58 * Constructs the NeeoCapabilityType using the specified text
60 * @param text the text
62 private NeeoCapabilityType(final String text) {
63 Objects.requireNonNull(text, "text is required");
68 * Parses the text into a NeeoCapabilityType enum (ignoring case)
70 * @param text the text to parse
71 * @return the NeeoCapabilityType type
73 public static NeeoCapabilityType parse(final String text) {
77 for (NeeoCapabilityType enm : NeeoCapabilityType.values()) {
78 if (text.equalsIgnoreCase(enm.text)) {
87 * Guess the {@link NeeoCapabilityType} for the given {@link ChannelType}
89 * @param channelType the possibly null channel type
90 * @return the best guess {@link NeeoCapabilityType}
92 public static NeeoCapabilityType guessType(@Nullable ChannelType channelType) {
93 String itemType = channelType == null ? null : channelType.getItemType();
94 if (channelType == null || itemType == null || itemType.isEmpty()) {
95 return NeeoCapabilityType.EXCLUDE;
98 switch (itemType.toLowerCase()) {
101 case "rollershutter":
102 return NeeoCapabilityType.SWITCH;
107 return NeeoCapabilityType.TEXTLABEL;
110 return NeeoCapabilityType.SLIDER;
112 return NeeoCapabilityType.EXCLUDE;
117 public String toString() {