Search in sources :

Example 1 with ParameterOption

use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.

the class AudioManagerImpl method getParameterOptions.

@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
    if (uri.toString().equals(CONFIG_URI)) {
        if (CONFIG_DEFAULT_SOURCE.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (AudioSource source : audioSources.values()) {
                ParameterOption option = new ParameterOption(source.getId(), source.getLabel(locale));
                options.add(option);
            }
            return options;
        } else if (CONFIG_DEFAULT_SINK.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (AudioSink sink : audioSinks.values()) {
                ParameterOption option = new ParameterOption(sink.getId(), sink.getLabel(locale));
                options.add(option);
            }
            return options;
        }
    }
    return null;
}
Also used : AudioSource(org.eclipse.smarthome.core.audio.AudioSource) AudioSink(org.eclipse.smarthome.core.audio.AudioSink) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ParameterOption

use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.

the class ConfigDescriptionParameterConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    ConfigDescriptionParameter configDescriptionParam = null;
    // read attributes
    Map<String, String> attributes = this.attributeMapValidator.readValidatedAttributes(reader);
    String name = attributes.get("name");
    Type type = toType(attributes.get("type"));
    BigDecimal min = toNumber(attributes.get("min"));
    BigDecimal max = toNumber(attributes.get("max"));
    BigDecimal step = toNumber(attributes.get("step"));
    String patternString = attributes.get("pattern");
    Boolean required = toBoolean(attributes.get("required"));
    Boolean readOnly = falseIfNull(toBoolean(attributes.get("readOnly")));
    Boolean multiple = falseIfNull(toBoolean(attributes.get("multiple")));
    String groupName = attributes.get("groupName");
    String unit = attributes.get("unit");
    // read values
    ConverterValueMap valueMap = new ConverterValueMap(reader, context);
    String parameterContext = valueMap.getString("context");
    if (required == null) {
        // fallback to deprecated "required" element
        required = valueMap.getBoolean("required", false);
    }
    String defaultValue = valueMap.getString("default");
    String label = valueMap.getString("label");
    String description = valueMap.getString("description");
    Boolean advanced = valueMap.getBoolean("advanced", false);
    Boolean verify = valueMap.getBoolean("verify", false);
    Boolean limitToOptions = valueMap.getBoolean("limitToOptions", true);
    Integer multipleLimit = valueMap.getInteger("multipleLimit");
    String unitLabel = null;
    if (unit == null) {
        unitLabel = valueMap.getString("unitLabel");
    }
    // read options and filter criteria
    List<ParameterOption> options = readParameterOptions(valueMap.getObject("options"));
    @SuppressWarnings("unchecked") List<FilterCriteria> filterCriteria = (List<FilterCriteria>) valueMap.getObject("filter");
    // create object
    configDescriptionParam = ConfigDescriptionParameterBuilder.create(name, type).withMinimum(min).withMaximum(max).withStepSize(step).withPattern(patternString).withRequired(required).withReadOnly(readOnly).withMultiple(multiple).withContext(parameterContext).withDefault(defaultValue).withLabel(label).withDescription(description).withOptions(options).withFilterCriteria(filterCriteria).withGroupName(groupName).withAdvanced(advanced).withVerify(verify).withLimitToOptions(limitToOptions).withMultipleLimit(multipleLimit).withUnit(unit).withUnitLabel(unitLabel).build();
    return configDescriptionParam;
}
Also used : FilterCriteria(org.eclipse.smarthome.config.core.FilterCriteria) BigDecimal(java.math.BigDecimal) ConverterValueMap(org.eclipse.smarthome.config.xml.util.ConverterValueMap) Type(org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) List(java.util.List) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter)

Example 3 with ParameterOption

use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.

the class RuleEngineTest method createConfigDescriptions.

private List<ConfigDescriptionParameter> createConfigDescriptions() {
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<ConfigDescriptionParameter>();
    List<ParameterOption> options = new ArrayList<ParameterOption>();
    options.add(new ParameterOption("1", "one"));
    options.add(new ParameterOption("2", "two"));
    String groupName = null;
    Boolean advanced = false;
    Boolean limitToOptions = true;
    Integer multipleLimit = 0;
    String label = "label1";
    String pattern = null;
    String context = "context1";
    String description = "description1";
    BigDecimal min = null;
    BigDecimal max = null;
    BigDecimal step = null;
    Boolean required = true;
    Boolean multiple = false;
    Boolean readOnly = false;
    String typeStr = ConfigDescriptionParameter.Type.INTEGER.name();
    String defValue = "3";
    List<FilterCriteria> filter = new ArrayList<FilterCriteria>();
    String configPropertyName = "config1";
    ConfigDescriptionParameter cfgDP = ConfigDescriptionParameterBuilder.create(configPropertyName, Type.valueOf(typeStr)).withMaximum(max).withMinimum(min).withStepSize(step).withPattern(pattern).withRequired(required).withReadOnly(readOnly).withMultiple(multiple).withContext(context).withDefault(defValue).withLabel(label).withDescription(description).withOptions(options).withFilterCriteria(filter).withGroupName(groupName).withAdvanced(advanced).withLimitToOptions(limitToOptions).withMultipleLimit(multipleLimit).build();
    configDescriptions.add(cfgDP);
    return configDescriptions;
}
Also used : ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) FilterCriteria(org.eclipse.smarthome.config.core.FilterCriteria) BigDecimal(java.math.BigDecimal)

