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