Search in sources :

Example 16 with ConfigDescription

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

the class PersistentInboxTest method configureConfigDescriptionRegistryMock.

private void configureConfigDescriptionRegistryMock(String paramName, Type type) throws URISyntaxException {
    URI configDescriptionURI = new URI("thing-type:test:test");
    ThingType thingType = ThingTypeBuilder.instance(THING_TYPE_UID, "Test").withConfigDescriptionURI(configDescriptionURI).build();
    ConfigDescriptionParameter param = ConfigDescriptionParameterBuilder.create(paramName, type).build();
    ConfigDescription configDesc = new ConfigDescription(configDescriptionURI, Collections.singletonList(param));
    when(thingTypeRegistry.getThingType(THING_TYPE_UID)).thenReturn(thingType);
    when(configDescriptionRegistry.getConfigDescription(eq(configDescriptionURI))).thenReturn(configDesc);
}
Also used : ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) URI(java.net.URI) ThingType(org.eclipse.smarthome.core.thing.type.ThingType)

Example 17 with ConfigDescription

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

the class BindingInfoXmlProvider method addingObject.

@Override
public synchronized void addingObject(BindingInfoXmlResult bindingInfoXmlResult) {
    if (bindingInfoXmlResult != null) {
        ConfigDescription configDescription = bindingInfoXmlResult.getConfigDescription();
        if (configDescription != null) {
            try {
                this.configDescriptionProvider.add(this.bundle, configDescription);
            } catch (Exception ex) {
                this.logger.error("Could not register ConfigDescription!", ex);
            }
        }
        BindingInfo bindingInfo = bindingInfoXmlResult.getBindingInfo();
        this.bindingInfoProvider.add(bundle, bindingInfo);
    }
}
Also used : BindingInfo(org.eclipse.smarthome.core.binding.BindingInfo) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription)

Example 18 with ConfigDescription

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

the class ThingManager method isComplete.

/**
 * Determines if all 'required' configuration parameters are available in the configuration
 *
 * @param prototype the "prototype", i.e. thing type or channel type
 * @param targetUID the UID of the thing or channel entity
 * @param configDescriptionURIFunction a function to determine the the config description UID for the given
 *            prototype
 * @param configuration the current configuration
 * @return true if all required configuration parameters are given, false otherwise
 */
private <T extends Identifiable<?>> boolean isComplete(T prototype, UID targetUID, Function<T, URI> configDescriptionURIFunction, Configuration configuration) {
    if (prototype == null) {
        logger.debug("Prototype for '{}' is not known, assuming it is initializable", targetUID);
        return true;
    }
    ConfigDescription description = resolve(configDescriptionURIFunction.apply(prototype), null);
    if (description == null) {
        logger.debug("Config description for '{}' is not resolvable, assuming '{}' is initializable", prototype.getUID(), targetUID);
        return true;
    }
    List<String> requiredParameters = getRequiredParameters(description);
    Set<String> propertyKeys = configuration.getProperties().keySet();
    if (logger.isDebugEnabled()) {
        logger.debug("Configuration of '{}' needs {}, has {}.", targetUID, requiredParameters, propertyKeys);
    }
    return propertyKeys.containsAll(requiredParameters);
}
Also used : ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription)

Example 19 with ConfigDescription

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

the class ItemChannelLinkConfigDescriptionProvider method getConfigDescription.

@Override
public ConfigDescription getConfigDescription(URI uri, Locale locale) {
    if (SCHEME.equals(uri.getScheme())) {
        ItemChannelLink link = itemChannelLinkRegistry.get(uri.getSchemeSpecificPart());
        if (link == null) {
            return null;
        }
        Item item = itemRegistry.get(link.getItemName());
        if (item == null) {
            return null;
        }
        Thing thing = thingRegistry.get(link.getLinkedUID().getThingUID());
        if (thing == null) {
            return null;
        }
        Channel channel = thing.getChannel(link.getLinkedUID().getId());
        if (channel == null) {
            return null;
        }
        ConfigDescriptionParameter paramProfile = ConfigDescriptionParameterBuilder.create(PARAM_PROFILE, Type.TEXT).withLabel("Profile").withDescription("the profile to use").withRequired(false).withLimitToOptions(true).withOptions(getOptions(link, item, channel, locale)).build();
        return new ConfigDescription(uri, Collections.singletonList(paramProfile));
    }
    return null;
}
Also used : Item(org.eclipse.smarthome.core.items.Item) Channel(org.eclipse.smarthome.core.thing.Channel) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 20 with ConfigDescription

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

the class ConfigDescriptionResource method getByURI.

@GET
@Path("/{uri}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a config description by URI.", response = ConfigDescriptionDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ConfigDescriptionDTO.class), @ApiResponse(code = 400, message = "Invalid URI syntax"), @ApiResponse(code = 404, message = "Not found") })
public Response getByURI(@HeaderParam("Accept-Language") @ApiParam(value = "Accept-Language") String language, @PathParam("uri") @ApiParam(value = "uri") String uri) {
    Locale locale = LocaleUtil.getLocale(language);
    URI uriObject = UriBuilder.fromPath(uri).build();
    ConfigDescription configDescription = this.configDescriptionRegistry.getConfigDescription(uriObject, locale);
    return configDescription != null ? Response.ok(ConfigDescriptionDTOMapper.map(configDescription)).build() : JSONResponse.createErrorResponse(Status.NOT_FOUND, "Configuration not found: " + uri);
}
Also used : Locale(java.util.Locale) ConfigDescription(org.eclipse.smarthome.config.core.ConfigDescription) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

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