Search in sources :

Example 1 with BlueZBluetoothDevice

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;
            }
        }
    }
}
Also used : BlueZBluetoothDevice(org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice)

Example 2 with BlueZBluetoothDevice

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();
}
Also used : BluetoothDevice(org.eclipse.smarthome.binding.bluetooth.BluetoothDevice) BlueZBluetoothDevice(org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice) BlueZBluetoothDevice(org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice)

Example 3 with BlueZBluetoothDevice

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);
            }
        }
    }
}
Also used : BluetoothDevice(org.eclipse.smarthome.binding.bluetooth.BluetoothDevice) BlueZBluetoothDevice(org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice) BlueZBluetoothDevice(org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice) HashSet(java.util.HashSet)

Example 4 with BlueZBluetoothDevice

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;
}
Also used : BlueZBluetoothDevice(org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice)

Aggregations

BlueZBluetoothDevice (org.eclipse.smarthome.binding.bluetooth.bluez.BlueZBluetoothDevice)4 BluetoothDevice (org.eclipse.smarthome.binding.bluetooth.BluetoothDevice)2 HashSet (java.util.HashSet)1