Search in sources :

Example 1 with CommandDescriptionBuilder

use of org.eclipse.smarthome.core.types.CommandDescriptionBuilder in project smarthome by eclipse.

the class CommandDescriptionConverter method unmarshal.

@Override
public final CommandDescription unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class);
    NodeIterator nodeIterator = new NodeIterator(nodes.getList());
    NodeList commandOptionsNode = (NodeList) nodeIterator.next();
    if (commandOptionsNode != null) {
        if ("options".equals(commandOptionsNode.getNodeName())) {
            CommandDescriptionBuilder commandDescriptionBuilder = CommandDescriptionBuilder.create();
            for (Object coNodeObject : commandOptionsNode.getList()) {
                NodeValue optionsNode = (NodeValue) coNodeObject;
                if ("option".equals(optionsNode.getNodeName())) {
                    String name = (String) optionsNode.getValue();
                    String command = optionsNode.getAttributes().get("value");
                    if (name != null && command != null) {
                        commandDescriptionBuilder.withCommandOption(new CommandOption(command, name));
                    }
                } else {
                    throw new ConversionException("The 'options' node must only contain 'option' nodes!");
                }
            }
            nodeIterator.assertEndOfType();
            return commandDescriptionBuilder.build();
        }
    }
    nodeIterator.assertEndOfType();
    return null;
}
Also used : NodeIterator(org.eclipse.smarthome.config.xml.util.NodeIterator) ConversionException(com.thoughtworks.xstream.converters.ConversionException) NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue) CommandOption(org.eclipse.smarthome.core.types.CommandOption) NodeList(org.eclipse.smarthome.config.xml.util.NodeList) CommandDescriptionBuilder(org.eclipse.smarthome.core.types.CommandDescriptionBuilder)

Example 2 with CommandDescriptionBuilder

use of org.eclipse.smarthome.core.types.CommandDescriptionBuilder in project smarthome by eclipse.

the class ChannelTypeI18nLocalizationService method createLocalizedCommandDescription.

@Nullable
private CommandDescription createLocalizedCommandDescription(final Bundle bundle, @Nullable final CommandDescription command, final ChannelTypeUID channelTypeUID, @Nullable final Locale locale) {
    if (command == null) {
        return null;
    }
    CommandDescriptionBuilder commandDescriptionBuilder = CommandDescriptionBuilder.create();
    for (final CommandOption options : command.getCommandOptions()) {
        String optionLabel = thingTypeI18nUtil.getChannelCommandOption(bundle, channelTypeUID, options.getCommand(), options.getLabel(), locale);
        optionLabel = optionLabel == null ? "" : optionLabel;
        commandDescriptionBuilder.withCommandOption(new CommandOption(options.getCommand(), optionLabel));
    }
    return commandDescriptionBuilder.build();
}
Also used : CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescriptionBuilder(org.eclipse.smarthome.core.types.CommandDescriptionBuilder) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with CommandDescriptionBuilder

use of org.eclipse.smarthome.core.types.CommandDescriptionBuilder in project smarthome by eclipse.

the class GenericItem method stateOptions2CommandOptions.

@Nullable
private CommandDescription stateOptions2CommandOptions(StateDescription stateDescription) {
    CommandDescriptionBuilder builder = CommandDescriptionBuilder.create();
    stateDescription.getOptions().forEach(so -> builder.withCommandOption(new CommandOption(so.getValue(), so.getLabel())));
    return builder.build();
}
Also used : CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescriptionBuilder(org.eclipse.smarthome.core.types.CommandDescriptionBuilder) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

CommandDescriptionBuilder (org.eclipse.smarthome.core.types.CommandDescriptionBuilder)3 CommandOption (org.eclipse.smarthome.core.types.CommandOption)3 Nullable (org.eclipse.jdt.annotation.Nullable)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 NodeIterator (org.eclipse.smarthome.config.xml.util.NodeIterator)1 NodeList (org.eclipse.smarthome.config.xml.util.NodeList)1 NodeValue (org.eclipse.smarthome.config.xml.util.NodeValue)1