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());
}
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());
}
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"))));
}
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()));
}
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()));
}
Aggregations