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.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;
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.
26 * @author Connor Petty - Initial Contribution
29 public class BluetoothDiscoveryDevice extends DelegateBluetoothDevice {
31 private @NonNullByDefault({}) BluetoothDevice delegate;
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;
39 public BluetoothDiscoveryDevice(BluetoothDevice device) {
40 super(device.getAdapter(), device.getAddress());
41 this.delegate = device;
45 protected @Nullable BluetoothDevice getDelegate() {
50 * Returns the model of the Bluetooth device.
52 * @return The devices model, null if not known
54 public @Nullable String getModel() {
59 * Returns the serial number of the Bluetooth device.
61 * @return The serial model, null if not known
63 public @Nullable String getSerialNumber() {
68 * Returns the hardware revision of the Bluetooth device.
70 * @return The hardware revision, null if not known
72 public @Nullable String getHardwareRevision() {
73 return hardwareRevision;
77 * Returns the firmware revision of the Bluetooth device.
79 * @return The firmware revision, null if not known
81 public @Nullable String getFirmwareRevision() {
82 return firmwareRevision;
86 * Returns the software revision of the Bluetooth device.
88 * @return The software revision, null if not known
90 public @Nullable String getSoftwareRevision() {
91 return softwareRevision;
95 public String toString() {
96 StringBuilder builder = new StringBuilder();
97 builder.append("BluetoothDevice [address=");
98 builder.append(address);
99 builder.append(", manufacturer=");
101 Integer manufacturer = getManufacturerId();
102 builder.append(manufacturer);
103 if (BluetoothCompanyIdentifiers.get(manufacturer) != null) {
104 builder.append(" (");
105 builder.append(BluetoothCompanyIdentifiers.get(manufacturer));
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());
123 return builder.toString();