Search in sources :

Example 1 with ConfigDescriptionParameterBuilder

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

the class MetadataConfigDescriptionProviderImpl method createValueConfigDescription.

private ConfigDescription createValueConfigDescription(MetadataConfigDescriptionProvider provider, @Nullable Locale locale) {
    String namespace = provider.getNamespace();
    String description = provider.getDescription(locale);
    List<ParameterOption> options = provider.getParameterOptions(locale);
    URI uri = URI.create(SCHEME + SEPARATOR + namespace);
    ConfigDescriptionParameterBuilder builder = ConfigDescriptionParameterBuilder.create("value", Type.TEXT);
    if (options != null && !options.isEmpty()) {
        builder.withOptions(options);
        builder.withLimitToOptions(true);
    } else {
        builder.withLimitToOptions(false);
    }
    builder.withDescription(description != null ? description : namespace);
    ConfigDescriptionParameter parameter = builder.build();
    return new ConfigDescription(uri, Collections.singletonList(parameter));
}
Also used : ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ConfigDescriptionParameterBuilder(org.eclipse.smarthome.config.core.ConfigDescriptionParameterBuilder) URI(java.net.URI)

Example 2 with ConfigDescriptionParameterBuilder

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

the class HomematicTypeGeneratorImpl method generateConfigDescription.

private void generateConfigDescription(HmDevice device, URI configDescriptionURI) {
    List<ConfigDescriptionParameter> parms = new ArrayList<ConfigDescriptionParameter>();
    List<ConfigDescriptionParameterGroup> groups = new ArrayList<ConfigDescriptionParameterGroup>();
    for (HmChannel channel : device.getChannels()) {
        String groupName = "HMG_" + channel.getNumber();
        String groupLabel = MetadataUtils.getDescription("CHANNEL_NAME") + " " + channel.getNumber();
        groups.add(new ConfigDescriptionParameterGroup(groupName, null, false, groupLabel, null));
        for (HmDatapoint dp : channel.getDatapoints()) {
            if (dp.getParamsetType() == HmParamsetType.MASTER) {
                ConfigDescriptionParameterBuilder builder = ConfigDescriptionParameterBuilder.create(MetadataUtils.getParameterName(dp), MetadataUtils.getConfigDescriptionParameterType(dp));
                builder.withLabel(MetadataUtils.getLabel(dp));
                builder.withDefault(ObjectUtils.toString(dp.getDefaultValue()));
                builder.withDescription(MetadataUtils.getDatapointDescription(dp));
                if (dp.isEnumType()) {
                    builder.withLimitToOptions(dp.isEnumType());
                    List<ParameterOption> options = MetadataUtils.generateOptions(dp, new OptionsBuilder<ParameterOption>() {

                        @Override
                        public ParameterOption createOption(String value, String description) {
                            return new ParameterOption(value, description);
                        }
                    });
                    builder.withOptions(options);
                }
                if (dp.isNumberType()) {
                    builder.withMinimum(MetadataUtils.createBigDecimal(dp.getMinValue()));
                    builder.withMaximum(MetadataUtils.createBigDecimal(dp.getMaxValue()));
                    builder.withStepSize(MetadataUtils.createBigDecimal(dp.isFloatType() ? new Float(0.1) : 1L));
                    builder.withUnitLabel(MetadataUtils.getUnit(dp));
                }
                builder.withGroupName(groupName);
                parms.add(builder.build());
            }
        }
    }
    configDescriptionProvider.addConfigDescription(new ConfigDescription(configDescriptionURI, parms, groups));
}
Also used : ArrayList(java.util.ArrayList) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameterBuilder(org.eclipse.smarthome.config.core.ConfigDescriptionParameterBuilder) HmDatapoint(org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint) ConfigDescriptionParameterGroup(org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) HmChannel(org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)

Aggregations

ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)2 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)2 ConfigDescriptionParameterBuilder (org.eclipse.smarthome.config.core.ConfigDescriptionParameterBuilder)2 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HmChannel (org.eclipse.smarthome.binding.homematic.internal.model.HmChannel)1 HmDatapoint (org.eclipse.smarthome.binding.homematic.internal.model.HmDatapoint)1 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)1