Search in sources :

Example 1 with ItemChannelLinkRegistry

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));
    }
}
Also used : ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) StateDescriptionFragment(org.openhab.core.types.StateDescriptionFragment)

Example 2 with ItemChannelLinkRegistry

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);
    }
}
Also used : ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry)

Example 3 with ItemChannelLinkRegistry

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);
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) ChannelUID(org.openhab.core.thing.ChannelUID) RESTResource(org.openhab.core.io.rest.RESTResource) ItemChannelLink(org.openhab.core.thing.link.ItemChannelLink) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with ItemChannelLinkRegistry

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);
        }
    });
}
Also used : ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ReadyService(org.openhab.core.service.ReadyService) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ThingManager(org.openhab.core.thing.ThingManager) ItemRegistry(org.openhab.core.items.ItemRegistry) ReadyMarker(org.openhab.core.service.ReadyMarker) URI(java.net.URI) ThingRegistry(org.openhab.core.thing.ThingRegistry) StorageService(org.openhab.core.storage.StorageService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ItemChannelLinkRegistry

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);
}
Also used : Locale(java.util.Locale) ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) EventPublisher(org.openhab.core.events.EventPublisher) Bundle(org.osgi.framework.Bundle) ReadyService(org.openhab.core.service.ReadyService) ItemRegistry(org.openhab.core.items.ItemRegistry) BundleResolver(org.openhab.core.util.BundleResolver) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ThingTypeMigrationService(org.openhab.core.thing.ThingTypeMigrationService) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ItemChannelLinkRegistry(org.openhab.core.thing.link.ItemChannelLinkRegistry) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ReadyMarker(org.openhab.core.service.ReadyMarker) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ItemChannelLinkRegistry (org.openhab.core.thing.link.ItemChannelLinkRegistry)6 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ItemRegistry (org.openhab.core.items.ItemRegistry)2 ReadyMarker (org.openhab.core.service.ReadyMarker)2 ReadyService (org.openhab.core.service.ReadyService)2 ChannelUID (org.openhab.core.thing.ChannelUID)2 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)2 ItemChannelLink (org.openhab.core.thing.link.ItemChannelLink)2 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)2 StateDescriptionFragment (org.openhab.core.types.StateDescriptionFragment)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 URI (java.net.URI)1 Locale (java.util.Locale)1 EventPublisher (org.openhab.core.events.EventPublisher)1 RESTResource (org.openhab.core.io.rest.RESTResource)1 StorageService (org.openhab.core.storage.StorageService)1 Channel (org.openhab.core.thing.Channel)1 ThingManager (org.openhab.core.thing.ThingManager)1 ThingRegistry (org.openhab.core.thing.ThingRegistry)1 ThingTypeMigrationService (org.openhab.core.thing.ThingTypeMigrationService)1