use of org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO 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.core.thing.dto.ChannelDefinitionDTO in project smarthome by eclipse.
the class ThingTypeResource method convertToChannelGroupDefinitionDTOs.
private List<ChannelGroupDefinitionDTO> convertToChannelGroupDefinitionDTOs(List<ChannelGroupDefinition> channelGroupDefinitions, Locale locale) {
List<ChannelGroupDefinitionDTO> channelGroupDefinitionDTOs = new ArrayList<>();
for (ChannelGroupDefinition channelGroupDefinition : channelGroupDefinitions) {
String id = channelGroupDefinition.getId();
ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
// Default to the channelGroupDefinition label to override the
// channelGroupType
String label = channelGroupDefinition.getLabel();
if (label == null) {
label = channelGroupType.getLabel();
}
// Default to the channelGroupDefinition description to override the
// channelGroupType
String description = channelGroupDefinition.getDescription();
if (description == null) {
description = channelGroupType.getDescription();
}
List<ChannelDefinition> channelDefinitions = channelGroupType.getChannelDefinitions();
List<ChannelDefinitionDTO> channelDefinitionDTOs = convertToChannelDefinitionDTOs(channelDefinitions, locale);
channelGroupDefinitionDTOs.add(new ChannelGroupDefinitionDTO(id, label, description, channelDefinitionDTOs));
}
return channelGroupDefinitionDTOs;
}
use of org.eclipse.smarthome.core.thing.dto.ChannelDefinitionDTO in project smarthome by eclipse.
the class ThingTypeResource method convertToChannelDefinitionDTOs.
private List<ChannelDefinitionDTO> convertToChannelDefinitionDTOs(List<ChannelDefinition> channelDefinitions, Locale locale) {
List<ChannelDefinitionDTO> channelDefinitionDTOs = new ArrayList<>();
for (ChannelDefinition channelDefinition : channelDefinitions) {
ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale);
if (channelType == null) {
logger.warn("Cannot find channel type: {}", channelDefinition.getChannelTypeUID());
return null;
}
// Default to the channelDefinition label to override the
// channelType
String label = channelDefinition.getLabel();
if (label == null) {
label = channelType.getLabel();
}
// Default to the channelDefinition description to override the
// channelType
String description = channelDefinition.getDescription();
if (description == null) {
description = channelType.getDescription();
}
ChannelDefinitionDTO channelDefinitionDTO = new ChannelDefinitionDTO(channelDefinition.getId(), channelDefinition.getChannelTypeUID().toString(), label, description, channelType.getTags(), channelType.getCategory(), channelType.getState(), channelType.isAdvanced(), channelDefinition.getProperties());
channelDefinitionDTOs.add(channelDefinitionDTO);
}
return channelDefinitionDTOs;
}
Aggregations