Search in sources :

Example 46 with ThingUID

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

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

the class FSInternetRadioDiscoveryParticipantJavaTest method validDiscoveryResultIfWithoutBaseUrl.

/**
 * Verify valid DiscoveryResult with FSInterntRadio device without base URL.
 *
 * @throws ValidationException
 */
@SuppressWarnings("null")
@Test
public void validDiscoveryResultIfWithoutBaseUrl() throws ValidationException {
    RemoteDevice fsInternetRadioDeviceWithoutUrl = createDefaultFSInternetRadioDevice(null);
    final DiscoveryResult result = discoveryParticipant.createResult(fsInternetRadioDeviceWithoutUrl);
    assertEquals(new ThingUID(DEFAULT_RADIO_THING_UID), result.getThingUID());
    assertEquals(FSInternetRadioBindingConstants.THING_TYPE_RADIO, result.getThingTypeUID());
    assertEquals(DEFAULT_RADIO_MANIFACTURER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MANUFACTURER));
    assertEquals(DEFAULT_RADIO_MODEL_NUMBER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MODEL));
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) RemoteDevice(org.jupnp.model.meta.RemoteDevice) Test(org.junit.Test)

Example 48 with ThingUID

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

the class HueBridgeNupnpDiscovery method discoverHueBridges.

/**
 * Discover available Hue Bridges and then add them in the discovery inbox
 */
private void discoverHueBridges() {
    for (BridgeJsonParameters bridge : getBridgeList()) {
        if (isReachableAndValidHueBridge(bridge)) {
            String host = bridge.getInternalIpAddress();
            String serialNumber = bridge.getId().substring(0, 6) + bridge.getId().substring(10);
            ThingUID uid = new ThingUID(THING_TYPE_BRIDGE, serialNumber);
            DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(buildProperties(host, serialNumber)).withLabel(LABEL_PATTERN.replace("IP", host)).withRepresentationProperty(SERIAL_NUMBER).build();
            thingDiscovered(result);
        }
    }
}
Also used : DiscoveryResult(org.eclipse.smarthome.config.discovery.DiscoveryResult) ThingUID(org.eclipse.smarthome.core.thing.ThingUID)

Example 49 with ThingUID

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

the class ModelRestrictedFirmwareUpdateServiceOSGiTest method testGetModelRestrictedFirmwareStatusInfo.

