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")));
}
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))));
}
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);
}
}
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.");
}
}
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));
}
Aggregations