Search in sources :

Example 1 with ItemChannelLink

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

the class LinkConsoleCommandExtension method removeChannelLink.

private void removeChannelLink(Console console, String itemName, ChannelUID channelUID) {
    ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUID);
    ItemChannelLink removedItemChannelLink = itemChannelLinkRegistry.remove(itemChannelLink.getUID());
    if (removedItemChannelLink != null) {
        console.println("Link " + itemChannelLink.toString() + "successfully removed.");
    } else {
        console.println("Could not remove link " + itemChannelLink.toString() + ".");
    }
}
Also used : ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink)

Example 2 with ItemChannelLink

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

the class ChannelItemProviderTest method testItemRemoval_itemFromOtherProvider.

@Test
public void testItemRemoval_itemFromOtherProvider() throws Exception {
    provider.linkRegistryListener.added(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
    resetAndPrepareListener();
    provider.itemRegistryListener.beforeAdding(new NumberItem(ITEM_NAME));
    verify(listener, only()).removed(same(provider), same(ITEM));
    verify(listener, never()).added(same(provider), same(ITEM));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) Test(org.junit.Test)

Example 3 with ItemChannelLink

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

the class GenericItemChannelLinkProvider method createItemChannelLink.

private void createItemChannelLink(String context, String itemName, String channelUID, Configuration configuration) throws BindingConfigParseException {
    ChannelUID channelUIDObject = null;
    try {
        channelUIDObject = new ChannelUID(channelUID);
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException(e.getMessage());
    }
    ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUIDObject, configuration);
    Set<String> itemNames = contextMap.get(context);
    if (itemNames == null) {
        itemNames = new HashSet<>();
        contextMap.put(context, itemNames);
    }
    itemNames.add(itemName);
    if (previousItemNames != null) {
        previousItemNames.remove(itemName);
    }
    Set<ItemChannelLink> links = itemChannelLinkMap.get(itemName);
    if (links == null) {
        itemChannelLinkMap.put(itemName, links = new HashSet<>());
    }
    if (!links.contains(itemChannelLink)) {
        links.add(itemChannelLink);
        notifyListenersAboutAddedElement(itemChannelLink);
    } else {
        notifyListenersAboutUpdatedElement(itemChannelLink, itemChannelLink);
    }
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) HashSet(java.util.HashSet)

Example 4 with ItemChannelLink

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

the class ChannelItemProviderTest method testItemCreation_alreadyExists.

@Test
public void testItemCreation_alreadyExists() throws Exception {
    when(itemRegistry.get(eq(ITEM_NAME))).thenReturn(ITEM);
    provider.linkRegistryListener.added(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
    verify(listener, never()).added(same(provider), same(ITEM));
}
Also used : ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) Test(org.junit.Test)

Example 5 with ItemChannelLink

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

the class ChannelItemProviderTest method testItemCreation_notThere.

@Test
public void testItemCreation_notThere() throws Exception {
    provider.linkRegistryListener.added(new ItemChannelLink(ITEM_NAME, CHANNEL_UID));
    verify(listener, only()).added(same(provider), same(ITEM));
}
Also used : ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) Test(org.junit.Test)

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