Search in sources :

Example 31 with DiscoveryResult

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

the class InboxConsoleCommandExtension method printInboxEntries.

private void printInboxEntries(Console console, List<DiscoveryResult> discoveryResults) {
    if (discoveryResults.isEmpty()) {
        console.println("No inbox entries found.");
    }
    for (DiscoveryResult discoveryResult : discoveryResults) {
        ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID();
        ThingUID thingUID = discoveryResult.getThingUID();
        String label = discoveryResult.getLabel();
        DiscoveryResultFlag flag = discoveryResult.getFlag();
        ThingUID bridgeId = discoveryResult.getBridgeUID();
        Map<String, Object> properties = discoveryResult.getProperties();
        String representationProperty = discoveryResult.getRepresentationProperty();
        String timestamp = new Date(discoveryResult.getTimestamp()).toString();
        String timeToLive = discoveryResult.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED ? "UNLIMITED" : "" + discoveryResult.getTimeToLive();
        console.println(String.format("%s [%s]: %s [thingId=%s, bridgeId=%s, properties=%s, representationProperty=%s, timestamp=%s, timeToLive=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties, representationProperty, timestamp, timeToLive));
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) DiscoveryResultFlag(org.eclipse.smarthome.config.discovery.DiscoveryResultFlag) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Date(java.util.Date)

Example 32 with DiscoveryResult

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

the class AutomaticInboxProcessorTest method testThingWhenNoRepresentationPropertySet.

@Test
public void testThingWhenNoRepresentationPropertySet() {
    inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty(DEVICE_ID_KEY, DEVICE_ID).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_UID)));
    when(thing.getProperties()).thenReturn(Collections.emptyMap());
    when(thingStatusInfoChangedEvent.getStatusInfo()).thenReturn(new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null));
    when(thingStatusInfoChangedEvent.getThingUID()).thenReturn(THING_UID);
    inboxAutoIgnore.receive(thingStatusInfoChangedEvent);
    results = inbox.stream().filter(withFlag(DiscoveryResultFlag.IGNORED)).collect(Collectors.toList());
    assertThat(results.size(), is(0));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingStatusInfo(org.eclipse.smarthome.core.thing.ThingStatusInfo) Test(org.junit.Test)

Example 33 with DiscoveryResult

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

the class PersistentInboxTest method testApproveNormalization.

@Test
public void testApproveNormalization() throws Exception {
    DiscoveryResult result = DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build();
    configureConfigDescriptionRegistryMock("foo", Type.TEXT);
    when(storage.getValues()).thenReturn(Collections.singletonList(result));
    inbox.approve(THING_UID, "Test");
    assertTrue(lastAddedThing.getConfiguration().get("foo") instanceof String);
    assertEquals("3", lastAddedThing.getConfiguration().get("foo"));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) Test(org.junit.Test)

Example 34 with DiscoveryResult

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

the class PersistentInboxTest method testEmittedAddedResultIsReadFromStorage.

@Test
public void testEmittedAddedResultIsReadFromStorage() {
    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(// 
    null).thenReturn(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", "bar").build());
    inbox.add(result);
    // 1st call checks existence of the result in the storage (returns null)
    // 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<InboxAddedEvent> eventCaptor = ArgumentCaptor.forClass(InboxAddedEvent.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) InboxAddedEvent(org.eclipse.smarthome.config.discovery.inbox.events.InboxAddedEvent) Test(org.junit.Test)

Example 35 with DiscoveryResult

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

the class HueLightDiscoveryServiceOSGiTest method hueLightRegistration.

@Test
public void hueLightRegistration() {
    FullLight light = new FullLight();
    light.setId("1");
    light.setModelID("LCT001");
    light.setType("Extended color light");
    AsyncResultWrapper<DiscoveryResult> resultWrapper = new AsyncResultWrapper<DiscoveryResult>();
    registerDiscoveryListener(new DiscoveryListener() {

        @Override
        public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
            resultWrapper.set(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;
        }
    });
    discoveryService.onLightAdded(null, light);
    waitForAssert(() -> {
        assertTrue(resultWrapper.isSet());
    });
    final DiscoveryResult result = resultWrapper.getWrappedObject();
    assertThat(result.getFlag(), is(DiscoveryResultFlag.NEW));
    assertThat(result.getThingUID().toString(), is("hue:0210:testBridge:" + light.getId()));
    assertThat(result.getThingTypeUID(), is(THING_TYPE_EXTENDED_COLOR_LIGHT));
    assertThat(result.getBridgeUID(), is(hueBridge.getUID()));
    assertThat(result.getProperties().get(LIGHT_ID), is(light.getId()));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) AsyncResultWrapper(org.eclipse.smarthome.test.AsyncResultWrapper) 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) HueLightDiscoveryService(org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) AbstractHueOSGiTest(org.eclipse.smarthome.binding.hue.test.AbstractHueOSGiTest) 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