Search in sources :

Example 46 with ItemChannelLink

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

the class ChannelLinkNotifierOSGiTest method updateLinks.

private void updateLinks(Thing thing, String itemSuffix) {
    forEachThingChannelUID(thing, channelUID -> {
        String itemName = getItemName(thing, channelUID, itemSuffix);
        managedItemChannelLinkProvider.update(new ItemChannelLink(itemName, channelUID));
    });
}
Also used : ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink)

Example 47 with ItemChannelLink

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

the class FeedHandlerTest method initializeItem.

private void initializeItem(ChannelUID channelUID) {
    // Create new item
    ItemRegistry itemRegistry = getService(ItemRegistry.class);
    assertThat(itemRegistry, is(notNullValue()));
    StringItem newItem = new StringItem(ITEM_NAME);
    // Add item state change listener
    StateChangeListener updateListener = new StateChangeListener() {

        @Override
        public void stateChanged(Item item, State oldState, State newState) {
        }

        @Override
        public void stateUpdated(Item item, State state) {
            currentItemState = (StringType) state;
        }
    };
    newItem.addStateChangeListener(updateListener);
    itemRegistry.add(newItem);
    // Add item channel link
    ManagedItemChannelLinkProvider itemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat(itemChannelLinkProvider, is(notNullValue()));
    itemChannelLinkProvider.add(new ItemChannelLink(ITEM_NAME, channelUID));
}
Also used : Item(org.openhab.core.items.Item) StringItem(org.openhab.core.library.items.StringItem) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) State(org.openhab.core.types.State) StateChangeListener(org.openhab.core.items.StateChangeListener) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemRegistry(org.openhab.core.items.ItemRegistry) StringItem(org.openhab.core.library.items.StringItem)

Example 48 with ItemChannelLink

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

the class AbstractModbusOSGiTest method linkItem.

protected void linkItem(String itemName, ChannelUID channelUID) {
    logger.debug("Linking {} <-> {}", itemName, channelUID);
    ItemChannelLink link = new ItemChannelLink(itemName, channelUID);
    assertThat(addedLinks.contains(link), not(equalTo(true)));
    itemChannelLinkProvider.add(link);
    addedLinks.add(link);
}
Also used : ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink)

Example 49 with ItemChannelLink

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

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.openhab.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.openhab.core.thing.ChannelUID) ThingUID(org.openhab.core.thing.ThingUID) Channel(org.openhab.core.thing.Channel) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ThingHandler(org.openhab.core.thing.binding.ThingHandler) NtpHandler(org.openhab.binding.ntp.internal.handler.NtpHandler) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem)

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