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));
}
}
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));
}
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"));
}
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"));
}
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()));
}
Aggregations