]> git.basschouten.com Git - openhab-addons.git/blob
02f938f887b8f3c5010f6df44527e129063741e5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.neeo.internal.models;
14
15 import java.util.Objects;
16
17 import org.apache.commons.lang.StringUtils;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.core.thing.type.ChannelKind;
20
21 /**
22  * Enumeration of channel kinds (item or trigger)
23  *
24  * @author Tim Roberts - Initial Contribution
25  */
26 @NonNullByDefault
27 public enum NeeoDeviceChannelKind {
28     /** Represents an item */
29     ITEM("item"),
30     /** Represents an trigger item */
31     TRIGGER("trigger");
32
33     /** The text value of the enum */
34     private final String text;
35
36     /**
37      * Constructs the NeeoDeviceChannelKind using the specified text
38      *
39      * @param text the text
40      */
41     private NeeoDeviceChannelKind(final String text) {
42         Objects.requireNonNull(text, "text is required");
43         this.text = text;
44     }
45
46     /**
47      * Parses the text into a NeeoDeviceChannelKind enum (ignoring case)
48      *
49      * @param text the text to parse
50      * @return the NeeoDeviceChannelKind type
51      */
52     public static NeeoDeviceChannelKind parse(final String text) {
53         if (StringUtils.isEmpty(text)) {
54             return ITEM;
55         }
56         for (NeeoDeviceChannelKind enm : NeeoDeviceChannelKind.values()) {
57             if (StringUtils.equalsIgnoreCase(text, enm.text)) {
58                 return enm;
59             }
60         }
61
62         return ITEM;
63     }
64
65     /**
66      * Returns the {@link NeeoDeviceChannelKind} for the given {@link ChannelKind}
67      *
68      * @param kind a non-null {@link ChannelKind}
69      * @return a non-null {@link NeeoDeviceChannelKind}
70      */
71     public static NeeoDeviceChannelKind get(ChannelKind kind) {
72         Objects.requireNonNull(kind, "kind cannot be null");
73         return kind == ChannelKind.TRIGGER ? TRIGGER : ITEM;
74     }
75
76     @Override
77     public String toString() {
78         return text;
79     }
80 }