Search in sources :

Example 16 with DiscoveryResult

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

the class AutomaticInboxProcessorTest method testThingWithConfigWentOnline.

@Test
public void testThingWithConfigWentOnline() {
    inbox.add(DiscoveryResultBuilder.create(THING_UID2).withProperty(OTHER_KEY, OTHER_VALUE).withRepresentationProperty(OTHER_KEY).build());
    List<DiscoveryResult> results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
    assertThat(results.size(), is(1));
    assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2)));
    when(thingRegistry.get(THING_UID2)).thenReturn(thing2);
    when(thingStatusInfoChangedEvent.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID2);
    inboxAutoIgnore.receive(thingStatusInfoChangedEvent);
    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.NEW)).collect(Collectors.toList());
    assertThat(results.size(), is(0));
    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
    assertThat(results.size(), is(1));
    assertThat(results.get(0).getThingUID(), is(equalTo(THING_UID2)));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Test(org.junit.Test)

Example 17 with DiscoveryResult

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

the class PersistentInboxTest method testEmittedUpdatedResultIsReadFromStorage.

@Test
public void testEmittedUpdatedResultIsReadFromStorage() {
    DiscoveryResult result = DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build();
    EventPublisher eventPublisher = mock(EventPublisher.class);
    inbox.setEventPublisher(eventPublisher);
    // 
    when(storage.get(THING_UID.toString())).thenReturn(// 
    result).thenReturn(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", "bar").build());
    inbox.add(result);
    // 1st call checks existence of the result in the storage (returns the original result)
    // 2nd call retrieves the stored instance before the event gets emitted
    // (modified due to storage mock configuration)
    verify(storage, times(2)).get(THING_UID.toString());
    ArgumentCaptor<InboxUpdatedEvent> eventCaptor = ArgumentCaptor.forClass(InboxUpdatedEvent.class);
    verify(eventPublisher).post(eventCaptor.capture());
    assertThat(eventCaptor.getValue().getDiscoveryResult().properties, hasEntry("foo", "bar"));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) InboxUpdatedEvent(org.eclipse.smarthome.config.discovery.inbox.events.InboxUpdatedEvent) Test(org.junit.Test)

Example 18 with DiscoveryResult

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

the class MDNSDiscoveryService method scan.

private void scan() {
    for (MDNSDiscoveryParticipant participant : participants) {
        ServiceInfo[] services = mdnsClient.list(participant.getServiceType());
        logger.debug("{} services found for {}", services.length, participant.getServiceType());
        for (ServiceInfo service : services) {
            DiscoveryResult result = participant.createResult(service);
            if (result != null) {
                thingDiscovered(result);
            }
        }
    }
    for (org.eclipse.smarthome.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant : oldParticipants) {
        ServiceInfo[] services = mdnsClient.list(participant.getServiceType());
        logger.debug("{} services found for {}", services.length, participant.getServiceType());
        for (ServiceInfo service : services) {
            DiscoveryResult result = participant.createResult(service);
            if (result != null) {
                thingDiscovered(result);
            }
        }
    }
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) MDNSDiscoveryParticipant(org.eclipse.smarthome.config.discovery.mdns.MDNSDiscoveryParticipant)

Example 19 with DiscoveryResult

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

the class FSInternetRadioDiscoveryParticipant method createResult.

@Override
public DiscoveryResult createResult(RemoteDevice device) {
    final ThingUID uid = getThingUID(device);
    if (uid != null) {
        final Map<String, Object> properties = new HashMap<>(1);
        final String ip = getIp(device);
        if (ip != null) {
            properties.put(CONFIG_PROPERTY_IP, ip);
            // add manufacturer and model, if provided
            final String manufacturer = getManufacturer(device);
            if (manufacturer != null) {
                properties.put(PROPERTY_MANUFACTURER, manufacturer);
            }
            final String model = getModel(device);
            if (model != null) {
                properties.put(PROPERTY_MODEL, model);
            }
            final DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(device.getDisplayString()).build();
            return result;
        }
    }
    return null;
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 20 with DiscoveryResult

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

the class HueBridgeNupnpDiscoveryOSGITest method invalidBridgesAreNotDiscovered.

@Test
public void invalidBridgesAreNotDiscovered() {
    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());
    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;
        }
    });
    // missing ip
    discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // missing id
    discoveryResult = "[{\"id\":\"\",\"internalipaddress\":192.168.30.22}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // id < 10
    discoveryResult = "[{\"id\":\"012345678\",\"internalipaddress\":192.168.30.22}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // bridge indicator not part of id
    discoveryResult = "[{\"id\":\"0123456789\",\"internalipaddress\":192.168.30.22}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // bridge indicator at wrong position (-1)
    discoveryResult = "[{\"id\":\"01234" + HueBridgeNupnpDiscovery.BRIDGE_INDICATOR + "7891\",\"internalipaddress\":192.168.30.22}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // bridge indicator at wrong position (+1)
    discoveryResult = "[{\"id\":\"0123456" + HueBridgeNupnpDiscovery.BRIDGE_INDICATOR + "7891\",\"internalipaddress\":192.168.30.22}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // bridge not reachable
    discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":192.168.30.1}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    // invalid bridge description
    expBridgeDescription = "";
    ;
    discoveryResult = "[{\"id\":\"001788fffe20057f\",\"internalipaddress\":" + ip1 + "}]";
    sut.startScan();
    waitForAssert(() -> {
        assertThat(results.size(), is(0));
    });
    waitForAssert(() -> {
        assertThat(inbox.stream().filter(forThingTypeUID(BRIDGE_THING_TYPE_UID)).collect(Collectors.toList()).size(), is(0));
    });
}
Also used : 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)

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