use of org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice in project smarthome by eclipse.
the class BlueZBridgeHandler method getDevice.
@Override
public BluetoothDevice getDevice(BluetoothAddress address) {
if (devices.containsKey(address.toString())) {
return devices.get(address.toString());
} else {
synchronized (devices) {
if (devices.containsKey(address.toString())) {
return devices.get(address.toString());
} else {
BlueZBluetoothDevice device = new BlueZBluetoothDevice(this, address, "");
device.initialize();
devices.put(address.toString(), device);
return device;
}
}
}
}
use of org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice in project smarthome by eclipse.
the class BlueZBridgeHandler method dispose.
@Override
public void dispose() {
if (discoveryJob != null) {
discoveryJob.cancel(true);
discoveryJob = null;
}
for (BluetoothDevice device : devices.values()) {
((BlueZBluetoothDevice) device).dispose();
}
devices.clear();
}
use of org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice in project smarthome by eclipse.
the class BlueZBridgeHandler method checkForNewDevices.
private void checkForNewDevices() {
logger.debug("Refreshing Bluetooth device list...");
Set<String> newAddresses = new HashSet<>();
List<tinyb.BluetoothDevice> tinybDevices = adapter.getDevices();
logger.debug("Found {} Bluetooth devices.", tinybDevices.size());
synchronized (tinybDeviceCache) {
tinybDeviceCache.clear();
tinybDevices.stream().forEach(d -> tinybDeviceCache.put(d.getAddress(), d));
}
for (tinyb.BluetoothDevice tinybDevice : tinybDevices) {
synchronized (devices) {
newAddresses.add(tinybDevice.getAddress());
BlueZBluetoothDevice device = (BlueZBluetoothDevice) devices.get(tinybDevice.getAddress());
if (device == null) {
createAndRegisterBlueZDevice(tinybDevice);
} else {
device.updateTinybDevice(tinybDevice);
notifyDiscoveryListeners(device);
}
}
}
// clean up orphaned entries
synchronized (devices) {
Set<String> oldAdresses = devices.keySet();
for (String address : oldAdresses) {
if (!newAddresses.contains(address)) {
devices.remove(address);
}
}
}
}
use of org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice in project smarthome by eclipse.
the class BlueZBridgeHandler method createAndRegisterBlueZDevice.
private BlueZBluetoothDevice createAndRegisterBlueZDevice(tinyb.BluetoothDevice tinybDevice) {
BlueZBluetoothDevice device = new BlueZBluetoothDevice(this, tinybDevice);
device.initialize();
devices.put(tinybDevice.getAddress(), device);
notifyDiscoveryListeners(device);
return device;
}
Aggregations