use of org.openhab.core.thing.link.ItemChannelLinkRegistry in project openhab-addons by openhab.
the class DeconzDynamicStateDescriptionProvider method setDescriptionFragment.
/**
* Set a state description for a channel. This description will be used when preparing the channel state by
* the framework for presentation. A previous description, if existed, will be replaced.
*
* @param channelUID
* channel UID
* @param stateDescriptionFragment
* state description for the channel
*/
public void setDescriptionFragment(ChannelUID channelUID, StateDescriptionFragment stateDescriptionFragment) {
StateDescriptionFragment oldStateDescriptionFragment = stateDescriptionFragments.get(channelUID);
if (!stateDescriptionFragment.equals(oldStateDescriptionFragment)) {
logger.trace("adding state description for channel {}", channelUID);
stateDescriptionFragments.put(channelUID, stateDescriptionFragment);
ItemChannelLinkRegistry itemChannelLinkRegistry = this.itemChannelLinkRegistry;
postEvent(ThingEventFactory.createChannelDescriptionChangedEvent(channelUID, itemChannelLinkRegistry != null ? itemChannelLinkRegistry.getLinkedItemNames(channelUID) : Set.of(), stateDescriptionFragment, oldStateDescriptionFragment));
}
}
use of org.openhab.core.thing.link.ItemChannelLinkRegistry 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);
}
}
use of org.openhab.core.thing.link.ItemChannelLinkRegistry 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);
}
use of org.openhab.core.thing.link.ItemChannelLinkRegistry in project openhab-core by openhab.
the class ThingManagerOSGiJavaTest method setUp.
@BeforeEach
public void setUp() throws Exception {
configDescriptionChannel = new URI("test:channel");
configDescriptionThing = new URI("test:test");
thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(//
List.of(ChannelBuilder.create(CHANNEL_UID, CoreItemFactory.SWITCH).withLabel("Test Label").withDescription("Test Description").withType(CHANNEL_TYPE_UID).withDefaultTags(Set.of("Test Tag")).build())).build();
registerVolatileStorageService();
managedThingProvider = getService(ManagedThingProvider.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
thingRegistry = getService(ThingRegistry.class);
assertNotNull(thingRegistry);
StorageService storageService;
storageService = getService(StorageService.class);
assertNotNull(storageService);
storage = storageService.getStorage("thing_status_storage");
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
thingManager = getService(ThingManager.class);
assertNotNull(thingManager);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(openhab.xmlThingTypes=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(e);
}
});
}
use of org.openhab.core.thing.link.ItemChannelLinkRegistry in project openhab-core by openhab.
the class ThingManagerOSGiTest method setUp.
@BeforeEach
@SuppressWarnings("null")
public void setUp() {
thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(ChannelBuilder.create(CHANNEL_UID, CoreItemFactory.SWITCH).withKind(ChannelKind.STATE).withType(CHANNEL_TYPE_UID).build()).build();
registerVolatileStorageService();
configurationAdmin = getService(ConfigurationAdmin.class);
assertNotNull(configurationAdmin);
channelTypeProvider = mock(ChannelTypeProvider.class);
when(channelTypeProvider.getChannelType(any(ChannelTypeUID.class), nullable(Locale.class))).thenReturn(ChannelTypeBuilder.state(CHANNEL_TYPE_UID, "label", CoreItemFactory.SWITCH).build());
registerService(channelTypeProvider);
managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
managedThingProvider = getService(ManagedThingProvider.class);
eventPublisher = getService(EventPublisher.class);
itemRegistry = getService(ItemRegistry.class);
assertNotNull(itemRegistry);
itemChannelLinkRegistry = getService(ItemChannelLinkRegistry.class);
assertNotNull(itemChannelLinkRegistry);
readyService = getService(ReadyService.class);
assertNotNull(readyService);
waitForAssert(() -> {
try {
assertThat(bundleContext.getServiceReferences(ReadyMarker.class, "(" + ThingManagerImpl.XML_THING_TYPE + "=" + bundleContext.getBundle().getSymbolicName() + ")"), is(notNullValue()));
} catch (InvalidSyntaxException e) {
fail("Failed to get service reference: " + e.getMessage());
}
});
Bundle bundle = mock(Bundle.class);
when(bundle.getSymbolicName()).thenReturn("org.openhab.core.thing");
BundleResolver bundleResolver = mock(BundleResolver.class);
when(bundleResolver.resolveBundle(any())).thenReturn(bundle);
ThingManagerImpl thingManager = (ThingManagerImpl) getService(ThingTypeMigrationService.class);
thingManager.setBundleResolver(bundleResolver);
}
Aggregations