Search in sources :

Example 31 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class ItemChannelLinkConfigDescriptionProvider method getConfigDescription.

@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
    if (SCHEME.equals(uri.getScheme())) {
        ItemChannelLink link = itemChannelLinkRegistry.get(uri.getSchemeSpecificPart());
        if (link == null) {
            return null;
        }
        Item item = itemRegistry.get(link.getItemName());
        if (item == null) {
            return null;
        }
        Thing thing = thingRegistry.get(link.getLinkedUID().getThingUID());
        if (thing == null) {
            return null;
        }
        Channel channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }
        ConfigDescriptionParameter paramProfile = ConfigDescriptionParameterBuilder.create(PARAM_PROFILE, Type.TEXT).withLabel("Profile").withDescription("the profile to use").withRequired(false).withLimitToOptions(true).withOptions(getOptions(link, item, channel, locale)).build();
        return new ConfigDescription(uri, Collections.singletonList(paramProfile));
    }
    return null;
}
Also used : Item(org.eclipse.smarthome.core.items.Item) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 32 with Channel

use of org.eclipse.smarthome.core.thing.Channel 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)

Example 33 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class BridgeBuilder method create.

public static BridgeBuilder create(ThingTypeUID thingTypeUID, String bridgeId) {
    BridgeImpl bridge = new BridgeImpl(thingTypeUID, bridgeId);
    bridge.setChannels(new ArrayList<Channel>());
    return new BridgeBuilder(bridge);
}
Also used : BridgeImpl(org.eclipse.smarthome.core.thing.internal.BridgeImpl) Channel(org.eclipse.smarthome.core.thing.Channel)

Example 34 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class EnrichedThingDTOMapperTest method mockChannels.

private List<Channel> mockChannels() {
    List<Channel> channels = new ArrayList<>();
    channels.add(ChannelBuilder.create(new ChannelUID(THING_TYPE_UID + ":" + UID + ":1"), ITEM_TYPE).build());
    channels.add(ChannelBuilder.create(new ChannelUID(THING_TYPE_UID + ":" + UID + ":2"), ITEM_TYPE).build());
    return channels;
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList)

Example 35 with Channel

use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.

the class LifxLightHandler method addRemoveZoneChannels.

private void addRemoveZoneChannels(int zones) {
    List<Channel> newChannels = new ArrayList<>();
    // retain non-zone channels
    for (Channel channel : getThing().getChannels()) {
        String channelId = channel.getUID().getId();
        if (!channelId.startsWith(CHANNEL_COLOR_ZONE) && !channelId.startsWith(CHANNEL_TEMPERATURE_ZONE)) {
            newChannels.add(channel);
        }
    }
    // add zone channels
    for (int i = 0; i < zones; i++) {
        newChannels.add(channelFactory.createColorZoneChannel(getThing().getUID(), i));
        newChannels.add(channelFactory.createTemperatureZoneChannel(getThing().getUID(), i));
    }
    updateThing(editThing().withChannels(newChannels).build());
    Map<String, String> properties = editProperties();
    properties.put(LifxBindingConstants.PROPERTY_ZONES, Integer.toString(zones));
    updateProperties(properties);
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList)

Aggregations

Channel (org.eclipse.smarthome.core.thing.Channel)36 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)16 ArrayList (java.util.ArrayList)8 Thing (org.eclipse.smarthome.core.thing.Thing)7 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)6 Nullable (org.eclipse.jdt.annotation.Nullable)5 Configuration (org.eclipse.smarthome.config.core.Configuration)5 Item (org.eclipse.smarthome.core.items.Item)4 ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)4 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)4 List (java.util.List)3 Locale (java.util.Locale)3 NonNull (org.eclipse.jdt.annotation.NonNull)3 AstroChannelConfig (org.eclipse.smarthome.binding.astro.internal.config.AstroChannelConfig)3 ItemChannelLinkRegistry (org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry)3 ProfileTypeUID (org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID)3 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Calendar (java.util.Calendar)2