Search in sources :

Example 1 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-addons by openhab.

the class AbstractModbusOSGiTest method tearDownAbstractModbusOSGiTest.

@AfterEach
public void tearDownAbstractModbusOSGiTest() throws Exception {
    logger.debug("tearDownAbstractModbusOSGiTest BEGIN");
    swapModbusManagerToReal();
    for (Item item : addedItems) {
        assertNotNull(itemProvider.remove(item.getName()));
    }
    for (Thing thing : addedThings) {
        disposeThing(thing);
    }
    for (ItemChannelLink link : addedLinks) {
        logger.debug("Unlinking {} <-> {}", link.getItemName(), link.getLinkedUID());
        assertNotNull(itemChannelLinkProvider.remove(link.getUID()));
    }
    logger.debug("tearDownAbstractModbusOSGiTest END");
}
Also used : Item(org.openhab.core.items.Item) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) Thing(org.openhab.core.thing.Thing) AfterEach(org.junit.jupiter.api.AfterEach)

Example 2 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-addons by openhab.

the class AbstractMieleThingHandlerTest method linkChannelsToItems.

private void linkChannelsToItems(Thing thing) {
    ItemChannelLinkRegistry itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class, ItemChannelLinkRegistry.class);
    assertNotNull(itemChannelLinkRegistry);
    for (Channel channel : thing.getChannels()) {
        String itemName = channel.getUID().getId();
        assertNotNull(itemName);
        ChannelUID channelUid = channel.getUID();
        assertNotNull(channelUid);
        ItemChannelLink link = itemChannelLinkRegistry.add(new ItemChannelLink(itemName, channelUid));
        assertNotNull(link);
    }
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry)

Example 3 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-addons by openhab.

the class WWNThingHandlerOSGiTest method createAndLinkItems.

protected void createAndLinkItems() {
    thing.getChannels().forEach(c -> {
        String itemName = getItemName(c.getUID().getId());
        Item item = itemFactory.createItem(c.getAcceptedItemType(), itemName);
        if (item != null) {
            itemRegistry.add(item);
        }
        managedItemChannelLinkProvider.add(new ItemChannelLink(itemName, c.getUID()));
    });
}
Also used : Item(org.openhab.core.items.Item) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink)

Example 4 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-addons by openhab.

the class SysteminfoOSGiTest method intializeItem.

private void intializeItem(ChannelUID channelUID, String itemName, String acceptedItemType) {
    if (acceptedItemType.equals("Number")) {
        testItem = new NumberItem(itemName);
    } else if (acceptedItemType.equals("String")) {
        testItem = new StringItem(itemName);
    }
    itemRegistry.add(testItem);
    ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat(itemChannelLinkProvider, is(notNullValue()));
    itemChannelLinkProvider.add(new ItemChannelLink(itemName, channelUID));
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) StringItem(org.openhab.core.library.items.StringItem)

Example 5 with ItemChannelLink

use of org.openhab.core.thing.link.ItemChannelLink in project openhab-core by openhab.

the class ItemChannelLinkResourceOSGiTest method beforeEach.

@BeforeEach
public void beforeEach() {
    registerVolatileStorageService();
    itemChannelLinkResource = getService(RESTResource.class, ItemChannelLinkResource.class);
    assertNotNull(itemChannelLinkResource);
    itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
    assertNotNull(itemChannelLinkRegistry);
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertNotNull(managedItemChannelLinkProvider);
    link1 = new ItemChannelLink(ITEM_NAME1, new ChannelUID(CHANNEL_UID1));
    link2 = new ItemChannelLink(ITEM_NAME2, new ChannelUID(CHANNEL_UID2));
    link3 = new ItemChannelLink(ITEM_NAME3, new ChannelUID(THING_TYPE_UID + ":" + UID + ":3"));
    when(itemChannelLinkProviderMock.getAll()).thenReturn(List.of(link1, link2, link3));
    registerService(itemChannelLinkProviderMock);
    waitForAssert(() -> {
        assertThat(itemChannelLinkRegistry.getAll(), hasSize(3));
    });
    when(uriBuilderMock.build(any())).thenReturn(URI.create(""));
    when(uriInfoMock.getAbsolutePathBuilder()).thenReturn(uriBuilderMock);
    when(uriInfoMock.getPath()).thenReturn("");
    when(httpHeadersMock.getHeaderString(anyString())).thenReturn(null);
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.openhab.core.thing.ChannelUID) RESTResource(org.openhab.core.io.rest.RESTResource) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)49 Test (org.junit.jupiter.api.Test)30 Thing (org.openhab.core.thing.Thing)14 Item (org.openhab.core.items.Item)13 JavaOSGiTest (org.openhab.core.test.java.JavaOSGiTest)13 ChannelUID (org.openhab.core.thing.ChannelUID)11 StringItem (org.openhab.core.library.items.StringItem)8 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)8 Configuration (org.openhab.core.config.core.Configuration)6 NumberItem (org.openhab.core.library.items.NumberItem)6 ThingUID (org.openhab.core.thing.ThingUID)6 Nullable (org.eclipse.jdt.annotation.Nullable)5 Channel (org.openhab.core.thing.Channel)5 ThingRegistry (org.openhab.core.thing.ThingRegistry)5 ThingHandler (org.openhab.core.thing.binding.ThingHandler)5 ThingHandlerCallback (org.openhab.core.thing.binding.ThingHandlerCallback)5 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)5 ArrayList (java.util.ArrayList)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)4