Search in sources :

Example 21 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class MagicHandlerFactoryTest method shoudlReturnNullForUnknownThingTypeUID.

@Test
public void shoudlReturnNullForUnknownThingTypeUID() {
    Thing thing = mock(Thing.class);
    when(thing.getThingTypeUID()).thenReturn(new ThingTypeUID("anyBinding:someThingType"));
    assertThat(factory.createHandler(thing), is(nullValue()));
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing) Test(org.junit.Test)

Example 22 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class LIRCRemoteDiscoveryService method addRemote.

private void addRemote(ThingUID bridge, String remote) {
    ThingTypeUID uid = LIRCBindingConstants.THING_TYPE_REMOTE;
    ThingUID thingUID = new ThingUID(uid, bridge, remote);
    if (thingUID != null) {
        if (discoveryServiceCallback != null && discoveryServiceCallback.getExistingDiscoveryResult(thingUID) != null) {
            // Ignore this remote as we already know about it
            logger.debug("Remote {}: Already known.", remote);
            return;
        }
        logger.trace("Remote {}: Discovered new remote.", remote);
        Map<String, Object> properties = new HashMap<>(1);
        properties.put(LIRCBindingConstants.PROPERTY_REMOTE, remote);
        DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withLabel(remote).withBridge(bridge).withProperties(properties).build();
        thingDiscovered(discoveryResult);
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) HashMap(java.util.HashMap) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Example 23 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class DiscoveryServiceRegistryOSGiTest method testGetExistingThing.

@Test
public void testGetExistingThing() {
    ThingUID thingUID = new ThingUID(EXTENDED_BINDING_ID, "foo");
    // verify that the callback has been set
    assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback);
    // verify that the thing cannot be found if it's not there
    assertNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingThing(thingUID));
    thingRegistry.add(ThingBuilder.create(new ThingTypeUID(EXTENDED_BINDING_ID, EXTENDED_THING_TYPE), thingUID).build());
    // verify that the existing Thing can be accessed
    assertNotNull(extendedDiscoveryServiceMock.discoveryServiceCallback.getExistingThing(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 24 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID 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 25 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareUpdateServiceTest method setup.

@Before
public void setup() {
    initMocks(this);
    Map<String, String> props1 = new HashMap<>();
    props1.put(Thing.PROPERTY_FIRMWARE_VERSION, V111);
    props1.put(Thing.PROPERTY_MODEL_ID, MODEL1);
    thing1 = ThingBuilder.create(THING_TYPE_UID1, THING1_ID).withProperties(props1).build();
    Map<String, String> props2 = new HashMap<>();
    props2.put(Thing.PROPERTY_FIRMWARE_VERSION, V112);
    props2.put(Thing.PROPERTY_MODEL_ID, MODEL2);
    thing2 = ThingBuilder.create(THING_TYPE_UID1, THING2_ID).withProperties(props2).build();
    Map<String, String> props3 = new HashMap<>();
    props3.put(Thing.PROPERTY_FIRMWARE_VERSION, VALPHA);
    thing3 = ThingBuilder.create(THING_TYPE_UID2, THING3_ID).withProperties(props3).build();
    firmwareUpdateService = new FirmwareUpdateService();
    safeCaller = getService(SafeCaller.class);
    assertNotNull(safeCaller);
    firmwareUpdateService.setSafeCaller(safeCaller);
    handler1 = addHandler(thing1);
    handler2 = addHandler(thing2);
    handler3 = addHandler(thing3);
    firmwareUpdateService.setEventPublisher(mockPublisher);
    when(mockLocaleProvider.getLocale()).thenReturn(Locale.ENGLISH);
    firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
    firmwareRegistry = new FirmwareRegistry();
    firmwareUpdateService.setFirmwareRegistry(firmwareRegistry);
    firmwareUpdateService.setLocaleProvider(mockLocaleProvider);
    firmwareRegistry.setLocaleProvider(mockLocaleProvider);
    when(mockProvider.getFirmware(eq(FW009_EN.getUID()), any())).thenReturn(FW009_EN);
    when(mockProvider.getFirmware(eq(FW111_EN.getUID()), any())).thenReturn(FW111_EN);
    when(mockProvider.getFirmware(eq(FW112_EN.getUID()), any())).thenReturn(FW112_EN);
    when(mockProvider.getFirmware(eq(FWALPHA_EN.getUID()), any())).thenReturn(FWALPHA_EN);
    when(mockProvider.getFirmwares(any(ThingTypeUID.class), any())).then(invocation -> {
        ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
        if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID2.equals(thingTypeUID) || THING_TYPE_UID3.equals(thingTypeUID)) {
            return Collections.emptySet();
        } else {
            return Stream.of(FW009_EN, FW111_EN, FW112_EN).collect(Collectors.toSet());
        }
    });
    firmwareRegistry.addFirmwareProvider(mockProvider);
    firmwareUpdateService.setTranslationProvider(mockTranslationProvider);
    firmwareUpdateService.setConfigDescriptionValidator(getService(ConfigDescriptionValidator.class));
}
Also used : SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) HashMap(java.util.HashMap) ConfigDescriptionValidator(org.eclipse.smarthome.config.core.validation.ConfigDescriptionValidator) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Before(org.junit.Before)

Aggregations

ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)63 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)27 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)25 Thing (org.eclipse.smarthome.core.thing.Thing)12 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)11 Locale (java.util.Locale)10 HashMap (java.util.HashMap)9 Collection (java.util.Collection)5 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)5 Before (org.junit.Before)5 Configuration (org.eclipse.smarthome.config.core.Configuration)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)3 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)3 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)3 ArrayList (java.util.ArrayList)2