Search in sources :

Example 1 with ConfigDescriptionDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionDTO in project openhab-core by openhab.

the class ChannelTypeResource method convertToChannelTypeDTO.

private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) {
    final URI descURI = channelType.getConfigDescriptionURI();
    final ConfigDescription configDescription = descURI == null ? null : configDescriptionRegistry.getConfigDescription(descURI, locale);
    final ConfigDescriptionDTO configDescriptionDTO = configDescription == null ? null : ConfigDescriptionDTOMapper.map(configDescription);
    final List<ConfigDescriptionParameterDTO> parameters = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameters;
    final List<ConfigDescriptionParameterGroupDTO> parameterGroups = configDescriptionDTO == null ? List.of() : configDescriptionDTO.parameterGroups;
    return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced(), channelType.getCommandDescription());
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ChannelTypeDTO(org.openhab.core.thing.dto.ChannelTypeDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) URI(java.net.URI)

Example 2 with ConfigDescriptionDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionDTO in project openhab-core by openhab.

the class ThingTypeResource method convertToThingTypeDTO.

private ThingTypeDTO convertToThingTypeDTO(ThingType thingType, Locale locale) {
    final ConfigDescription configDescription;
    final URI descURI = thingType.getConfigDescriptionURI();
    configDescription = descURI == null ? null : configDescriptionRegistry.getConfigDescription(descURI, locale);
    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);
    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.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionParameterGroupDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ChannelDefinitionDTO(org.openhab.core.thing.dto.ChannelDefinitionDTO) ThingTypeDTO(org.openhab.core.thing.dto.ThingTypeDTO) StrippedThingTypeDTO(org.openhab.core.thing.dto.StrippedThingTypeDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) URI(java.net.URI) BridgeType(org.openhab.core.thing.type.BridgeType)

Example 3 with ConfigDescriptionDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionDTO in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapperTest method testThatDefaultValuesAreAList.

@Test
public void testThatDefaultValuesAreAList() {
    ConfigDescriptionParameter configDescriptionParameter = ConfigDescriptionParameterBuilder.create(CONFIG_PARAMETER_NAME, Type.TEXT).withDefault(CONFIG_PARAMETER_DEFAULT_VALUE).withMultiple(true).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(CONFIG_URI).withParameter(configDescriptionParameter).build();
    ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription);
    assertThat(cddto.parameters, hasSize(1));
    ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0);
    assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class));
    assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE));
    EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto;
    assertThat(ecdpdto.defaultValues, is(notNullValue()));
    assertThat(ecdpdto.defaultValues, hasSize(3));
    assertThat(ecdpdto.defaultValues, is(equalTo(List.of("first value", "second value", "third value"))));
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigDescriptionDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionDTO in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapperTest method testThatDefaultValueIsNotAList.

@Test
public void testThatDefaultValueIsNotAList() {
    ConfigDescriptionParameter configDescriptionParameter = ConfigDescriptionParameterBuilder.create(CONFIG_PARAMETER_NAME, Type.TEXT).withDefault(CONFIG_PARAMETER_DEFAULT_VALUE).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(CONFIG_URI).withParameter(configDescriptionParameter).build();
    ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription);
    assertThat(cddto.parameters, hasSize(1));
    ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0);
    assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class));
    assertThat(cdpdto.defaultValue, is(CONFIG_PARAMETER_DEFAULT_VALUE));
    EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto;
    assertThat(ecdpdto.defaultValues, is(nullValue()));
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigDescriptionDTO

use of org.openhab.core.config.core.dto.ConfigDescriptionDTO in project openhab-core by openhab.

the class EnrichedConfigDescriptionDTOMapperTest method testThatDefaultValuesAreEmptyIfMultipleIsTrue.

@Test
public void testThatDefaultValuesAreEmptyIfMultipleIsTrue() {
    ConfigDescriptionParameter configDescriptionParameter = ConfigDescriptionParameterBuilder.create(CONFIG_PARAMETER_NAME, Type.TEXT).withMultiple(true).build();
    ConfigDescription configDescription = ConfigDescriptionBuilder.create(CONFIG_URI).withParameter(configDescriptionParameter).build();
    ConfigDescriptionDTO cddto = EnrichedConfigDescriptionDTOMapper.map(configDescription);
    assertThat(cddto.parameters, hasSize(1));
    ConfigDescriptionParameterDTO cdpdto = cddto.parameters.get(0);
    assertThat(cdpdto, instanceOf(EnrichedConfigDescriptionParameterDTO.class));
    assertThat(cdpdto.defaultValue, is(nullValue()));
    EnrichedConfigDescriptionParameterDTO ecdpdto = (EnrichedConfigDescriptionParameterDTO) cdpdto;
    assertThat(ecdpdto.defaultValues, is(nullValue()));
}
Also used : ConfigDescriptionParameterDTO(org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO) ConfigDescriptionDTO(org.openhab.core.config.core.dto.ConfigDescriptionDTO) ConfigDescription(org.openhab.core.config.core.ConfigDescription) ConfigDescriptionParameter(org.openhab.core.config.core.ConfigDescriptionParameter) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigDescription (org.openhab.core.config.core.ConfigDescription)5 ConfigDescriptionDTO (org.openhab.core.config.core.dto.ConfigDescriptionDTO)5 ConfigDescriptionParameterDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO)5 Test (org.junit.jupiter.api.Test)3 ConfigDescriptionParameter (org.openhab.core.config.core.ConfigDescriptionParameter)3 URI (java.net.URI)2 ConfigDescriptionParameterGroupDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO)2 ChannelDefinitionDTO (org.openhab.core.thing.dto.ChannelDefinitionDTO)1 ChannelTypeDTO (org.openhab.core.thing.dto.ChannelTypeDTO)1 StrippedThingTypeDTO (org.openhab.core.thing.dto.StrippedThingTypeDTO)1 ThingTypeDTO (org.openhab.core.thing.dto.ThingTypeDTO)1 BridgeType (org.openhab.core.thing.type.BridgeType)1