]> git.basschouten.com Git - openhab-addons.git/blob
c3294f0da065211135636e65b49f0e4d556e28a3
[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.binding.digitalstrom.internal.lib.climate.constants;
14
15 /**
16  * The {@link ControlStates} contains all digitalSTROM heating control states.
17  *
18  * @author Michael Ochel - Initial contribution
19  * @author Matthias Siegele - Initial contribution
20  */
21 public enum ControlStates {
22
23     INTERNAL((short) 0, "internal"),
24     EXTERNAL((short) 1, "external"),
25     EXBACKUP((short) 2, "exbackup"),
26     EMERGENCY((short) 3, "emergency");
27
28     private final Short id;
29     private final String key;
30     private static final ControlStates[] CONTROL_STATES = new ControlStates[ControlStates.values().length];
31
32     static {
33         for (ControlStates controlState : ControlStates.values()) {
34             CONTROL_STATES[controlState.id] = controlState;
35         }
36     }
37
38     private ControlStates(short id, String key) {
39         this.id = id;
40         this.key = key;
41     }
42
43     /**
44      * Returns the key of the operation mode.
45      *
46      * @return key
47      */
48     public String getKey() {
49         return key;
50     }
51
52     /**
53      * Returns the ID of the operation mode.
54      *
55      * @return ID
56      */
57     public Short getID() {
58         return id;
59     }
60
61     /**
62      * Returns the {@link ControlStates} of the given control state id.
63      *
64      * @param id of the control state
65      * @return control state
66      */
67     public static ControlStates getControlState(short id) {
68         try {
69             return CONTROL_STATES[id];
70         } catch (IndexOutOfBoundsException e) {
71             return null;
72         }
73     }
74 }