]> git.basschouten.com Git - openhab-addons.git/blob
ff428865fcd0bf082f9b8072004c954021f50207
[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.bluetooth.bluegiga.internal.enumeration;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * Class to implement the BlueGiga Enumeration <b>AttributeValueType</b>.
20  * <p>
21  * These enumerations are in the Attribute Client class
22  * <p>
23  * Note that this code is autogenerated. Manual changes may be overwritten.
24  *
25  * @author Chris Jackson - Initial contribution of Java code generator
26  */
27 public enum AttributeValueType {
28     /**
29      * Default unknown value
30      */
31     UNKNOWN(-1),
32
33     /**
34      * [0] Value was read
35      */
36     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ(0x0000),
37
38     /**
39      * [1] Value was notified
40      */
41     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_NOTIFY(0x0001),
42
43     /**
44      * [2] Value was indicated
45      */
46     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_INDICATE(0x0002),
47
48     /**
49      * [3] Value was read
50      */
51     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ_BY_TYPE(0x0003),
52
53     /**
54      * [4] Value was part of a long attribute
55      */
56     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ_BLOB(0x0004),
57
58     /**
59      * [5] Value was indicated and the remote device is waiting for a confirmation. Indicate
60      * Confirm command can be used to send a confirmation.
61      */
62     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_INDICATE_RSP_REQ(0x0005);
63
64     /**
65      * A mapping between the integer code and its corresponding type to
66      * facilitate lookup by code.
67      */
68     private static Map<Integer, AttributeValueType> codeMapping;
69
70     private int key;
71
72     private AttributeValueType(int key) {
73         this.key = key;
74     }
75
76     private static void initMapping() {
77         codeMapping = new HashMap<>();
78         for (AttributeValueType s : values()) {
79             codeMapping.put(s.key, s);
80         }
81     }
82
83     /**
84      * Lookup function based on the type code. Returns null if the code does not exist.
85      *
86      * @param attributeValueType
87      *            the code to lookup
88      * @return enumeration value.
89      */
90     public static AttributeValueType getAttributeValueType(int attributeValueType) {
91         if (codeMapping == null) {
92             initMapping();
93         }
94
95         if (codeMapping.get(attributeValueType) == null) {
96             return UNKNOWN;
97         }
98
99         return codeMapping.get(attributeValueType);
100     }
101
102     /**
103      * Returns the BlueGiga protocol defined value for this enum
104      *
105      * @return the BGAPI enumeration key
106      */
107     public int getKey() {
108         return key;
109     }
110 }