use of org.eclipse.smarthome.core.thing.ThingUID 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.core.thing.ThingUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testCache.
@Test
public void testCache() {
ScanListener mockScanListener1 = mock(ScanListener.class);
ArgumentCaptor<DiscoveryResult> discoveryResultCaptor = ArgumentCaptor.forClass(DiscoveryResult.class);
ThingUID thingUID = new ThingUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE, "foo");
ThingTypeUID thingTypeUID = new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE);
inbox.remove(thingUID);
discoveryServiceRegistry.startScan(thingTypeUID, mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(1)).onFinished());
discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener);
waitForAssert(() -> {
verify(mockDiscoveryListener, times(1)).thingDiscovered(any(), discoveryResultCaptor.capture());
});
assertTrue(discoveryResultCaptor.getValue().getProperties().isEmpty());
discoveryServiceRegistry.removeDiscoveryListener(mockDiscoveryListener);
extendedDiscoveryServiceMock.setDiscoveryProperties(Collections.singletonMap("ip", "0.0.0.0"));
inbox.remove(thingUID);
discoveryServiceRegistry.startScan(thingTypeUID, mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(2)).onFinished());
discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener);
waitForAssert(() -> {
verify(mockDiscoveryListener, times(2)).thingDiscovered(any(), discoveryResultCaptor.capture());
});
assertEquals(Collections.singletonMap("ip", "0.0.0.0"), discoveryResultCaptor.getValue().getProperties());
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class DiscoveryServiceRegistryOSGiTest method testGetExistingDiscoveryResult.
@Test
public void testGetExistingDiscoveryResult() {
ScanListener mockScanListener1 = mock(ScanListener.class);
ThingUID thingUID = new ThingUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE, "foo");
// verify that the callback has been set
assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback);
// verify that the DiscoveryResult cannot be found if it's not there
assertNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingDiscoveryResult(thingUID));
discoveryServiceRegistry.startScan(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), mockScanListener1);
waitForAssert(() -> verify(mockScanListener1, times(1)).onFinished(), 2000, DFL_SLEEP_TIME);
// verify that the existing DiscoveryResult can be accessed
assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingDiscoveryResult(thingUID));
// verify that a non-existing DiscoveryResult can not be accessed
thingUID = new ThingUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE, "bar");
assertNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingDiscoveryResult(thingUID));
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class DiscoveryResultDTOMapper method map.
/**
* Maps discovery result into discovery result data transfer object.
*
* @param discoveryResult the discovery result
* @return the discovery result data transfer object
*/
public static DiscoveryResultDTO map(DiscoveryResult discoveryResult) {
ThingUID thingUID = discoveryResult.getThingUID();
ThingUID bridgeUID = discoveryResult.getBridgeUID();
return new DiscoveryResultDTO(thingUID.toString(), bridgeUID != null ? bridgeUID.toString() : null, discoveryResult.getThingTypeUID().toString(), discoveryResult.getLabel(), discoveryResult.getFlag(), discoveryResult.getProperties(), discoveryResult.getRepresentationProperty());
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class AbstractDiscoveryService method removeOlderResults.
/**
* Call to remove all results of the given types that are older than the
* given timestamp. To remove all left over results after a full scan, this
* method could be called {@link #getTimestampOfLastScan()} as timestamp.
*
* @param timestamp timestamp, older results will be removed
* @param thingTypeUIDs collection of {@code ThingType}s, only results of these
* {@code ThingType}s will be removed; if {@code null} then
* {@link DiscoveryService#getSupportedThingTypes()} will be used
* instead
* @param bridgeUID if not {@code null} only results of that bridge are being removed
*/
protected void removeOlderResults(long timestamp, @Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) {
Collection<ThingUID> removedThings = null;
Collection<ThingTypeUID> toBeRemoved = thingTypeUIDs != null ? thingTypeUIDs : getSupportedThingTypes();
for (DiscoveryListener discoveryListener : discoveryListeners) {
try {
removedThings = discoveryListener.removeOlderResults(this, timestamp, toBeRemoved, bridgeUID);
} catch (Exception e) {
logger.error("An error occurred while calling the discovery listener {}.", discoveryListener.getClass().getName(), e);
}
}
if (removedThings != null) {
synchronized (cachedResults) {
for (ThingUID uid : removedThings) {
cachedResults.remove(uid);
}
}
}
}
Aggregations