]> git.basschouten.com Git - openhab-addons.git/blob
3acf2bd440dbda8b74a817207c982c4b157225ef
[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.discovery;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.bluetooth.BluetoothCompanyIdentifiers;
18 import org.openhab.binding.bluetooth.BluetoothDevice;
19 import org.openhab.binding.bluetooth.DelegateBluetoothDevice;
20
21 /**
22  * The {@link BluetoothDiscoveryDevice} is the BluetoothDevice subclass passed to
23  * BluetoothDiscoveryParticipants as part of discovery. It includes extra fields
24  * provided for the convenience of participant implementations.
25  *
26  * @author Connor Petty - Initial Contribution
27  */
28 @NonNullByDefault
29 public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
30
31     private @NonNullByDefault({}) BluetoothDevice delegate;
32
33     protected @Nullable String model;
34     protected @Nullable String serialNumber;
35     protected @Nullable String hardwareRevision;
36     protected @Nullable String firmwareRevision;
37     protected @Nullable String softwareRevision;
38
39     public BluetoothDiscoveryDevice(BluetoothDevice device) {
40         super(device.getAdapter(), device.getAddress());
41         this.delegate = device;
42     }
43
44     @Override
45     protected @Nullable BluetoothDevice getDelegate() {
46         return delegate;
47     }
48
49     /**
50      * Returns the model of the Bluetooth device.
51      *
52      * @return The devices model, null if not known
53      */
54     public @Nullable String getModel() {
55         return model;
56     }
57
58     /**
59      * Returns the serial number of the Bluetooth device.
60      *
61      * @return The serial model, null if not known
62      */
63     public @Nullable String getSerialNumber() {
64         return serialNumber;
65     }
66
67     /**
68      * Returns the hardware revision of the Bluetooth device.
69      *
70      * @return The hardware revision, null if not known
71      */
72     public @Nullable String getHardwareRevision() {
73         return hardwareRevision;
74     }
75
76     /**
77      * Returns the firmware revision of the Bluetooth device.
78      *
79      * @return The firmware revision, null if not known
80      */
81     public @Nullable String getFirmwareRevision() {
82         return firmwareRevision;
83     }
84
85     /**
86      * Returns the software revision of the Bluetooth device.
87      *
88      * @return The software revision, null if not known
89      */
90     public @Nullable String getSoftwareRevision() {
91         return softwareRevision;
92     }
93
94     @Override
95     public String toString() {
96         StringBuilder builder = new StringBuilder();
97         builder.append("BluetoothDevice [address=");
98         builder.append(address);
99         builder.append(", manufacturer=");
100
101         Integer manufacturer = getManufacturerId();
102         builder.append(manufacturer);
103         if (BluetoothCompanyIdentifiers.get(manufacturer) != null) {
104             builder.append(" (");
105             builder.append(BluetoothCompanyIdentifiers.get(manufacturer));
106             builder.append(')');
107         }
108         builder.append(", name=");
109         builder.append(getName());
110         builder.append(", model=");
111         builder.append(model);
112         builder.append(", serialNumber=");
113         builder.append(serialNumber);
114         builder.append(", hardwareRevision=");
115         builder.append(hardwareRevision);
116         builder.append(", firmwareRevision=");
117         builder.append(firmwareRevision);
118         builder.append(", softwareRevision=");
119         builder.append(softwareRevision);
120         builder.append(", rssi=");
121         builder.append(getRssi());
122         builder.append(']');
123         return builder.toString();
124     }
125 }