Search in sources :

Example 1 with CommandDescription

use of org.eclipse.smarthome.core.types.CommandDescription 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 CommandDescription

use of org.eclipse.smarthome.core.types.CommandDescription 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 CommandDescription

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

the class ChannelCommandDescriptionProvider method getCommandDescription.

@Override
@Nullable
public CommandDescription getCommandDescription(String itemName, @Nullable Locale locale) {
    Set<ChannelUID> boundChannels = itemChannelLinkRegistry.getBoundChannels(itemName);
    if (!boundChannels.isEmpty()) {
        ChannelUID channelUID = boundChannels.iterator().next();
        Channel channel = thingRegistry.getChannel(channelUID);
        if (channel != null) {
            CommandDescription commandDescription = null;
            ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale);
            if (channelType != null) {
                commandDescription = channelType.getCommandDescription();
            }
            CommandDescription dynamicCommandDescription = getDynamicCommandDescription(channel, commandDescription, locale);
            if (dynamicCommandDescription != null) {
                return dynamicCommandDescription;
            }
            return commandDescription;
        }
    }
    return null;
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) Channel(org.eclipse.smarthome.core.thing.Channel) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with CommandDescription

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

the class ChannelTypeConverter method unmarshalType.

@Override
protected ChannelTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    boolean advanced = readBoolean(attributes, "advanced", false);
    boolean system = readBoolean(attributes, "system", false);
    String uid = system ? XmlHelper.getSystemUID(super.getID(attributes)) : super.getUID(attributes, context);
    ChannelTypeUID channelTypeUID = new ChannelTypeUID(uid);
    String itemType = readItemType(nodeIterator);
    String kind = readKind(nodeIterator);
    String label = super.readLabel(nodeIterator);
    String description = super.readDescription(nodeIterator);
    String category = readCategory(nodeIterator);
    Set<String> tags = readTags(nodeIterator);
    StateDescription stateDescription = readStateDescription(nodeIterator);
    CommandDescription commandDescription = readCommandDescription(nodeIterator);
    EventDescription eventDescription = readEventDescription(nodeIterator);
    AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator);
    Object[] configDescriptionObjects = super.getConfigDescriptionObjects(nodeIterator);
    if (kind == null) {
        // Default for kind is 'state'
        kind = "state";
    }
    ChannelKind cKind = ChannelKind.parse(kind);
    URI configDescriptionURI = (URI) configDescriptionObjects[0];
    ChannelType channelType = null;
    if (cKind == ChannelKind.STATE) {
        StateChannelTypeBuilder builder = ChannelTypeBuilder.state(channelTypeUID, label, itemType).isAdvanced(advanced).withDescription(description).withCategory(category).withTags(tags).withConfigDescriptionURI(configDescriptionURI).withStateDescription(stateDescription).withAutoUpdatePolicy(autoUpdatePolicy).withCommandDescription(commandDescription);
        channelType = builder.build();
    } else if (cKind == ChannelKind.TRIGGER) {
        channelType = ChannelTypeBuilder.trigger(channelTypeUID, label).isAdvanced(advanced).withDescription(description).withCategory(category).withTags(tags).withConfigDescriptionURI(configDescriptionURI).withEventDescription(eventDescription).build();
    }
    ChannelTypeXmlResult channelTypeXmlResult = new ChannelTypeXmlResult(channelType, (ConfigDescription) configDescriptionObjects[1], system);
    return channelTypeXmlResult;
}
Also used : CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) ChannelKind(org.eclipse.smarthome.core.thing.type.ChannelKind) URI(java.net.URI) StateChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder) AutoUpdatePolicy(org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) EventDescription(org.eclipse.smarthome.core.types.EventDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 5 with CommandDescription

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

the class ChannelTypeI18nLocalizationService method createLocalizedChannelType.

public ChannelType createLocalizedChannelType(Bundle bundle, ChannelType channelType, @Nullable Locale locale) {
    ChannelTypeUID channelTypeUID = channelType.getUID();
    String defaultLabel = channelType.getLabel();
    String label = thingTypeI18nUtil.getChannelLabel(bundle, channelTypeUID, defaultLabel, locale);
    String description = thingTypeI18nUtil.getChannelDescription(bundle, channelTypeUID, channelType.getDescription(), locale);
    switch(channelType.getKind()) {
        case STATE:
            StateDescription state = createLocalizedStateDescription(bundle, channelType.getState(), channelTypeUID, locale);
            CommandDescription command = createLocalizedCommandDescription(bundle, channelType.getCommandDescription(), channelTypeUID, locale);
            StateChannelTypeBuilder stateBuilder = ChannelTypeBuilder.state(channelTypeUID, label == null ? defaultLabel : label, channelType.getItemType()).isAdvanced(channelType.isAdvanced()).withCategory(channelType.getCategory()).withConfigDescriptionURI(channelType.getConfigDescriptionURI()).withTags(channelType.getTags()).withStateDescription(state).withAutoUpdatePolicy(channelType.getAutoUpdatePolicy()).withCommandDescription(command);
            if (description != null) {
                stateBuilder.withDescription(description);
            }
            return stateBuilder.build();
        case TRIGGER:
            TriggerChannelTypeBuilder triggerBuilder = ChannelTypeBuilder.trigger(channelTypeUID, label == null ? defaultLabel : label).isAdvanced(channelType.isAdvanced()).withCategory(channelType.getCategory()).withConfigDescriptionURI(channelType.getConfigDescriptionURI()).withTags(channelType.getTags()).withEventDescription(channelType.getEvent());
            if (description != null) {
                triggerBuilder.withDescription(description);
            }
            return triggerBuilder.build();
        default:
            return new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), channelType.getKind(), label == null ? defaultLabel : label, description, channelType.getCategory(), channelType.getTags(), channelType.getState(), channelType.getEvent(), channelType.getConfigDescriptionURI(), channelType.getAutoUpdatePolicy());
    }
}
Also used : TriggerChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.TriggerChannelTypeBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Aggregations

CommandDescription (org.eclipse.smarthome.core.types.CommandDescription)5 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)3 List (java.util.List)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 CommandDescriptionService (org.eclipse.smarthome.core.service.CommandDescriptionService)2 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)2 StateChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder)2 CommandOption (org.eclipse.smarthome.core.types.CommandOption)2 StateDescription (org.eclipse.smarthome.core.types.StateDescription)2 Test (org.junit.Test)2 URI (java.net.URI)1 Locale (java.util.Locale)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Channel (org.eclipse.smarthome.core.thing.Channel)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1 AutoUpdatePolicy (org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy)1 ChannelKind (org.eclipse.smarthome.core.thing.type.ChannelKind)1 TriggerChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.TriggerChannelTypeBuilder)1 EventDescription (org.eclipse.smarthome.core.types.EventDescription)1