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