Search in sources :

Example 1 with DiscoveryService

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

the class DiscoveryServiceRegistryImpl method abortScans.

private boolean abortScans(Set<DiscoveryService> discoveryServices) {
    boolean allServicesAborted = true;
    for (DiscoveryService discoveryService : discoveryServices) {
        Collection<ThingTypeUID> supportedThingTypes = discoveryService.getSupportedThingTypes();
        try {
            logger.debug("Abort scan for thing types '{}' on '{}'...", supportedThingTypes, discoveryService.getClass().getName());
            discoveryService.abortScan();
            logger.debug("Scan for thing types '{}' aborted on '{}'.", supportedThingTypes, discoveryService.getClass().getName());
        } catch (Exception ex) {
            logger.error("Cannot abort scan for thing types '{}' on '{}'!", supportedThingTypes, discoveryService.getClass().getName(), ex);
            allServicesAborted = false;
        }
    }
    return allServicesAborted;
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) ExtendedDiscoveryService(org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) CancellationException(java.util.concurrent.CancellationException)

Example 2 with DiscoveryService

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

the class DiscoveryServiceRegistryImpl method startScans.

private boolean startScans(Set<DiscoveryService> discoveryServices, @Nullable ScanListener listener) {
    boolean atLeastOneDiscoveryServiceHasBeenStarted = false;
    if (discoveryServices.size() > 1) {
        logger.debug("Trying to start {} scans with an aggregating listener.", discoveryServices.size());
        AggregatingScanListener aggregatingScanListener = new AggregatingScanListener(discoveryServices.size(), listener);
        for (DiscoveryService discoveryService : discoveryServices) {
            if (startScan(discoveryService, aggregatingScanListener)) {
                atLeastOneDiscoveryServiceHasBeenStarted = true;
            } else {
                logger.debug("Reducing number of discovery services in aggregating listener, because discovery service failed to start scan.");
                aggregatingScanListener.reduceNumberOfDiscoveryServices();
            }
        }
    } else {
        if (startScan(discoveryServices.iterator().next(), listener)) {
            atLeastOneDiscoveryServiceHasBeenStarted = true;
        }
    }
    return atLeastOneDiscoveryServiceHasBeenStarted;
}
Also used : ExtendedDiscoveryService(org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService)

Example 3 with DiscoveryService

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

the class HueLightDiscoveryServiceOSGiTest method setUp.

@Before
public void setUp() {
    registerVolatileStorageService();
    thingRegistry = getService(ThingRegistry.class, ThingRegistry.class);
    assertThat(thingRegistry, is(notNullValue()));
    Configuration configuration = new Configuration();
    configuration.put(HOST, "1.2.3.4");
    configuration.put(USER_NAME, "testUserName");
    configuration.put(SERIAL_NUMBER, "testSerialNumber");
    hueBridge = (Bridge) thingRegistry.createThingOfType(BRIDGE_THING_TYPE_UID, BRIDGE_THING_UID, null, "Bridge", configuration);
    assertThat(hueBridge, is(notNullValue()));
    thingRegistry.add(hueBridge);
    hueBridgeHandler = getThingHandler(hueBridge, HueBridgeHandler.class);
    assertThat(hueBridgeHandler, is(notNullValue()));
    discoveryService = getService(DiscoveryService.class, HueLightDiscoveryService.class);
    assertThat(discoveryService, is(notNullValue()));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) HueLightDiscoveryService(org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService) HueBridgeHandler(org.eclipse.smarthome.binding.hue.handler.HueBridgeHandler) DiscoveryService(org.eclipse.smarthome.config.discovery.DiscoveryService) HueLightDiscoveryService(org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) Before(org.junit.Before)

Example 4 with DiscoveryService

use of org.eclipse.smarthome.config.discovery.DiscoveryService 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)

Example 5 with DiscoveryService

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

the class TradfriDiscoveryServiceTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    when(handler.getThing()).thenReturn(BridgeBuilder.create(GATEWAY_TYPE_UID, "1").build());
    discovery = new TradfriDiscoveryService(handler);
    listener = new DiscoveryListener() {

        @Override
        public void thingRemoved(DiscoveryService source, ThingUID thingUID) {
        }

        @Override
        public void thingDiscovered(DiscoveryService source, DiscoveryResult result) {
            discoveryResult = result;
        }

        @Override
        public Collection<ThingUID> removeOlderResults(DiscoveryService source, long timestamp, Collection<ThingTypeUID> thingTypeUIDs, ThingUID bridgeUID) {
            return null;
        }
    };
    discovery.addDiscoveryListener(listener);
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) 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) TradfriDiscoveryService(org.eclipse.smarthome.binding.tradfri.internal.discovery.TradfriDiscoveryService) DiscoveryListener(org.eclipse.smarthome.config.discovery.DiscoveryListener) TradfriDiscoveryService(org.eclipse.smarthome.binding.tradfri.internal.discovery.TradfriDiscoveryService) Before(org.junit.Before)

Aggregations

DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)8 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)5 Collection (java.util.Collection)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)4 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)4 ExtendedDiscoveryService (org.eclipse.smarthome.config.discovery.ExtendedDiscoveryService)3 Before (org.junit.Before)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 HueLightDiscoveryService (org.eclipse.smarthome.binding.hue.internal.discovery.HueLightDiscoveryService)2 InboxPredicates.forThingTypeUID (org.eclipse.smarthome.config.discovery.inbox.InboxPredicates.forThingTypeUID)2 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)2 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 CancellationException (java.util.concurrent.CancellationException)1 Collectors (java.util.stream.Collectors)1 HueBindingConstants (org.eclipse.smarthome.binding.hue.HueBindingConstants)1 HueBridgeHandler (org.eclipse.smarthome.binding.hue.handler.HueBridgeHandler)1