2 * Copyright (c) 2010-2020 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.bluez.internal;
15 import java.util.Collection;
16 import java.util.List;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.bluetooth.BluetoothAddress;
22 import com.github.hypfvieh.bluetooth.DeviceManager;
23 import com.github.hypfvieh.bluetooth.wrapper.BluetoothAdapter;
24 import com.github.hypfvieh.bluetooth.wrapper.BluetoothDevice;
27 * This is a threadsafe wrapper for a {@link DeviceManager} that also only exposes the methods
28 * required to implement this binding.
30 * @author Connor Petty - Initial Contribution
33 public class DeviceManagerWrapper {
35 private DeviceManager deviceManager;
37 public DeviceManagerWrapper(DeviceManager deviceManager) {
38 this.deviceManager = deviceManager;
41 public synchronized Collection<BluetoothAdapter> scanForBluetoothAdapters() {
42 return deviceManager.scanForBluetoothAdapters();
45 public synchronized @Nullable BluetoothAdapter getAdapter(BluetoothAddress address) {
46 // we don't use `deviceManager.getAdapter` here since it might perform a scan if the adapter is missing.
47 String addr = address.toString();
48 List<BluetoothAdapter> adapters = deviceManager.getAdapters();
49 if (adapters != null) {
50 for (BluetoothAdapter btAdapter : adapters) {
51 String btAddr = btAdapter.getAddress();
52 if (addr.equalsIgnoreCase(btAddr)) {
60 public synchronized List<BluetoothDevice> getDevices(BluetoothAdapter adapter) {
61 return deviceManager.getDevices(adapter.getAddress(), true);