use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.
the class ConfigurableServiceResource method normalizeConfiguration.
private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, String serviceId) {
if (properties == null || properties.isEmpty()) {
return properties;
}
ConfigurableServiceDTO service = getServiceById(serviceId);
if (service == null) {
return properties;
}
URI uri;
try {
uri = new URI(service.configDescriptionURI);
} catch (URISyntaxException e) {
logger.warn("Not a valid URI: {}", service.configDescriptionURI);
return properties;
}
ConfigDescription configDesc = configDescRegistry.getConfigDescription(uri);
if (configDesc == null) {
return properties;
}
return ConfigUtil.normalizeTypes(properties, Collections.singletonList(configDesc));
}
use of org.eclipse.smarthome.config.core.ConfigDescription in project smarthome by eclipse.
the class ThingTypeResource method convertToThingTypeDTO.
private ThingTypeDTO convertToThingTypeDTO(ThingType thingType, Locale locale) {
final ConfigDescription configDescription;
if (thingType.getConfigDescriptionURI() != null) {
configDescription = this.configDescriptionRegistry.getConfigDescription(thingType.getConfigDescriptionURI(), locale);
} else {
configDescription = null;
}
List<ConfigDescriptionParameterDTO> parameters;
List<ConfigDescriptionParameterGroupDTO> parameterGroups;
if (configDescription != null) {
ConfigDescriptionDTO configDescriptionDTO = ConfigDescriptionDTOMapper.map(configDescription);
parameters = configDescriptionDTO.parameters;
parameterGroups = configDescriptionDTO.parameterGroups;
} else {
parameters = new ArrayList<>(0);
parameterGroups = new ArrayList<>(0);
}
final List<ChannelDefinitionDTO> channelDefinitions = convertToChannelDefinitionDTOs(thingType.getChannelDefinitions(), locale);
if (channelDefinitions == null) {
return null;
}
return new ThingTypeDTO(thingType.getUID().toString(), thingType.getLabel(), thingType.getDescription(), thingType.getCategory(), thingType.isListed(), parameters, channelDefinitions, convertToChannelGroupDefinitionDTOs(thingType.getChannelGroupDefinitions(), locale), thingType.getSupportedBridgeTypeUIDs(), thingType.getProperties(), thingType instanceof BridgeType, parameterGroups, thingType.getExtensibleChannelTypeIds());
}
use of org.eclipse.smarthome.config.core.ConfigDescription 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.ConfigDescription 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.ConfigDescription in project smarthome by eclipse.
the class AbstractDescriptionTypeConverter method getConfigDescriptionObjects.
/**
* Returns the value of the {@code config-description-ref} and the {@code config-description} tags from the specific
* XML type definition.
*
* @param nodeIterator the iterator to be used to extract the information (must not be null)
*
* @return the URI and configuration object
* (contains two elements: URI - could be null, ConfigDescription - could be null)
*/
protected Object[] getConfigDescriptionObjects(NodeIterator nodeIterator) {
URI configDescriptionURI = readConfigDescriptionURI(nodeIterator);
ConfigDescription configDescription = null;
if (configDescriptionURI == null) {
configDescription = readConfigDescription(nodeIterator);
if (configDescription != null) {
configDescriptionURI = configDescription.getUID();
}
}
return new Object[] { configDescriptionURI, configDescription };
}
Aggregations