Search in sources :

Example 1 with CommandOption

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));
}
Also used : Locale(java.util.Locale) CommandDescriptionService(org.eclipse.smarthome.core.service.CommandDescriptionService) CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) NonNull(org.eclipse.jdt.annotation.NonNull) List(java.util.List) Test(org.junit.Test)

Example 2 with CommandOption

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));
}
Also used : CommandDescriptionService(org.eclipse.smarthome.core.service.CommandDescriptionService) CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) NonNull(org.eclipse.jdt.annotation.NonNull) List(java.util.List) Test(org.junit.Test)

Example 3 with CommandOption

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;
}
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 4 with CommandOption

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();
}
Also used : CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescriptionBuilder(org.eclipse.smarthome.core.types.CommandDescriptionBuilder) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 5 with CommandOption

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();
}
Also used : CommandOption(org.eclipse.smarthome.core.types.CommandOption) CommandDescriptionBuilder(org.eclipse.smarthome.core.types.CommandDescriptionBuilder) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

CommandOption (org.eclipse.smarthome.core.types.CommandOption)5 CommandDescriptionBuilder (org.eclipse.smarthome.core.types.CommandDescriptionBuilder)3 List (java.util.List)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 CommandDescriptionService (org.eclipse.smarthome.core.service.CommandDescriptionService)2 CommandDescription (org.eclipse.smarthome.core.types.CommandDescription)2 Test (org.junit.Test)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 Locale (java.util.Locale)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