Search in sources :

Example 26 with Channel

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

the class ChannelStateDescriptionProvider method getStateDescription.

@Override
public StateDescription getStateDescription(String itemName, Locale locale) {
    Set<ChannelUID> boundChannels = itemChannelLinkRegistry.getBoundChannels(itemName);
    if (!boundChannels.isEmpty()) {
        ChannelUID channelUID = boundChannels.iterator().next();
        Channel channel = thingRegistry.getChannel(channelUID);
        if (channel != null) {
            StateDescription stateDescription = null;
            ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale);
            if (channelType != null) {
                stateDescription = channelType.getState();
                if ((channelType.getItemType() != null) && ((stateDescription == null) || (stateDescription.getPattern() == null))) {
                    String pattern = null;
                    if (channelType.getItemType().equalsIgnoreCase(CoreItemFactory.STRING)) {
                        pattern = "%s";
                    } else if (channelType.getItemType().startsWith(CoreItemFactory.NUMBER)) {
                        pattern = "%.0f";
                    }
                    if (pattern != null) {
                        logger.trace("Provide a default pattern {} for item {}", pattern, itemName);
                        if (stateDescription == null) {
                            stateDescription = new StateDescription(null, null, null, pattern, false, null);
                        } else {
                            stateDescription = new StateDescription(stateDescription.getMinimum(), stateDescription.getMaximum(), stateDescription.getStep(), pattern, stateDescription.isReadOnly(), stateDescription.getOptions());
                        }
                    }
                }
            }
            StateDescription dynamicStateDescription = getDynamicStateDescription(channel, stateDescription, locale);
            if (dynamicStateDescription != null) {
                return dynamicStateDescription;
            }
            return stateDescription;
        }
    }
    return null;
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 27 with Channel

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

the class CommunicationManager method determineProfileTypeUID.

@Nullable
private ProfileTypeUID determineProfileTypeUID(ItemChannelLink link, Item item, @Nullable Thing thing) {
    ProfileTypeUID profileTypeUID = getConfiguredProfileTypeUID(link);
    Channel channel = null;
    if (profileTypeUID == null) {
        if (thing == null) {
            return null;
        }
        channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }
        // ask advisors
        profileTypeUID = getAdvice(link, item, channel);
        if (profileTypeUID == null) {
            // ask default advisor
            logger.trace("No profile advisor found for link {}, falling back to the defaults", link);
            profileTypeUID = defaultProfileFactory.getSuggestedProfileTypeUID(channel, item.getType());
        }
    }
    return profileTypeUID;
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 28 with Channel

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

the class CommunicationManager method handleCallFromHandler.

void handleCallFromHandler(ChannelUID channelUID, @Nullable Thing thing, Consumer<Profile> action) {
    itemChannelLinkRegistry.stream().filter(link -> {
        // all links for the channel
        return link.getLinkedUID().equals(channelUID);
    }).forEach(link -> {
        Item item = getItem(link.getItemName());
        if (item != null) {
            Profile profile = getProfile(link, item, thing);
            action.accept(profile);
        }
    });
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) Arrays(java.util.Arrays) ItemFactory(org.eclipse.smarthome.core.items.ItemFactory) ProfileFactory(org.eclipse.smarthome.core.thing.profiles.ProfileFactory) LoggerFactory(org.slf4j.LoggerFactory) Command(org.eclipse.smarthome.core.types.Command) ItemChannelLinkConfigDescriptionProvider(org.eclipse.smarthome.core.thing.internal.link.ItemChannelLinkConfigDescriptionProvider) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) UID(org.eclipse.smarthome.core.thing.UID) State(org.eclipse.smarthome.core.types.State) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) ItemStateConverter(org.eclipse.smarthome.core.items.ItemStateConverter) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ThingEventFactory(org.eclipse.smarthome.core.thing.events.ThingEventFactory) List(java.util.List) StateProfile(org.eclipse.smarthome.core.thing.profiles.StateProfile) Entry(java.util.Map.Entry) NonNull(org.eclipse.jdt.annotation.NonNull) SystemProfileFactory(org.eclipse.smarthome.core.thing.internal.profiles.SystemProfileFactory) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ItemCommandEvent(org.eclipse.smarthome.core.items.events.ItemCommandEvent) EventFilter(org.eclipse.smarthome.core.events.EventFilter) EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) Function(java.util.function.Function) RegistryChangeListener(org.eclipse.smarthome.core.common.registry.RegistryChangeListener) HashSet(java.util.HashSet) ProfileCallbackImpl(org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl) Component(org.osgi.service.component.annotations.Component) SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) Type(org.eclipse.smarthome.core.types.Type) ProfileCallback(org.eclipse.smarthome.core.thing.profiles.ProfileCallback) TriggerProfile(org.eclipse.smarthome.core.thing.profiles.TriggerProfile) Logger(org.slf4j.Logger) Profile(org.eclipse.smarthome.core.thing.profiles.Profile) Item(org.eclipse.smarthome.core.items.Item) ItemStateEvent(org.eclipse.smarthome.core.items.events.ItemStateEvent) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ProfileAdvisor(org.eclipse.smarthome.core.thing.profiles.ProfileAdvisor) ChannelTriggeredEvent(org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) Event(org.eclipse.smarthome.core.events.Event) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Item(org.eclipse.smarthome.core.items.Item) StateProfile(org.eclipse.smarthome.core.thing.profiles.StateProfile) TriggerProfile(org.eclipse.smarthome.core.thing.profiles.TriggerProfile) Profile(org.eclipse.smarthome.core.thing.profiles.Profile)

