Search in sources :

Example 1 with ChannelTypeRegistry

use of org.openhab.core.thing.type.ChannelTypeRegistry in project openhab-core by openhab.

the class ThingFactoryHelper method withChannelTypeRegistry.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static <T> T withChannelTypeRegistry(Function<ChannelTypeRegistry, T> consumer) {
    BundleContext bundleContext = FrameworkUtil.getBundle(ThingFactoryHelper.class).getBundleContext();
    ServiceReference ref = bundleContext.getServiceReference(ChannelTypeRegistry.class.getName());
    try {
        ChannelTypeRegistry channelTypeRegistry = null;
        if (ref != null) {
            channelTypeRegistry = (ChannelTypeRegistry) bundleContext.getService(ref);
        }
        return consumer.apply(channelTypeRegistry);
    } finally {
        if (ref != null) {
            bundleContext.ungetService(ref);
        }
    }
}
Also used : ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ChannelTypeRegistry

use of org.openhab.core.thing.type.ChannelTypeRegistry in project openhab-core by openhab.

the class SystemWideChannelTypesTest method setUp.

@BeforeEach
public void setUp() {
    thingTypeProvider = getService(ThingTypeProvider.class);
    assertThat(thingTypeProvider, is(notNullValue()));
    channelTypeRegistry = getService(ChannelTypeRegistry.class);
    assertThat(channelTypeRegistry, is(notNullValue()));
    ChannelTypeProvider provider = getService(ChannelTypeProvider.class, DefaultSystemChannelTypeProvider.class);
    assertTrue(provider instanceof DefaultSystemChannelTypeProvider);
    systemChannelTypeProvider = provider;
}
Also used : DefaultSystemChannelTypeProvider(org.openhab.core.thing.DefaultSystemChannelTypeProvider) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) DefaultSystemChannelTypeProvider(org.openhab.core.thing.DefaultSystemChannelTypeProvider) ChannelTypeProvider(org.openhab.core.thing.type.ChannelTypeProvider) ThingTypeProvider(org.openhab.core.thing.binding.ThingTypeProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ChannelTypeRegistry

use of org.openhab.core.thing.type.ChannelTypeRegistry in project openhab-addons by openhab.

the class AbstractMieleThingHandlerTest method createChannelsForThingHandler.

private List<Channel> createChannelsForThingHandler(ThingTypeUID thingTypeUid, ThingUID thingUid) {
    ChannelTypeRegistry channelTypeRegistry = getService(ChannelTypeRegistry.class, ChannelTypeRegistry.class);
    assertNotNull(channelTypeRegistry);
    ThingTypeRegistry thingTypeRegistry = getService(ThingTypeRegistry.class, ThingTypeRegistry.class);
    assertNotNull(thingTypeRegistry);
    ThingType thingType = thingTypeRegistry.getThingType(thingTypeUid);
    assertNotNull(thingType);
    List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
    assertNotNull(channelDefinitions);
    List<Channel> channels = new ArrayList<Channel>();
    for (ChannelDefinition channelDefinition : channelDefinitions) {
        ChannelTypeUID channelTypeUid = channelDefinition.getChannelTypeUID();
        assertNotNull(channelTypeUid);
        ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUid);
        assertNotNull(channelType);
        String acceptedItemType = channelType.getItemType();
        assertNotNull(acceptedItemType);
        String channelId = channelDefinition.getId();
        assertNotNull(channelId);
        ChannelUID channelUid = new ChannelUID(thingUid, channelId);
        assertNotNull(channelUid);
        Channel channel = ChannelBuilder.create(channelUid, acceptedItemType).build();
        assertNotNull(channel);
        channels.add(channel);
    }
    return channels;
}
Also used : ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ThingType(org.openhab.core.thing.type.ThingType) ChannelType(org.openhab.core.thing.type.ChannelType)

Example 4 with ChannelTypeRegistry

use of org.openhab.core.thing.type.ChannelTypeRegistry in project openhab-addons by openhab.

the class WWNThingHandlerOSGiTest method setUp.

