Search in sources :

Example 46 with ChannelUID

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

the class ThingBuilderTest method testWithoutChannel.

@Test
public void testWithoutChannel() {
    ThingBuilder thingBuilder = ThingBuilder.create(THING_TYPE_UID, THING_UID);
    // 
    thingBuilder.withChannels(// 
    ChannelBuilder.create(new ChannelUID(THING_UID, "channel1"), "").build(), ChannelBuilder.create(new ChannelUID(THING_UID, "channel2"), "").build());
    thingBuilder.withoutChannel(new ChannelUID(THING_UID, "channel1"));
    assertThat(thingBuilder.build().getChannels().size(), is(equalTo(1)));
    assertThat(thingBuilder.build().getChannels().get(0).getUID().getId(), is(equalTo("channel2")));
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Test(org.junit.Test)

Example 47 with ChannelUID

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

the class GenericItemChannelLinkProviderJavaTest method testNoAmnesia.

@SuppressWarnings("unchecked")
@Test
public void testNoAmnesia() throws Exception {
    GenericItemChannelLinkProvider provider = new GenericItemChannelLinkProvider();
    provider.addProviderChangeListener(listener);
    provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, "Number", ITEM, CHANNEL, new Configuration());
    provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    assertThat(provider.getAll().size(), is(1));
    assertThat(provider.getAll().iterator().next().toString(), is(LINK));
    verify(listener, only()).added(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
    reset(listener);
    provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    provider.processBindingConfiguration(ITEMS_TESTMODEL_NAME, "Number", ITEM, CHANNEL, new Configuration());
    provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    assertThat(provider.getAll().size(), is(1));
    assertThat(provider.getAll().iterator().next().toString(), is(LINK));
    verify(listener, only()).updated(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
    reset(listener);
    provider.startConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    provider.stopConfigurationUpdate(ITEMS_TESTMODEL_NAME);
    assertThat(provider.getAll().size(), is(0));
    verify(listener, only()).removed(same(provider), eq(new ItemChannelLink(ITEM, new ChannelUID(CHANNEL))));
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) GenericItemChannelLinkProvider(org.eclipse.smarthome.model.thing.internal.GenericItemChannelLinkProvider) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 48 with ChannelUID

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

the class DeviceHandler method loadOutputChannel.

private void loadOutputChannel(ChannelTypeUID channelTypeUID, String acceptedItemType) {
    if (channelTypeUID == null || acceptedItemType == null) {
        return;
    }
    currentChannel = channelTypeUID.getId();
    List<Channel> channelList = new LinkedList<Channel>(this.getThing().getChannels());
    boolean channelIsAlreadyLoaded = false;
    boolean channelListChanged = false;
    if (!channelList.isEmpty()) {
        Iterator<Channel> channelInter = channelList.iterator();
        while (channelInter.hasNext()) {
            Channel eshChannel = channelInter.next();
            if (DsChannelTypeProvider.isOutputChannel(eshChannel.getUID().getId())) {
                if (!eshChannel.getUID().getId().equals(currentChannel) && !(device.isShade() && eshChannel.getUID().getId().equals(DsChannelTypeProvider.SHADE))) {
                    channelInter.remove();
                    channelListChanged = true;
                } else {
                    if (!eshChannel.getUID().getId().equals(DsChannelTypeProvider.SHADE)) {
                        channelIsAlreadyLoaded = true;
                    }
                }
            }
        }
    }
    if (!channelIsAlreadyLoaded && currentChannel != null) {
        Channel channel = ChannelBuilder.create(new ChannelUID(this.getThing().getUID(), channelTypeUID.getId()), acceptedItemType).withType(channelTypeUID).build();
        channelList.add(channel);
        channelListChanged = true;
    }
    if (channelListChanged) {
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withChannels(channelList);
        updateThing(thingBuilder.build());
        logger.debug("load channel: {} with item: {}", channelTypeUID.getAsString(), acceptedItemType);
    }
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) LinkedList(java.util.LinkedList)

Example 49 with ChannelUID

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

the class ConnectedBluetoothHandler method activateChannel.

protected void activateChannel(@Nullable BluetoothCharacteristic characteristic, ChannelTypeUID channelTypeUID, @Nullable String name) {
    if (characteristic != null) {
        String channelId = name != null ? name : characteristic.getGattCharacteristic().name();
        if (channelId == null) {
            // use the type id as a fallback
            channelId = channelTypeUID.getId();
        }
        if (getThing().getChannel(channelId) == null) {
            // the channel does not exist yet, so let's add it
            ThingBuilder updatedThing = editThing();
            Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), channelId), "Number").withType(channelTypeUID).build();
            updatedThing.withChannel(channel);
            updateThing(updatedThing.build());
            logger.debug("Added channel '{}' to Thing '{}'", channelId, getThing().getUID());
        }
        deviceCharacteristics.add(characteristic);
        device.enableNotifications(characteristic);
        if (isLinked(channelId)) {
            device.readCharacteristic(characteristic);
        }
    } else {
        logger.debug("Characteristic is null - not activating any channel.");
    }
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel)

Example 50 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID 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)

Aggregations

ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)69 Test (org.junit.Test)31 Thing (org.eclipse.smarthome.core.thing.Thing)24 Channel (org.eclipse.smarthome.core.thing.Channel)16 JavaTest (org.eclipse.smarthome.test.java.JavaTest)14 Configuration (org.eclipse.smarthome.config.core.Configuration)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)9 Item (org.eclipse.smarthome.core.items.Item)7 Command (org.eclipse.smarthome.core.types.Command)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)7 DmxBridgeHandler (org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler)6 StringItem (org.eclipse.smarthome.core.library.items.StringItem)6 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)6 BaseThingHandler (org.eclipse.smarthome.core.thing.binding.BaseThingHandler)6 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)6 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)6 NonNull (org.eclipse.jdt.annotation.NonNull)5 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)5 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)5