use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ThingRegistryImpl method createThingOfType.
@Override
public Thing createThingOfType(ThingTypeUID thingTypeUID, ThingUID thingUID, ThingUID bridgeUID, String label, Configuration configuration) {
logger.debug("Creating thing for type '{}'.", thingTypeUID);
for (ThingHandlerFactory thingHandlerFactory : thingHandlerFactories) {
if (thingHandlerFactory.supportsThingType(thingTypeUID)) {
Thing thing = thingHandlerFactory.createThing(thingTypeUID, configuration, thingUID, bridgeUID);
thing.setLabel(label);
return thing;
}
}
logger.warn("Cannot create thing. No binding found that supports creating a thing of type '{}'.", thingTypeUID);
return null;
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ThingConsoleCommandExtension method execute.
@Override
public void execute(String[] args, Console console) {
Collection<Thing> things = thingRegistry.getAll();
if (args.length > 0) {
String subCommand = args[0];
switch(subCommand) {
case SUBCMD_LIST:
printThings(console, things);
return;
case SUBCMD_CLEAR:
removeAllThings(console, things);
return;
case SUBCMD_REMOVE:
if (args.length > 1) {
ThingUID thingUID = new ThingUID(args[1]);
removeThing(console, things, thingUID);
} else {
console.println("Specify thing id to remove: things remove <thingUID> (e.g. \"hue:light:1\")");
}
return;
case SUBCMD_TRIGGER:
if (args.length == 3) {
triggerChannel(console, args[1], args[2]);
} else if (args.length == 2) {
triggerChannel(console, args[1], null);
} else {
console.println("Command '" + subCommand + "' needs arguments <channelUID> [<event>]");
}
break;
default:
break;
}
} else {
printUsage(console);
}
}
use of org.eclipse.smarthome.core.thing.Thing 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;
}
use of org.eclipse.smarthome.core.thing.Thing in project smarthome by eclipse.
the class ProfileCallbackImpl method handleCommand.
@Override
public void handleCommand(Command command) {
Thing thing = thingProvider.apply(link.getLinkedUID().getThingUID());
if (thing != null) {
final ThingHandler handler = thing.getHandler();
if (handler != null) {
if (ThingHandlerHelper.isHandlerInitialized(thing)) {
logger.debug("Delegating command '{}' for item '{}' to handler for channel '{}'", command, link.getItemName(), link.getLinkedUID());
safeCaller.create(handler, ThingHandler.class).withTimeout(CommunicationManager.THINGHANDLER_EVENT_TIMEOUT).onTimeout(() -> {
logger.warn("Handler for thing '{}' takes more than {}ms for handling a command", handler.getThing().getUID(), CommunicationManager.THINGHANDLER_EVENT_TIMEOUT);
}).build().handleCommand(link.getLinkedUID(), command);
} else {
logger.debug("Not delegating command '{}' for item '{}' to handler for channel '{}', " + "because handler is not initialized (thing must be in status UNKNOWN, ONLINE or OFFLINE but was {}).", command, link.getItemName(), link.getLinkedUID(), thing.getStatus());
}
} else {
logger.warn("Cannot delegate command '{}' for item '{}' to handler for channel '{}', " + "because no handler is assigned. Maybe the binding is not installed or not " + "propertly initialized.", command, link.getItemName(), link.getLinkedUID());
}
} else {
logger.warn("Cannot delegate command '{}' for item '{}' to handler for channel '{}', " + "because no thing with the UID '{}' could be found.", command, link.getItemName(), link.getLinkedUID(), link.getLinkedUID().getThingUID());
}
}
use of org.eclipse.smarthome.core.thing.Thing 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