use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class GenericItemChannelLinkProviderJavaTest method testLinkConfiguration.
@Test
public void testLinkConfiguration() {
Collection<Thing> things = thingRegistry.getAll();
assertThat(things.size(), is(0));
String thingsModel = "Bridge hue:bridge:huebridge [ ipAddress = \"192.168.3.84\", userName = \"19fc3fa6fc870a4280a55f21315631f\" ] {" + //
"LCT001 bulb3 [ lightId = \"3\" ]" + //
"LCT001 bulb4 [ lightId = \"3\" ]" + "}";
modelRepository.addOrRefreshModel(THINGS_TESTMODEL_NAME, new ByteArrayInputStream(thingsModel.getBytes()));
String itemsModel = "Color Light3Color \"Light3 Color\" { channel=\"hue:LCT001:huebridge:bulb3:color\" [ foo=\"bar\", answer=42, always=true ] }" + "Group:Switch:MAX TestSwitches";
modelRepository.addOrRefreshModel(ITEMS_TESTMODEL_NAME, new ByteArrayInputStream(itemsModel.getBytes()));
waitForAssert(() -> {
assertThat(thingRegistry.getAll().size(), is(3));
assertThat(itemRegistry.getItems().size(), is(2));
assertThat(itemChannelLinkRegistry.getAll().size(), is(1));
});
ItemChannelLink link = itemChannelLinkRegistry.get("Light3Color -> hue:LCT001:huebridge:bulb3:color");
assertNotNull(link);
assertEquals("Light3Color", link.getItemName());
assertEquals("hue:LCT001:huebridge:bulb3:color", link.getLinkedUID().toString());
assertEquals("bar", link.getConfiguration().get("foo"));
assertEquals(new BigDecimal(42), link.getConfiguration().get("answer"));
assertEquals(true, link.getConfiguration().get("always"));
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink 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));
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class LinkConsoleCommandExtension method clear.
private void clear(Console console) {
Collection<ItemChannelLink> itemChannelLinks = itemChannelLinkRegistry.getAll();
for (ItemChannelLink itemChannelLink : itemChannelLinks) {
itemChannelLinkRegistry.remove(itemChannelLink.getUID());
}
console.println(itemChannelLinks.size() + " links successfully removed.");
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class LinkConsoleCommandExtension method addChannelLink.
private void addChannelLink(Console console, String itemName, ChannelUID channelUID) {
ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUID);
itemChannelLinkRegistry.add(itemChannelLink);
console.println("Link " + itemChannelLink.toString() + " successfully added.");
}
use of org.eclipse.smarthome.core.thing.link.ItemChannelLink in project smarthome by eclipse.
the class ItemChannelLinkConfigDescriptionProvider method getConfigDescription.
@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
if (SCHEME.equals(uri.getScheme())) {
ItemChannelLink link = itemChannelLinkRegistry.get(uri.getSchemeSpecificPart());
if (link == null) {
return null;
}
Item item = itemRegistry.get(link.getItemName());
if (item == null) {
return null;
}
Thing thing = thingRegistry.get(link.getLinkedUID().getThingUID());
if (thing == null) {
return null;
}
Channel channel = thing.getChannel(link.getLinkedUID().getId());
if (channel == null) {
return null;
}
ConfigDescriptionParameter paramProfile = ConfigDescriptionParameterBuilder.create(PARAM_PROFILE, Type.TEXT).withLabel("Profile").withDescription("the profile to use").withRequired(false).withLimitToOptions(true).withOptions(getOptions(link, item, channel, locale)).build();
return new ConfigDescription(uri, Collections.singletonList(paramProfile));
}
return null;
}
Aggregations