Example 4 with ParameterOption

use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.

the class AbstractResourceBundleProvider method getLocalizedConfigurationDescription.

protected List<ConfigDescriptionParameter> getLocalizedConfigurationDescription(TranslationProvider i18nProvider, List<ConfigDescriptionParameter> config, Bundle bundle, String uid, String prefix, Locale locale) {
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<ConfigDescriptionParameter>();
    if (config != null) {
        ConfigDescriptionI18nUtil util = new ConfigDescriptionI18nUtil(i18nProvider);
        for (ConfigDescriptionParameter parameter : config) {
            String parameterName = parameter.getName();
            URI uri = null;
            try {
                uri = new URI(prefix + ":" + uid + ".name");
            } catch (URISyntaxException e) {
                logger.error("Constructed invalid uri '{}:{}.name'", prefix, uid, e);
            }
            String llabel = parameter.getLabel();
            if (llabel != null) {
                llabel = util.getParameterLabel(bundle, uri, parameterName, llabel, locale);
            }
            String ldescription = parameter.getDescription();
            if (ldescription != null) {
                ldescription = util.getParameterDescription(bundle, uri, parameterName, ldescription, locale);
            }
            String lpattern = parameter.getPattern();
            if (lpattern != null) {
                lpattern = util.getParameterPattern(bundle, uri, parameterName, lpattern, locale);
            }
            List<ParameterOption> loptions = parameter.getOptions();
            if (loptions != null && !loptions.isEmpty()) {
                for (ParameterOption option : loptions) {
                    String label = util.getParameterOptionLabel(bundle, uri, parameterName, option.getValue(), option.getLabel(), locale);
                    option = new ParameterOption(option.getValue(), label);
                }
            }
            String lunitLabel = parameter.getUnitLabel();
            if (lunitLabel != null) {
                lunitLabel = util.getParameterUnitLabel(bundle, uri, parameterName, parameter.getUnit(), lunitLabel, locale);
            }
            configDescriptions.add(ConfigDescriptionParameterBuilder.create(parameterName, parameter.getType()).withMinimum(parameter.getMinimum()).withMaximum(parameter.getMaximum()).withStepSize(parameter.getStepSize()).withPattern(lpattern).withRequired(parameter.isRequired()).withMultiple(parameter.isMultiple()).withReadOnly(parameter.isReadOnly()).withContext(parameter.getContext()).withDefault(parameter.getDefault()).withLabel(llabel).withDescription(ldescription).withFilterCriteria(parameter.getFilterCriteria()).withGroupName(parameter.getGroupName()).withAdvanced(parameter.isAdvanced()).withOptions(loptions).withLimitToOptions(parameter.getLimitToOptions()).withMultipleLimit(parameter.getMultipleLimit()).withUnit(parameter.getUnit()).withUnitLabel(lunitLabel).build());
        }
    }
    return configDescriptions;
}
Also used : ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) ConfigDescriptionI18nUtil(org.eclipse.smarthome.config.core.i18n.ConfigDescriptionI18nUtil) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 5 with ParameterOption

use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.

the class MediaActionTypeProvider method getSinkOptions.

/**
 * This method creates one option for every sink that is found in the system.
 *
 * @return a list of parameter options representing the audio sinks
 */
private List<ParameterOption> getSinkOptions(Locale locale) {
    List<ParameterOption> options = new ArrayList<>();
    for (String sinkId : audioManager.getSinkIds()) {
        AudioSink sink = audioManager.getSink(sinkId);
        options.add(new ParameterOption(sinkId, sink.getLabel(locale)));
    }
    return options;
}
Also used : AudioSink(org.eclipse.smarthome.core.audio.AudioSink) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList)

Aggregations

ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)16 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)5 Test (org.junit.Test)5 List (java.util.List)4 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)4 BigDecimal (java.math.BigDecimal)2 FilterCriteria (org.eclipse.smarthome.config.core.FilterCriteria)2 AudioSink (org.eclipse.smarthome.core.audio.AudioSink)2 TTSServiceStub (org.eclipse.smarthome.core.voice.internal.TTSServiceStub)2 File (java.io.File)1 URISyntaxException (java.net.URISyntaxException)1 ZoneId (java.time.ZoneId)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1 TimeZone (java.util.TimeZone)1 TimeUnit (java.util.concurrent.TimeUnit)1