Search in sources :

Example 26 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class BluetoothDiscoveryService method deviceDiscovered.

private void deviceDiscovered(BluetoothAdapter adapter, BluetoothDevice device) {
    for (BluetoothDiscoveryParticipant participant : participants) {
        try {
            DiscoveryResult result = participant.createResult(device);
            if (result != null) {
                thingDiscovered(result);
                return;
            }
        } catch (Exception e) {
            logger.error("Participant '{}' threw an exception", participant.getClass().getName(), e);
        }
    }
    // We did not find a thing type for this device, so let's treat it as a generic one
    String label = device.getName();
    if (label == null || label.length() == 0 || label.equals(device.getAddress().toString().replace(':', '-'))) {
        label = "Bluetooth Device";
    }
    Map<String, Object> properties = new HashMap<>();
    properties.put(BluetoothBindingConstants.CONFIGURATION_ADDRESS, device.getAddress().toString());
    Integer txPower = device.getTxPower();
    if (txPower != null && txPower > 0) {
        properties.put(BluetoothBindingConstants.PROPERTY_TXPOWER, Integer.toString(txPower));
    }
    String manufacturer = BluetoothCompanyIdentifiers.get(device.getManufacturerId());
    if (manufacturer != null) {
        properties.put(Thing.PROPERTY_VENDOR, manufacturer);
        label += " (" + manufacturer + ")";
    }
    ThingUID thingUID = new ThingUID(BluetoothBindingConstants.THING_TYPE_BEACON, adapter.getUID(), device.getAddress().toString().toLowerCase().replace(":", ""));
    // Create the discovery result and add to the inbox
    DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withRepresentationProperty(BluetoothBindingConstants.CONFIGURATION_ADDRESS).withBridge(adapter.getUID()).withLabel(label).build();
    thingDiscovered(discoveryResult);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) BluetoothDiscoveryParticipant(org.eclipse.smarthome.binding.bluetooth.discovery.BluetoothDiscoveryParticipant) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 27 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class TradfriDiscoveryParticipantOSGITest method validDiscoveryResult.

@Test
public void validDiscoveryResult() {
    DiscoveryResult result = discoveryParticipant.createResult(tradfriGateway);
    assertNotNull(result);
    assertThat(result.getProperties().get(Thing.PROPERTY_FIRMWARE_VERSION), is("1.1"));
    assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
    assertThat(result.getThingUID(), is(new ThingUID("tradfri:gateway:gw1234567890ab")));
    assertThat(result.getThingTypeUID(), is(GATEWAY_TYPE_UID));
    assertThat(result.getBridgeUID(), is(nullValue()));
    assertThat(result.getProperties().get(Thing.PROPERTY_VENDOR), is("IKEA of Sweden"));
    assertThat(result.getProperties().get(GATEWAY_CONFIG_HOST), is("192.168.0.5"));
    assertThat(result.getProperties().get(GATEWAY_CONFIG_PORT), is(1234));
    assertThat(result.getRepresentationProperty(), is(GATEWAY_CONFIG_HOST));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 28 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class TradfriDiscoveryServiceTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    when(handler.getThing()).thenReturn(BridgeBuilder.create(GATEWAY_TYPE_UID, "1").build());
    discovery = new TradfriDiscoveryService(handler);
    listener = new DiscoveryListener() {

        @Override
        public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
        }

        @Override
        public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
            discoveryResult = result;
        }

        @Override
        public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
            return null;
        }
    };
    discovery.addDiscoveryListener(listener);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Collection(java.util.Collection) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) TradfriDiscoveryService(org.eclipse.smarthome.binding.tradfri.internal.discovery.TradfriDiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) TradfriDiscoveryService(org.eclipse.smarthome.binding.tradfri.internal.discovery.TradfriDiscoveryService) Before(org.junit.Before)

Example 29 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class PersistentInbox method setFlag.

@Override
public void setFlag(ThingUID thingUID, DiscoveryResultFlag flag) {
    DiscoveryResult result = get(thingUID);
    if (result instanceof DiscoveryResultImpl) {
        DiscoveryResultImpl resultImpl = (DiscoveryResultImpl) result;
        resultImpl.setFlag((flag == null) ? DiscoveryResultFlag.NEW : flag);
        discoveryResultStorage.put(resultImpl.getThingUID().toString(), resultImpl);
        notifyListeners(resultImpl, EventType.updated);
    } else {
        logger.warn("Cannot set flag for result of instance type '{}'", result.getClass().getName());
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult)

Example 30 with DiscoveryResult

use of org.eclipse.smarthome.config.discovery.DiscoveryResult in project smarthome by eclipse.

the class PersistentInbox method removeResultsForBridge.

private void removeResultsForBridge(ThingUID bridgeUID) {
    for (ThingUID thingUID : getResultsForBridge(bridgeUID)) {
        DiscoveryResult discoveryResult = get(thingUID);
        if (discoveryResult != null) {
            this.discoveryResultStorage.remove(thingUID.toString());
            notifyListeners(discoveryResult, EventType.removed);
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) InboxPredicates.forThingUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Aggregations

DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)42 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)29 HashMap (java.util.HashMap)16 Test (org.junit.Test)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)12 Collection (java.util.Collection)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)4 ThingStatusInfo (org.eclipse.smarthome.core.thing.ThingStatusInfo)4 DiscoveryResultFlag (org.eclipse.smarthome.config.discovery.DiscoveryResultFlag)3 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Date (java.util.Date)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors (java.util.stream.Collectors)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 Configuration (org.eclipse.smarthome.config.core.Configuration)2