use of org.openhab.core.items.ItemFactory in project openhab-core by openhab.
the class ItemBuilderImpl method build.
@Override
public Item build() {
Item item = null;
if (GroupItem.TYPE.equals(itemType)) {
item = new GroupItem(name, baseItem, groupFunction);
} else {
for (ItemFactory itemFactory : itemFactories) {
item = itemFactory.createItem(itemType, name);
if (item != null) {
break;
}
}
}
if (item == null) {
throw new IllegalStateException("No item factory could handle type " + itemType);
}
if (item instanceof ActiveItem) {
ActiveItem activeItem = (ActiveItem) item;
activeItem.setLabel(label);
activeItem.setCategory(category);
activeItem.addGroupNames(groups);
activeItem.addTags(tags);
}
return item;
}
use of org.openhab.core.items.ItemFactory 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();
}
use of org.openhab.core.items.ItemFactory in project openhab-core by openhab.
the class CommunicationManager method calculateAcceptedTypes.
private synchronized void calculateAcceptedTypes() {
acceptedCommandTypeMap.clear();
acceptedStateTypeMap.clear();
for (ItemFactory itemFactory : itemFactories) {
for (String itemTypeName : itemFactory.getSupportedItemTypes()) {
Item item = itemFactory.createItem(itemTypeName, "tmp");
if (item != null) {
acceptedCommandTypeMap.put(itemTypeName, item.getAcceptedCommandTypes());
acceptedStateTypeMap.put(itemTypeName, item.getAcceptedDataTypes());
} else {
logger.error("Item factory {} suggested it can create items of type {} but returned null", itemFactory, itemTypeName);
}
}
}
}
Aggregations