Search in sources :

Example 1 with ItemFactory

use of org.eclipse.smarthome.core.items.ItemFactory in project smarthome by eclipse.

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);
            }
        }
    }
}
Also used : Item(org.eclipse.smarthome.core.items.Item) ItemFactory(org.eclipse.smarthome.core.items.ItemFactory)

Example 2 with ItemFactory

use of org.eclipse.smarthome.core.items.ItemFactory in project smarthome by eclipse.

the class ChannelItemProvider method createItemForLink.

private void createItemForLink(ItemChannelLink link) {
    if (!enabled) {
        return;
    }
    if (itemRegistry.get(link.getItemName()) != null) {
        // there is already an item, we do not need to create one
        return;
    }
    Channel channel = thingRegistry.getChannel(link.getLinkedUID());
    if (channel != null) {
        Item item = null;
        // Only create an item for state channels
        if (channel.getKind() == ChannelKind.STATE) {
            for (ItemFactory itemFactory : itemFactories) {
                item = itemFactory.createItem(channel.getAcceptedItemType(), link.getItemName());
                if (item != null) {
                    break;
                }
            }
        }
        if (item instanceof GenericItem) {
            GenericItem gItem = (GenericItem) item;
            gItem.setLabel(getLabel(channel));
            gItem.setCategory(getCategory(channel));
            gItem.addTags(channel.getDefaultTags());
        }
        if (item != null) {
            items.put(item.getName(), item);
            for (ProviderChangeListener<Item> listener : listeners) {
                listener.added(this, item);
            }
        }
    }
}
Also used : GenericItem(org.eclipse.smarthome.core.items.GenericItem) Item(org.eclipse.smarthome.core.items.Item) GenericItem(org.eclipse.smarthome.core.items.GenericItem) ItemFactory(org.eclipse.smarthome.core.items.ItemFactory) Channel(org.eclipse.smarthome.core.thing.Channel)

Aggregations

Item (org.eclipse.smarthome.core.items.Item)2 ItemFactory (org.eclipse.smarthome.core.items.ItemFactory)2 GenericItem (org.eclipse.smarthome.core.items.GenericItem)1 Channel (org.eclipse.smarthome.core.thing.Channel)1