Example 29 with Channel

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

the class ThingConfigDescriptionAliasProvider method getChannelConfigDescriptionURI.

@Nullable
private URI getChannelConfigDescriptionURI(URI uri) {
    String stringUID = uri.getSchemeSpecificPart();
    if (uri.getFragment() != null) {
        stringUID = stringUID + "#" + uri.getFragment();
    }
    ChannelUID channelUID = new ChannelUID(stringUID);
    ThingUID thingUID = channelUID.getThingUID();
    // First, get the thing so we get access to the channel type via the channel
    Thing thing = thingRegistry.get(thingUID);
    if (thing == null) {
        return null;
    }
    Channel channel = thing.getChannel(channelUID.getId());
    if (channel == null) {
        return null;
    }
    ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
    if (channelType == null) {
        return null;
    }
    // Get the config description URI for this channel type
    URI configURI = channelType.getConfigDescriptionURI();
    return configURI;
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Channel(org.eclipse.smarthome.core.thing.Channel) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) URI(java.net.URI) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 30 with Channel

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

the class ThingFactoryHelper method createChannels.

/**
 * Create {@link Channel} instances for the given Thing.
 *
 * @param thingType the type of the Thing (must not be null)
 * @param thingUID the Thing's UID (must not be null)
 * @param configDescriptionRegistry {@link ConfigDescriptionRegistry} that will be used to initialize the
 *            {@link Channel}s with their corresponding default values, if given.
 * @return a list of {@link Channel}s
 */
public static List<Channel> createChannels(ThingType thingType, ThingUID thingUID, ConfigDescriptionRegistry configDescriptionRegistry) {
    List<Channel> channels = new ArrayList<>();
    List<ChannelDefinition> channelDefinitions = thingType.getChannelDefinitions();
    for (ChannelDefinition channelDefinition : channelDefinitions) {
        Channel channel = createChannel(channelDefinition, thingUID, null, configDescriptionRegistry);
        if (channel != null) {
            channels.add(channel);
        }
    }
    List<ChannelGroupDefinition> channelGroupDefinitions = thingType.getChannelGroupDefinitions();
    withChannelTypeRegistry(channelTypeRegistry -> {
        for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
            ChannelGroupType channelGroupType = null;
            if (channelTypeRegistry != null) {
                channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID());
            }
            if (channelGroupType != null) {
                List<ChannelDefinition> channelGroupChannelDefinitions = channelGroupType.getChannelDefinitions();
                for (ChannelDefinition channelDefinition : channelGroupChannelDefinitions) {
                    Channel channel = createChannel(channelDefinition, thingUID, channelGroupDefinition.getId(), configDescriptionRegistry);
                    if (channel != null) {
                        channels.add(channel);
                    }
                }
            } else {
                logger.warn("Could not create channels for channel group '{}' for thing type '{}', because channel group type '{}' could not be found.", channelGroupDefinition.getId(), thingUID, channelGroupDefinition.getTypeUID());
            }
        }
        return null;
    });
    return channels;
}
Also used : ChannelDefinition(org.eclipse.smarthome.core.thing.type.ChannelDefinition) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList) ChannelGroupType(org.eclipse.smarthome.core.thing.type.ChannelGroupType) ChannelGroupDefinition(org.eclipse.smarthome.core.thing.type.ChannelGroupDefinition)

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