Search in sources :

Example 76 with Thing

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;
}
Also used : ThingHandlerFactory(org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 77 with Thing

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);
    }
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 78 with Thing

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;
}
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 79 with Thing

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());
    }
}
Also used : ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 80 with Thing

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;
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Thing(org.eclipse.smarthome.core.thing.Thing) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Thing (org.eclipse.smarthome.core.thing.Thing)98 Test (org.junit.Test)43 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)28 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)24 Configuration (org.eclipse.smarthome.config.core.Configuration)19 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 JavaTest (org.eclipse.smarthome.test.java.JavaTest)18 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)13 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Item (org.eclipse.smarthome.core.items.Item)9 Path (javax.ws.rs.Path)8 Nullable (org.eclipse.jdt.annotation.Nullable)8 Locale (java.util.Locale)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Channel (org.eclipse.smarthome.core.thing.Channel)7 ThingHandlerCallback (org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback)7 Command (org.eclipse.smarthome.core.types.Command)7 List (java.util.List)6