]> git.basschouten.com Git - openhab-addons.git/blob
0dfaa292a7788e50edda3ed62991d54abade69f0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.thing.type.ChannelKind;
19
20 /**
21  * Enumeration of channel kinds (item or trigger)
22  *
23  * @author Tim Roberts - Initial Contribution
24  */
25 @NonNullByDefault
26 public enum NeeoDeviceChannelKind {
27     /** Represents an item */
28     ITEM("item"),
29     /** Represents a trigger item */
30     TRIGGER("trigger");
31
32     /** The text value of the enum */
33     private final String text;
34
35     /**
36      * Constructs the NeeoDeviceChannelKind using the specified text
37      *
38      * @param text the text
39      */
40     private NeeoDeviceChannelKind(final String text) {
41         Objects.requireNonNull(text, "text is required");
42         this.text = text;
43     }
44
45     /**
46      * Parses the text into a NeeoDeviceChannelKind enum (ignoring case)
47      *
48      * @param text the text to parse
49      * @return the NeeoDeviceChannelKind type
50      */
51     public static NeeoDeviceChannelKind parse(final String text) {
52         if (text.isEmpty()) {
53             return ITEM;
54         }
55         for (NeeoDeviceChannelKind enm : NeeoDeviceChannelKind.values()) {
56             if (text.equalsIgnoreCase(enm.text)) {
57                 return enm;
58             }
59         }
60
61         return ITEM;
62     }
63
64     /**
65      * Returns the {@link NeeoDeviceChannelKind} for the given {@link ChannelKind}
66      *
67      * @param kind a non-null {@link ChannelKind}
68      * @return a non-null {@link NeeoDeviceChannelKind}
69      */
70     public static NeeoDeviceChannelKind get(ChannelKind kind) {
71         Objects.requireNonNull(kind, "kind cannot be null");
72         return kind == ChannelKind.TRIGGER ? TRIGGER : ITEM;
73     }
74
75     @Override
76     public String toString() {
77         return text;
78     }
79 }