@BeforeEach
public void setUp() throws ItemNotFoundException {
    registerService(volatileStorageService);
    managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class);
    assertThat("Could not get ManagedThingProvider", managedThingProvider, is(notNullValue()));
    thingTypeRegistry = getService(ThingTypeRegistry.class);
    assertThat("Could not get ThingTypeRegistry", thingTypeRegistry, is(notNullValue()));
    channelTypeRegistry = getService(ChannelTypeRegistry.class);
    assertThat("Could not get ChannelTypeRegistry", channelTypeRegistry, is(notNullValue()));
    channelGroupTypeRegistry = getService(ChannelGroupTypeRegistry.class);
    assertThat("Could not get ChannelGroupTypeRegistry", channelGroupTypeRegistry, is(notNullValue()));
    eventPublisher = getService(EventPublisher.class);
    assertThat("Could not get EventPublisher", eventPublisher, is(notNullValue()));
    itemFactory = getService(ItemFactory.class);
    assertThat("Could not get ItemFactory", itemFactory, is(notNullValue()));
    itemRegistry = getService(ItemRegistry.class);
    assertThat("Could not get ItemRegistry", itemRegistry, is(notNullValue()));
    managedItemChannelLinkProvider = getService(ManagedItemChannelLinkProvider.class);
    assertThat("Could not get ManagedItemChannelLinkProvider", managedItemChannelLinkProvider, is(notNullValue()));
    clientBuilder = getService(ClientBuilder.class);
    assertThat("Could not get ClientBuilder", clientBuilder, is(notNullValue()));
    eventSourceFactory = getService(SseEventSourceFactory.class);
    assertThat("Could not get SseEventSourceFactory", eventSourceFactory, is(notNullValue()));
    ComponentContext componentContext = mock(ComponentContext.class);
    when(componentContext.getBundleContext()).thenReturn(bundleContext);
    nestTestHandlerFactory = new WWNTestHandlerFactory(clientBuilder, eventSourceFactory);
    nestTestHandlerFactory.activate(componentContext, Map.of(WWNTestHandlerFactory.REDIRECT_URL_CONFIG_PROPERTY, REDIRECT_URL));
    registerService(nestTestHandlerFactory);
    nestTestHandlerFactory = getService(ThingHandlerFactory.class, WWNTestHandlerFactory.class);
    assertThat("Could not get NestTestHandlerFactory", nestTestHandlerFactory, is(notNullValue()));
    bridge = buildBridge();
    thing = buildThing(bridge);
    bridgeHandler = addThing(bridge, WWNTestAccountHandler.class);
    thingHandler = addThing(thing, thingClass);
    createAndLinkItems();
    assertThatAllItemStatesAreNull();
}
Also used : ManagedItemChannelLinkProvider(org.openhab.core.thing.link.ManagedItemChannelLinkProvider) EventPublisher(org.openhab.core.events.EventPublisher) ComponentContext(org.osgi.service.component.ComponentContext) WWNTestAccountHandler(org.openhab.binding.nest.internal.wwn.test.WWNTestAccountHandler) ItemRegistry(org.openhab.core.items.ItemRegistry) ThingHandlerFactory(org.openhab.core.thing.binding.ThingHandlerFactory) WWNTestHandlerFactory(org.openhab.binding.nest.internal.wwn.test.WWNTestHandlerFactory) ThingProvider(org.openhab.core.thing.ThingProvider) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ChannelGroupTypeRegistry(org.openhab.core.thing.type.ChannelGroupTypeRegistry) ChannelTypeRegistry(org.openhab.core.thing.type.ChannelTypeRegistry) ItemFactory(org.openhab.core.items.ItemFactory) SseEventSourceFactory(org.osgi.service.jaxrs.client.SseEventSourceFactory) ManagedThingProvider(org.openhab.core.thing.ManagedThingProvider) ThingTypeRegistry(org.openhab.core.thing.type.ThingTypeRegistry) ClientBuilder(javax.ws.rs.client.ClientBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ChannelTypeRegistry (org.openhab.core.thing.type.ChannelTypeRegistry)4 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ThingTypeRegistry (org.openhab.core.thing.type.ThingTypeRegistry)2 ArrayList (java.util.ArrayList)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 WWNTestAccountHandler (org.openhab.binding.nest.internal.wwn.test.WWNTestAccountHandler)1 WWNTestHandlerFactory (org.openhab.binding.nest.internal.wwn.test.WWNTestHandlerFactory)1 EventPublisher (org.openhab.core.events.EventPublisher)1 ItemFactory (org.openhab.core.items.ItemFactory)1 ItemRegistry (org.openhab.core.items.ItemRegistry)1 Channel (org.openhab.core.thing.Channel)1 ChannelUID (org.openhab.core.thing.ChannelUID)1 DefaultSystemChannelTypeProvider (org.openhab.core.thing.DefaultSystemChannelTypeProvider)1 ManagedThingProvider (org.openhab.core.thing.ManagedThingProvider)1 ThingProvider (org.openhab.core.thing.ThingProvider)1 ThingHandlerFactory (org.openhab.core.thing.binding.ThingHandlerFactory)1 ThingTypeProvider (org.openhab.core.thing.binding.ThingTypeProvider)1 ManagedItemChannelLinkProvider (org.openhab.core.thing.link.ManagedItemChannelLinkProvider)1 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)1 ChannelGroupTypeRegistry (org.openhab.core.thing.type.ChannelGroupTypeRegistry)1