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.discovery;
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;
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.
27 * @author Connor Petty - Initial Contribution
30 public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
32 private BluetoothDevice delegate;
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;
40 public BluetoothDiscoveryDevice(BluetoothDevice device) {
41 super(device.getAdapter(), device.getAddress());
42 this.delegate = device;
46 protected @NonNull BluetoothDevice getDelegate() {
51 * Returns the model of the Bluetooth device.
53 * @return The devices model, null if not known
55 public @Nullable String getModel() {
60 * Returns the serial number of the Bluetooth device.
62 * @return The serial model, null if not known
64 public @Nullable String getSerialNumber() {
69 * Returns the hardware revision of the Bluetooth device.
71 * @return The hardware revision, null if not known
73 public @Nullable String getHardwareRevision() {
74 return hardwareRevision;
78 * Returns the firmware revision of the Bluetooth device.
80 * @return The firmware revision, null if not known
82 public @Nullable String getFirmwareRevision() {
83 return firmwareRevision;
87 * Returns the software revision of the Bluetooth device.
89 * @return The software revision, null if not known
91 public @Nullable String getSoftwareRevision() {
92 return softwareRevision;
96 public String toString() {
97 StringBuilder builder = new StringBuilder();
98 builder.append("BluetoothDevice [address=");
99 builder.append(address);
100 builder.append(", manufacturer=");
102 Integer manufacturer = getManufacturerId();
103 builder.append(manufacturer);
104 if (BluetoothCompanyIdentifiers.get(manufacturer) != null) {
105 builder.append(" (");
106 builder.append(BluetoothCompanyIdentifiers.get(manufacturer));
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());
124 return builder.toString();