Search in sources :

Example 6 with ConfigDescription

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));
}
Also used : ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URISyntaxException(java.net.URISyntaxException) ConfigurableServiceDTO(org.eclipse.smarthome.io.rest.core.service.ConfigurableServiceDTO) URI(java.net.URI)

Example 7 with ConfigDescription

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());
}
Also used : ConfigDescriptionParameterDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.eclipse.smarthome.config.core.dto.ConfigDescriptionDTO) ChannelDefinitionDTO(org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO) ThingTypeDTO(org.eclipse.smarthome.core.thing.dto.ThingTypeDTO) StrippedThingTypeDTO(org.eclipse.smarthome.core.thing.dto.StrippedThingTypeDTO) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) BridgeType(org.eclipse.smarthome.core.thing.type.BridgeType)

Example 8 with ConfigDescription

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;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ChannelBuilder(org.eclipse.smarthome.core.thing.binding.builder.ChannelBuilder) URI(java.net.URI)

Example 9 with ConfigDescription

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);
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) Command(org.eclipse.smarthome.core.types.Command) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) ConfigDescriptionProvider(org.eclipse.smarthome.config.core.ConfigDescriptionProvider) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 10 with ConfigDescription

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 };
}
Also used : ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URI(java.net.URI)

Aggregations

ConfigDescription (org.eclipse.smarthome.config.core.ConfigDescription)22 URI (java.net.URI)10 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)9 ArrayList (java.util.ArrayList)5 List (java.util.List)3 ConfigDescriptionParameterGroup (org.eclipse.smarthome.config.core.ConfigDescriptionParameterGroup)3 BindingInfo (org.eclipse.smarthome.core.binding.BindingInfo)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 URISyntaxException (java.net.URISyntaxException)2 Locale (java.util.Locale)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 ConfigDescriptionDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionDTO)2 ConfigDescriptionParameterDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterDTO)2 ConfigDescriptionParameterGroupDTO (org.eclipse.smarthome.config.core.dto.ConfigDescriptionParameterGroupDTO)2 NodeIterator (org.eclipse.smarthome.config.xml.util.NodeIterator)2 ThingType (org.eclipse.smarthome.core.thing.type.ThingType)2