Search in sources :

Example 36 with DiscoveryResult

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

the class HueBridgeNupnpDiscoveryOSGITest method validBridgesAreDiscovered.

@Test
public void validBridgesAreDiscovered() {
    List<DiscoveryResult> oldResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList());
    for (final DiscoveryResult oldResult : oldResults) {
        inbox.remove(oldResult.getThingUID());
    }
    sut = new ConfigurableBridgeNupnpDiscoveryMock();
    registerService(sut, DiscoveryService.class.getName());
    discoveryResult = validBridgeDiscoveryResult;
    final Map<ThingUID, DiscoveryResult> results = new HashMap<>();
    registerDiscoveryListener(new DiscoveryListener() {

        @Override
        public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
            results.put(result.getThingUID(), result);
        }

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

        @Override
        public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
            return null;
        }
    });
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(2));
        assertThat(results.get(BRIDGE_THING_UID_1), is(notNullValue()));
        checkDiscoveryResult(results.get(BRIDGE_THING_UID_1), ip1, sn1);
        assertThat(results.get(BRIDGE_THING_UID_2), is(notNullValue()));
        checkDiscoveryResult(results.get(BRIDGE_THING_UID_2), ip2, sn2);
        final List<DiscoveryResult> inboxResults = inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList());
        assertTrue(inboxResults.size() >= 2);
        assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_1)).findFirst().orElse(null), is(notNullValue()));
        assertThat(inboxResults.stream().filter(result -> result.getThingUID().equals(BRIDGE_THING_UID_2)).findFirst().orElse(null), is(notNullValue()));
    });
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) VolatileStorageService(org.eclipse.smarthome.test.storage.VolatileStorageService) Collection(java.util.Collection) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) InboxPredicates.forThingTypeUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingTypeUID) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) Inbox(org.eclipse.smarthome.config.discovery.inbox.Inbox) Map(java.util.Map) HueBindingConstants(org.eclipse.smarthome.binding.hue.HueBindingConstants) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Assert(org.junit.Assert) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Before(org.junit.Before) HashMap(java.util.HashMap) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Collection(java.util.Collection) InboxPredicates.forThingTypeUID(org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingTypeUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 37 with DiscoveryResult

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

the class HueBridgeDiscoveryParticipantOSGITest method validDiscoveryResult.

@Test
public void validDiscoveryResult() {
    final DiscoveryResult result = discoveryParticipant.createResult(hueDevice);
    assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
    assertThat(result.getThingUID(), is(new ThingUID("hue:bridge:serial123")));
    assertThat(result.getThingTypeUID(), is(THING_TYPE_BRIDGE));
    assertThat(result.getBridgeUID(), is(nullValue()));
    assertThat(result.getProperties().get(HOST), is("1.2.3.4"));
    assertThat(result.getProperties().get(SERIAL_NUMBER), is("serial123"));
    assertThat(result.getRepresentationProperty(), is(SERIAL_NUMBER));
}
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 38 with DiscoveryResult

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

the class HueBridgeDiscoveryParticipant method createResult.

@Override
@Nullable
public DiscoveryResult createResult(RemoteDevice device) {
    ThingUID uid = getThingUID(device);
    if (uid != null) {
        Map<String, Object> properties = new HashMap<>(2);
        properties.put(HOST, device.getDetails().getBaseURL().getHost());
        properties.put(SERIAL_NUMBER, device.getDetails().getSerialNumber());
        DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(device.getDetails().getFriendlyName()).withRepresentationProperty(SERIAL_NUMBER).build();
        return result;
    } else {
        return null;
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 39 with DiscoveryResult

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

the class HueLightDiscoveryService method onLightAddedInternal.

private void onLightAddedInternal(FullLight light) {
    ThingUID thingUID = getThingUID(light);
    ThingTypeUID thingTypeUID = getThingTypeUID(light);
    String modelId = light.getModelID().replaceAll(HueLightHandler.NORMALIZE_ID_REGEX, "_");
    if (thingUID != null && thingTypeUID != null) {
        ThingUID bridgeUID = hueBridgeHandler.getThing().getUID();
        Map<String, Object> properties = new HashMap<>(1);
        properties.put(LIGHT_ID, light.getId());
        properties.put(MODEL_ID, modelId);
        properties.put(LIGHT_UNIQUE_ID, light.getUniqueID());
        DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID).withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(LIGHT_UNIQUE_ID).withLabel(light.getName()).build();
        thingDiscovered(discoveryResult);
    } else {
        logger.debug("discovered unsupported light of type '{}' and model '{}' with id {}", light.getType(), modelId, light.getId());
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 40 with DiscoveryResult

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

the class FSInternetRadioDiscoveryParticipantJavaTest method validDiscoveryResultWithComplete.

/**
 * Verify valid DiscoveryResult with completeFSInterntRadioDevice.
 *
 * @throws ValidationException
 */
@SuppressWarnings("null")
@Test
public void validDiscoveryResultWithComplete() throws ValidationException {
    RemoteDevice completeFSInternetRadioDevice = createDefaultFSInternetRadioDevice(DEFAULT_RADIO_BASE_URL);
    final DiscoveryResult result = discoveryParticipant.createResult(completeFSInternetRadioDevice);
    assertEquals(new ThingUID(DEFAULT_RADIO_THING_UID), result.getThingUID());
    assertEquals(FSInternetRadioBindingConstants.THING_TYPE_RADIO, result.getThingTypeUID());
    assertEquals(DEFAULT_RADIO_MANIFACTURER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MANUFACTURER));
    assertEquals(DEFAULT_RADIO_MODEL_NUMBER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MODEL));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) RemoteDevice(org.jupnp.model.meta.RemoteDevice) Test(org.junit.Test)

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