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;
}
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();
}
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();
}
Aggregations