2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.bluegiga.internal.enumeration;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Class to implement the BlueGiga Enumeration <b>AttributeChangeReason</b>.
24 * This enumeration contains the reason for an attribute value change.
26 * Note that this code is autogenerated. Manual changes may be overwritten.
28 * @author Chris Jackson - Initial contribution of Java code generator
31 public enum AttributeChangeReason {
33 * Default unknown value
38 * [0] Value was written by remote device using write request
40 ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_REQUEST(0x0000),
43 * [1] Value was written by remote device using write command
45 ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_COMMAND(0x0001),
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.
54 ATTRIBUTES_ATTRIBUTE_CHANGE_REASON_WRITE_REQUEST_USER(0x0002);
57 * A mapping between the integer code and its corresponding type to
58 * facilitate lookup by code.
60 private static @Nullable Map<Integer, AttributeChangeReason> codeMapping;
64 private AttributeChangeReason(int key) {
69 * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
71 * @param attributeChangeReason
73 * @return enumeration value.
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);
82 codeMapping = localCodeMapping;
85 return localCodeMapping.getOrDefault(attributeChangeReason, UNKNOWN);
89 * Returns the BlueGiga protocol defined value for this enum
91 * @return the BGAPI enumeration key