use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.
the class RuleEngine method isOptionalConfig.
private boolean isOptionalConfig(List<ConfigDescriptionParameter> configDescriptions) {
if (configDescriptions != null && !configDescriptions.isEmpty()) {
boolean required = false;
Iterator<ConfigDescriptionParameter> i = configDescriptions.iterator();
while (i.hasNext()) {
ConfigDescriptionParameter param = i.next();
required = required || param.isRequired();
}
return !required;
}
return true;
}
use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.
the class Printer method getConfigurationDescriptionRecords.
/**
* This method is responsible for printing the set of {@link ConfigDescriptionParameter}s.
*
* @param configDescriptions set of {@link ConfigDescriptionParameter}s for printing.
* @return a formated string, representing the set of {@link ConfigDescriptionParameter}s.
*/
private static List<String> getConfigurationDescriptionRecords(List<ConfigDescriptionParameter> configDescriptions) {
List<String> configParamContent = new ArrayList<String>();
if (configDescriptions != null && !configDescriptions.isEmpty()) {
for (ConfigDescriptionParameter parameter : configDescriptions) {
int[] columnWidths = new int[] { COLUMN_CONFIG_PARAMETER, COLUMN_CONFIG_PARAMETER_PROP, COLUMN_CONFIG_PARAMETER_PROP_VALUE };
configParamContent.add(Utils.getColumn(COLUMN_PROPERTY_VALUE, parameter.getName() + " : "));
List<String> configParamProperty = new ArrayList<String>();
configParamProperty.add("");
configParamProperty.add(TYPE);
configParamProperty.add(parameter.getType().toString());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
if (parameter.getLabel() != null) {
configParamProperty.set(1, LABEL);
configParamProperty.set(2, parameter.getLabel());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getDescription() != null) {
configParamProperty.set(1, DESCRIPTION);
configParamProperty.set(2, parameter.getDescription());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getDefault() != null) {
configParamProperty.set(1, DEFAULT);
configParamProperty.set(2, parameter.getDefault());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getContext() != null) {
configParamProperty.set(1, CONTEXT);
configParamProperty.set(2, parameter.getContext());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getPattern() != null) {
configParamProperty.set(1, PATTERN);
configParamProperty.set(2, parameter.getPattern());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getStepSize() != null) {
configParamProperty.set(1, STEP_SIZE);
configParamProperty.set(2, parameter.getStepSize().toString());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getMinimum() != null) {
configParamProperty.set(1, MIN);
configParamProperty.set(2, parameter.getMinimum().toString());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
if (parameter.getMaximum() != null) {
configParamProperty.set(1, MAX);
configParamProperty.set(2, parameter.getMaximum().toString());
configParamContent.add(Utils.getRow(columnWidths, configParamProperty));
}
columnWidths = new int[] { COLUMN_CONFIG_PARAMETER_PROP, COLUMN_CONFIG_PARAMETER_PROP_VALUE };
List<String> options = collectRecords(columnWidths, OPTIONS, parameter.getOptions());
for (String option : options) {
configParamContent.add(Utils.getColumn(COLUMN_CONFIG_PARAMETER, "") + option);
}
List<String> filters = collectRecords(columnWidths, FILTER_CRITERIA, parameter.getFilterCriteria());
for (String filter : filters) {
configParamContent.add(Utils.getColumn(COLUMN_CONFIG_PARAMETER, "") + filter);
}
configParamContent.add(Utils.getColumn(COLUMN_PROPERTY_VALUE, Utils.printChars('-', COLUMN_PROPERTY_VALUE)));
}
}
return configParamContent;
}
use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.
the class ThingFactoryHelper method createChannelBuilder.
static ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelType channelType, ConfigDescriptionRegistry configDescriptionRegistry) {
ChannelBuilder channelBuilder = //
ChannelBuilder.create(channelUID, channelType.getItemType()).withType(//
channelType.getUID()).withDefaultTags(//
channelType.getTags()).withKind(//
channelType.getKind()).withLabel(channelType.getLabel());
String description = channelType.getDescription();
if (description != null) {
channelBuilder = channelBuilder.withDescription(description);
}
// Initialize channel configuration with default-values
URI channelConfigDescriptionURI = channelType.getConfigDescriptionURI();
if (configDescriptionRegistry != null && channelConfigDescriptionURI != null) {
ConfigDescription cd = configDescriptionRegistry.getConfigDescription(channelConfigDescriptionURI);
if (cd != null) {
Configuration config = new Configuration();
for (ConfigDescriptionParameter param : cd.getParameters()) {
String defaultValue = param.getDefault();
if (defaultValue != null) {
Object value = getDefaultValueAsCorrectType(param.getType(), defaultValue);
if (value != null) {
config.put(param.getName(), value);
}
}
}
channelBuilder = channelBuilder.withConfiguration(config);
}
}
return channelBuilder;
}
use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.
the class ThingManagerOSGiJavaTest method testInitializeOnlyIfInitializable.
@Test
public void testInitializeOnlyIfInitializable() throws Exception {
registerThingTypeProvider();
registerChannelTypeProvider();
registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) {
@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
}
});
ConfigDescriptionProvider mockConfigDescriptionProvider = mock(ConfigDescriptionProvider.class);
List<ConfigDescriptionParameter> parameters = //
Collections.singletonList(//
ConfigDescriptionParameterBuilder.create(CONFIG_PARAM_NAME, Type.TEXT).withRequired(true).build());
registerService(mockConfigDescriptionProvider, ConfigDescriptionProvider.class.getName());
// verify a missing mandatory thing config prevents it from getting initialized
when(mockConfigDescriptionProvider.getConfigDescription(eq(CONFIG_DESCRIPTION_THING), any())).thenReturn(new ConfigDescription(CONFIG_DESCRIPTION_THING, parameters));
assertThingStatus(Collections.emptyMap(), Collections.emptyMap(), ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING);
// verify a missing mandatory channel config prevents it from getting initialized
when(mockConfigDescriptionProvider.getConfigDescription(eq(CONFIG_DESCRIPTION_CHANNEL), any())).thenReturn(new ConfigDescription(CONFIG_DESCRIPTION_CHANNEL, parameters));
assertThingStatus(Collections.singletonMap(CONFIG_PARAM_NAME, "value"), Collections.emptyMap(), ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_CONFIGURATION_PENDING);
// verify a satisfied config does not prevent it from getting initialized anymore
assertThingStatus(Collections.singletonMap(CONFIG_PARAM_NAME, "value"), Collections.singletonMap(CONFIG_PARAM_NAME, "value"), ThingStatus.ONLINE, ThingStatusDetail.NONE);
}
use of org.eclipse.smarthome.config.core.ConfigDescriptionParameter in project smarthome by eclipse.
the class ConfigDescriptionsTest method ConfigDescriptionsShouldLoadProperly.
@Test
public void ConfigDescriptionsShouldLoadProperly() throws Exception {
int initialNumberOfConfigDescriptions = configDescriptionRegistry.getConfigDescriptions().size();
// install test bundle
Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME);
assertThat(bundle, is(notNullValue()));
Collection<ConfigDescription> configDescriptions = configDescriptionRegistry.getConfigDescriptions();
assertThat(configDescriptions.size(), is(initialNumberOfConfigDescriptions + 3));
URI bridgeURI = new URI("thing-type:hue:bridge");
ConfigDescription bridgeConfigDescription = configDescriptions.stream().filter(it -> it.getUID().equals(bridgeURI)).findFirst().get();
assertThat(bridgeConfigDescription, is(notNullValue()));
Collection<ConfigDescriptionParameter> parameters = bridgeConfigDescription.getParameters();
assertThat(parameters.size(), is(2));
ConfigDescriptionParameter ipParameter = parameters.stream().filter(it -> it.getName().equals("ip")).findFirst().get();
assertThat(ipParameter, is(notNullValue()));
assertThat(ipParameter.getType(), is(Type.TEXT));
assertThat(ipParameter.getContext(), is("network-address"));
assertThat(ipParameter.getLabel(), is("Network Address"));
assertThat(ipParameter.getDescription(), is("Network address of the hue bridge."));
assertThat(ipParameter.isRequired(), is(true));
ConfigDescriptionParameter userNameParameter = parameters.stream().filter(it -> it.getName().equals("username")).findFirst().get();
assertThat(userNameParameter, is(notNullValue()));
assertThat(userNameParameter.isAdvanced(), is(true));
assertThat(userNameParameter.getType(), is(Type.TEXT));
assertThat(userNameParameter.getContext(), is("password"));
assertThat(userNameParameter.getLabel(), is("Username"));
assertThat(userNameParameter.getDescription(), is("Name of a registered hue bridge user, that allows to access the API."));
URI colorURI = new URI("channel-type:hue:color");
ConfigDescription colorConfigDescription = configDescriptions.stream().filter(it -> it.getUID().equals(colorURI)).findFirst().get();
assertThat(colorConfigDescription, is(notNullValue()));
parameters = colorConfigDescription.getParameters();
assertThat(parameters.size(), is(1));
ConfigDescriptionParameter lastDimValueParameter = parameters.stream().filter(it -> it.getName().equals("lastDimValue")).findFirst().get();
assertThat(lastDimValueParameter, is(notNullValue()));
assertThat(lastDimValueParameter.getType(), is(Type.BOOLEAN));
Collection<ConfigDescriptionParameterGroup> groups = bridgeConfigDescription.getParameterGroups();
assertThat(groups.size(), is(2));
ConfigDescriptionParameterGroup group1 = groups.stream().filter(it -> it.getName().equals("group1")).findFirst().get();
assertThat(group1, is(notNullValue()));
assertThat(group1.getContext(), is("Group1-context"));
assertThat(group1.getLabel(), is("Group Label 1"));
assertThat(group1.getDescription(), is("Group description 1"));
// uninstall test bundle
bundle.uninstall();
assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
}
Aggregations