Search in sources :

Example 71 with ThingUID

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));
    }
}
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 72 with ThingUID

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());
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 73 with ThingUID

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));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 74 with 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());
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 75 with ThingUID

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);
            }
        }
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) CancellationException(java.util.concurrent.CancellationException)

Aggregations

ThingUID (org.eclipse.smarthome.core.thing.ThingUID)99 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)29 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)27 Thing (org.eclipse.smarthome.core.thing.Thing)26 Test (org.junit.Test)25 HashMap (java.util.HashMap)21 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)14 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Path (javax.ws.rs.Path)9 JsonObject (com.google.gson.JsonObject)8 JsonParser (com.google.gson.JsonParser)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Locale (java.util.Locale)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 Consumes (javax.ws.rs.Consumes)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Collection (java.util.Collection)4 GET (javax.ws.rs.GET)4 InboxPredicates.forThingUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingUID)4