use of org.eclipse.smarthome.core.thing.ChannelUID 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;
}
use of org.eclipse.smarthome.core.thing.ChannelUID 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);
}
});
}
use of org.eclipse.smarthome.core.thing.ChannelUID 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;
}
use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class LinkConsoleCommandExtension method execute.
@Override
public void execute(String[] args, Console console) {
if (args.length > 0) {
String subCommand = args[0];
switch(subCommand) {
case SUBCMD_LIST:
list(console, itemChannelLinkRegistry.getAll());
return;
case SUBCMD_CL_ADD:
if (args.length > 2) {
String itemName = args[1];
ChannelUID channelUID = new ChannelUID(args[2]);
addChannelLink(console, itemName, channelUID);
} else {
console.println("Specify item name and channel UID to link: link <itemName> <channelUID>");
}
return;
case SUBCMD_CL_REMOVE:
if (args.length > 2) {
String itemName = args[1];
ChannelUID channelUID = new ChannelUID(args[2]);
removeChannelLink(console, itemName, channelUID);
} else {
console.println("Specify item name and channel UID to unlink: link <itemName> <channelUID>");
}
return;
case SUBCMD_CLEAR:
clear(console);
return;
default:
console.println("Unknown command '" + subCommand + "'");
printUsage(console);
break;
}
} else {
printUsage(console);
}
}
use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.
the class ItemChannelLinkRegistry method getBoundThings.
/**
* Returns a set of bound things for the given item name.
*
* @param itemName item name
* @return set of bound things for the given item name
*/
public Set<Thing> getBoundThings(String itemName) {
Set<Thing> things = new HashSet<>();
Collection<ChannelUID> boundChannels = getBoundChannels(itemName);
for (ChannelUID channelUID : boundChannels) {
Thing thing = thingRegistry.get(channelUID.getThingUID());
if (thing != null) {
things.add(thing);
}
}
return things;
}
Aggregations