@Test
public void testGetModelRestrictedFirmwareStatusInfo() {
    // given two things of the same thing type but with different models, both with firmware 1.0.0 installed
    ThingUID thingUID1 = createAndRegisterThing(THING_ID_1, MODEL_ID_1, VERSION_1_0_0).getUID();
    ThingUID thingUID2 = createAndRegisterThing(THING_ID_2, MODEL_ID_2, VERSION_1_0_0).getUID();
    // given a firmware provider that provides different firmwares for the different models
    registerService(createFirmwareProvider(createModelRestrictedFirmware(MODEL_ID_1, VERSION_1_0_1), createModelRestrictedFirmware(MODEL_ID_2, VERSION_1_0_2)));
    // then there is an update to 1.0.1 available for thing1
    FirmwareStatusInfo firmwareStatusInfoA = firmwareUpdateService.getFirmwareStatusInfo(thingUID1);
    assertThat(firmwareStatusInfoA.getFirmwareStatus(), is(UPDATE_EXECUTABLE));
    assertThat(firmwareStatusInfoA.getUpdatableFirmwareUID().getFirmwareVersion(), is(VERSION_1_0_1));
    // and then there is an update to 1.0.2 available for thing2
    FirmwareStatusInfo firmwareStatusInfoB = firmwareUpdateService.getFirmwareStatusInfo(thingUID2);
    assertThat(firmwareStatusInfoB.getFirmwareStatus(), is(UPDATE_EXECUTABLE));
    assertThat(firmwareStatusInfoB.getUpdatableFirmwareUID().getFirmwareVersion(), is(VERSION_1_0_2));
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 50 with ThingUID

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

the class ChannelStateDescriptionProviderOSGiTest method presentItemStateDescription.

/**
 * Assert that item's state description is present.
 */
@Test
public void presentItemStateDescription() throws ItemNotFoundException {
    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    ManagedThingProvider managedThingProvider = getService(ManagedThingProvider.class);
    Thing thing = thingRegistry.createThingOfType(new ThingTypeUID("hue:lamp"), new ThingUID("hue:lamp:lamp1"), null, "test thing", new Configuration());
    assertNotNull(thing);
    managedThingProvider.add(thing);
    ItemChannelLink link = new ItemChannelLink("TestItem", getChannel(thing, "1").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem2", getChannel(thing, "2").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem3", getChannel(thing, "3").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem4", getChannel(thing, "4").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem5", getChannel(thing, "5").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem6", getChannel(thing, "6").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem7_1", getChannel(thing, "7_1").getUID());
    linkRegistry.add(link);
    link = new ItemChannelLink("TestItem7_2", getChannel(thing, "7_2").getUID());
    linkRegistry.add(link);
    // 
    final Collection<Item> items = itemRegistry.getItems();
    assertEquals(false, items.isEmpty());
    Item item = itemRegistry.getItem("TestItem");
    assertEquals("Number", item.getType());
    StateDescription state = item.getStateDescription();
    assertNotNull(state);
    assertEquals(BigDecimal.ZERO, state.getMinimum());
    assertEquals(BigDecimal.valueOf(100), state.getMaximum());
    assertEquals(BigDecimal.TEN, state.getStep());
    assertEquals("%d Peek", state.getPattern());
    assertEquals(true, state.isReadOnly());
    List<StateOption> opts = state.getOptions();
    assertEquals(1, opts.size());
    final StateOption opt = opts.get(0);
    assertEquals("SOUND", opt.getValue());
    assertEquals("My great sound.", opt.getLabel());
    item = itemRegistry.getItem("TestItem2");
    assertEquals("Number", item.getType());
    state = item.getStateDescription();
    assertNotNull(state);
    assertEquals(BigDecimal.ZERO, state.getMinimum());
    assertEquals(BigDecimal.valueOf(256), state.getMaximum());
    assertEquals(BigDecimal.valueOf(8), state.getStep());
    assertEquals("%.0f", state.getPattern());
    assertEquals(false, state.isReadOnly());
    opts = state.getOptions();
    assertEquals(0, opts.size());
    item = itemRegistry.getItem("TestItem3");
    assertEquals("String", item.getType());
    state = item.getStateDescription();
    assertNotNull(state);
    assertNull(state.getMinimum());
    assertNull(state.getMaximum());
    assertNull(state.getStep());
    assertEquals("%s", state.getPattern());
    assertEquals(false, state.isReadOnly());
    opts = state.getOptions();
    assertEquals(0, opts.size());
    item = itemRegistry.getItem("TestItem4");
    assertEquals("Color", item.getType());
    state = item.getStateDescription();
    assertNull(state);
    item = itemRegistry.getItem("TestItem5");
    assertEquals("Dimmer", item.getType());
    state = item.getStateDescription();
    assertNull(state);
    item = itemRegistry.getItem("TestItem6");
    assertEquals("Switch", item.getType());
    state = item.getStateDescription();
    assertNull(state);
    item = itemRegistry.getItem("TestItem7_1");
    assertEquals("Number", item.getType());
    state = item.getStateDescription();
    assertNotNull(state);
    assertEquals(BigDecimal.valueOf(10), state.getMinimum());
    assertEquals(BigDecimal.valueOf(100), state.getMaximum());
    assertEquals(BigDecimal.valueOf(5), state.getStep());
    assertEquals("VALUE %d", state.getPattern());
    assertEquals(false, state.isReadOnly());
    opts = state.getOptions();
    assertNotNull(opts);
    assertEquals(2, opts.size());
    final StateOption opt0 = opts.get(0);
    assertNotNull(opt0);
    assertEquals(opt0.getValue(), "value0");
    assertEquals(opt0.getLabel(), "label0");
    final StateOption opt1 = opts.get(1);
    assertNotNull(opt1);
    assertEquals(opt1.getValue(), "value1");
    assertEquals(opt1.getLabel(), "label1");
    item = itemRegistry.getItem("TestItem7_2");
    assertEquals("Number", item.getType());
    state = item.getStateDescription();
    assertNotNull(state);
    assertEquals(BigDecimal.valueOf(1), state.getMinimum());
    assertEquals(BigDecimal.valueOf(101), state.getMaximum());
    assertEquals(BigDecimal.valueOf(20), state.getStep());
    assertEquals("NEW %d Peek", state.getPattern());
    assertEquals(true, state.isReadOnly());
    opts = state.getOptions();
    assertNotNull(opts);
    assertEquals(1, opts.size());
    final StateOption opt2 = opts.get(0);
    assertEquals("SOUND", opt2.getValue());
    assertEquals("My great sound.", opt2.getLabel());
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) SwitchItem(org.eclipse.smarthome.core.library.items.SwitchItem) ColorItem(org.eclipse.smarthome.core.library.items.ColorItem) Item(org.eclipse.smarthome.core.items.Item) StringItem(org.eclipse.smarthome.core.library.items.StringItem) DimmerItem(org.eclipse.smarthome.core.library.items.DimmerItem) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ManagedThingProvider(org.eclipse.smarthome.core.thing.ManagedThingProvider) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing) StateOption(org.eclipse.smarthome.core.types.StateOption) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) StateDescription(org.eclipse.smarthome.core.types.StateDescription) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

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