Search in sources :

Example 11 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class GenericItemChannelLinkProviderJavaTest method testLinkConfiguration.

@Test
public void testLinkConfiguration() {
    Collection<Thing> things = thingRegistry.getAll();
    assertThat(things.size(), is(0));
    String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + // 
    "LCT001 bulb3 [ lightId = \"3\" ]" + // 
    "LCT001 bulb4 [ lightId = \"3\" ]" + "}";
    modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
    String itemsModel = "Color Light3Color \"Light3 Color\" { channel=\"hue:LCT001:huebridge:bulb3:color\" [ foo=\"bar\", answer=42, always=true ] }" + "Group:Switch:MAX TestSwitches";
    modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
    waitForAssert(() -> {
        assertThat(thingRegistry.getAll().size(), is(3));
        assertThat(itemRegistry.getItems().size(), is(2));
        assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
    });
    ItemChannelLink link = itemChannelLinkRegistry.get("Light3Color -> hue:LCT001:huebridge:bulb3:color");
    assertNotNull(link);
    assertEquals("Light3Color", link.getItemName());
    assertEquals("hue:LCT001:huebridge:bulb3:color", link.getLinkedUID().toString());
    assertEquals("bar", link.getConfiguration().get("foo"));
    assertEquals(new BigDecimal(42), link.getConfiguration().get("answer"));
    assertEquals(true, link.getConfiguration().get("always"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) Thing(org.eclipse.smarthome.core.thing.Thing) BigDecimal(java.math.BigDecimal) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 12 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class NtpOSGiTest method initialize.

private void initialize(Configuration configuration, String channelID, String acceptedItemType, Configuration channelConfiguration) {
    configuration.put(NtpBindingConstants.PROPERTY_NTP_SERVER_PORT, TEST_PORT);
    ThingUID ntpUid = new ThingUID(NtpBindingConstants.THING_TYPE_NTP, TEST_THING_ID);
    ChannelUID channelUID = new ChannelUID(ntpUid, channelID);
    Channel channel = ChannelBuilder.create(channelUID, acceptedItemType).withType(channelTypeUID).withConfiguration(channelConfiguration).withLabel("label").withKind(ChannelKind.STATE).build();
    ntpThing = ThingBuilder.create(NtpBindingConstants.THING_TYPE_NTP, ntpUid).withConfiguration(configuration).withChannel(channel).build();
    managedThingProvider.add(ntpThing);
    // Wait for the NTP thing to be added to the ManagedThingProvider.
    ntpHandler = waitForAssert(() -> {
        final ThingHandler thingHandler = ntpThing.getHandler();
        assertThat(thingHandler, is(instanceOf(NtpHandler.class)));
        return (NtpHandler) thingHandler;
    }, DFL_TIMEOUT * 3, DFL_SLEEP_TIME);
    if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_STRING)) {
        testItem = new StringItem(TEST_ITEM_NAME);
    } else if (acceptedItemType.equals(ACCEPTED_ITEM_TYPE_DATE_TIME)) {
        testItem = new DateTimeItem(TEST_ITEM_NAME);
    }
    itemRegistry.add(testItem);
    // Wait for the item , linked to the NTP thing to be added to the
    // ManagedThingProvider.
    final ManagedItemChannelLinkProvider itemChannelLinkProvider = waitForAssert(() -> {
        final ManagedItemChannelLinkProvider tmp = getService(ManagedItemChannelLinkProvider.class);
        assertNotNull(tmp);
        return tmp;
    });
    itemChannelLinkProvider.add(new ItemChannelLink(TEST_ITEM_NAME, channelUID));
}
Also used : ManagedItemChannelLinkProvider(org.eclipse.smarthome.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) NtpHandler(org.eclipse.smarthome.binding.ntp.handler.NtpHandler) DateTimeItem(org.eclipse.smarthome.core.library.items.DateTimeItem) StringItem(org.eclipse.smarthome.core.library.items.StringItem)

Example 13 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class LinkConsoleCommandExtension method clear.

private void clear(Console console) {
    Collection<ItemChannelLink> itemChannelLinks = itemChannelLinkRegistry.getAll();
    for (ItemChannelLink itemChannelLink : itemChannelLinks) {
        itemChannelLinkRegistry.remove(itemChannelLink.getUID());
    }
    console.println(itemChannelLinks.size() + " links successfully removed.");
}
Also used : ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink)

Example 14 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class LinkConsoleCommandExtension method addChannelLink.

private void addChannelLink(Console console, String itemName, ChannelUID channelUID) {
    ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUID);
    itemChannelLinkRegistry.add(itemChannelLink);
    console.println("Link " + itemChannelLink.toString() + " successfully added.");
}
Also used : ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink)

Example 15 with ItemChannelLink

use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.

the class ItemChannelLinkConfigDescriptionProvider method getConfigDescription.

@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
    if (SCHEME.equals(uri.getScheme())) {
        ItemChannelLink link = itemChannelLinkRegistry.get(uri.getSchemeSpecificPart());
        if (link == null) {
            return null;
        }
        Item item = itemRegistry.get(link.getItemName());
        if (item == null) {
            return null;
        }
        Thing thing = thingRegistry.get(link.getLinkedUID().getThingUID());
        if (thing == null) {
            return null;
        }
        Channel channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }
        ConfigDescriptionParameter paramProfile = ConfigDescriptionParameterBuilder.create(PARAM_PROFILE, Type.TEXT).withLabel("Profile").withDescription("the profile to use").withRequired(false).withLimitToOptions(true).withOptions(getOptions(link, item, channel, locale)).build();
        return new ConfigDescription(uri, Collections.singletonList(paramProfile));
    }
    return null;
}
Also used : Item(org.eclipse.smarthome.core.items.Item) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Thing(org.eclipse.smarthome.core.thing.Thing)

Aggregations

ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)17 Test (org.junit.Test)8 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)4 Channel (org.eclipse.smarthome.core.thing.Channel)3 Thing (org.eclipse.smarthome.core.thing.Thing)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Configuration (org.eclipse.smarthome.config.core.Configuration)2 Item (org.eclipse.smarthome.core.items.Item)2 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)2 StringItem (org.eclipse.smarthome.core.library.items.StringItem)2 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Field (java.lang.reflect.Field)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1