use of org.eclipse.smarthome.core.types.CommandOption in project smarthome by eclipse.
the class GenericItemTest method testCommandDescriptionWithLocale.
@Test
public void testCommandDescriptionWithLocale() {
TestItem item = new TestItem("test");
CommandDescriptionService commandDescriptionService = mock(CommandDescriptionService.class);
when(commandDescriptionService.getCommandDescription(eq("test"), any(Locale.class))).thenReturn(new CommandDescription() {
@Override
@NonNull
public List<@NonNull CommandOption> getCommandOptions() {
return Arrays.asList(new CommandOption("C1", "Command 1"), new CommandOption("C2", "Command 2"), new CommandOption("C3", "Command 3"));
}
});
item.setCommandDescriptionService(commandDescriptionService);
assertThat(item.getCommandDescription(Locale.getDefault()).getCommandOptions(), hasSize(3));
}
use of org.eclipse.smarthome.core.types.CommandOption in project smarthome by eclipse.
the class GenericItemTest method testCommandDescription.
@Test
public void testCommandDescription() {
TestItem item = new TestItem("test");
CommandDescriptionService commandDescriptionService = mock(CommandDescriptionService.class);
when(commandDescriptionService.getCommandDescription("test", null)).thenReturn(new CommandDescription() {
@Override
@NonNull
public List<@NonNull CommandOption> getCommandOptions() {
return Arrays.asList(new CommandOption("ALERT", "Alert"), new CommandOption("REBOOT", "Reboot"));
}
});
item.setCommandDescriptionService(commandDescriptionService);
assertThat(item.getCommandDescription().getCommandOptions(), hasSize(2));
}
use of org.eclipse.smarthome.core.types.CommandOption 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.CommandOption 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.CommandOption 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