]> git.basschouten.com Git - openhab-addons.git/blob
ca17d5c08bf1d65601e26cf2abfb9ee62def29d2
[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>AttributeChangeReason</b>.
20  * <p>
21  * This enumeration contains the reason for an attribute value change.
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 AttributeChangeReason {
28     /**
29      * Default unknown value
30      */
31     UNKNOWN(-1),
32
33     /**
34      * [0] Value was written by remote device using write request
35      */
36     ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_REQUEST(0x0000),
37
38     /**
39      * [1] Value was written by remote device using write command
40      */
41     ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_COMMAND(0x0001),
42
43     /**
44      * [2] Local attribute value was written by the remote device, but the Smart Bluetooth stack is
45      * waiting for the write to be confirmed by the application. User Write Response command should
46      * be used to send the confirmation. For this reason to appear the attribute in the GATT database
47      * must have the user property enabled. See Profile Toolkit Developer Guide for more
48      * information how to enable the user property for an attribute.
49      */
50     ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_REQUEST_USER(0x0002);
51
52     /**
53      * A mapping between the integer code and its corresponding type to
54      * facilitate lookup by code.
55      */
56     private static Map<Integer, AttributeChangeReason> codeMapping;
57
58     private int key;
59
60     private AttributeChangeReason(int key) {
61         this.key = key;
62     }
63
64     private static void initMapping() {
65         codeMapping = new HashMap<>();
66         for (AttributeChangeReason s : values()) {
67             codeMapping.put(s.key, s);
68         }
69     }
70
71     /**
72      * Lookup function based on the type code. Returns null if the code does not exist.
73      *
74      * @param attributeChangeReason
75      *            the code to lookup
76      * @return enumeration value.
77      */
78     public static AttributeChangeReason getAttributeChangeReason(int attributeChangeReason) {
79         if (codeMapping == null) {
80             initMapping();
81         }
82
83         if (codeMapping.get(attributeChangeReason) == null) {
84             return UNKNOWN;
85         }
86
87         return codeMapping.get(attributeChangeReason);
88     }
89
90     /**
91      * Returns the BlueGiga protocol defined value for this enum
92      *
93      * @return the BGAPI enumeration key
94      */
95     public int getKey() {
96         return key;
97     }
98 }