Search in sources :

Example 1 with ChannelDefinitionDTO

use of org.openhab.core.thing.dto.ChannelDefinitionDTO 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 2 with ChannelDefinitionDTO

use of org.openhab.core.thing.dto.ChannelDefinitionDTO in project openhab-core by openhab.

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 = channelGroupTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
        // Default to the channelGroupDefinition label/description to override the channelGroupType
        String label = channelGroupDefinition.getLabel();
        String description = channelGroupDefinition.getDescription();
        List<ChannelDefinition> channelDefinitions = Collections.emptyList();
        if (channelGroupType == null) {
            logger.warn("Cannot find channel group type: {}", channelGroupDefinition.getTypeUID());
        } else {
            if (label == null) {
                label = channelGroupType.getLabel();
            }
            if (description == null) {
                description = channelGroupType.getDescription();
            }
            channelDefinitions = channelGroupType.getChannelDefinitions();
        }
        List<ChannelDefinitionDTO> channelDefinitionDTOs = convertToChannelDefinitionDTOs(channelDefinitions, locale);
        channelGroupDefinitionDTOs.add(new ChannelGroupDefinitionDTO(id, label, description, channelDefinitionDTOs));
    }
    return channelGroupDefinitionDTOs;
}
Also used : ChannelDefinitionDTO(org.openhab.core.thing.dto.ChannelDefinitionDTO) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelGroupDefinitionDTO(org.openhab.core.thing.dto.ChannelGroupDefinitionDTO) ChannelGroupType(org.openhab.core.thing.type.ChannelGroupType) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition)

Example 3 with ChannelDefinitionDTO

use of org.openhab.core.thing.dto.ChannelDefinitionDTO in project openhab-core by openhab.

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());
        } else {
            // 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;
}
Also used : ChannelDefinitionDTO(org.openhab.core.thing.dto.ChannelDefinitionDTO) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) ChannelType(org.openhab.core.thing.type.ChannelType)

Aggregations

ChannelDefinitionDTO (org.openhab.core.thing.dto.ChannelDefinitionDTO)3 ArrayList (java.util.ArrayList)2 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)2 URI (java.net.URI)1 ConfigDescription (org.openhab.core.config.core.ConfigDescription)1 ConfigDescriptionDTO (org.openhab.core.config.core.dto.ConfigDescriptionDTO)1 ConfigDescriptionParameterDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterDTO)1 ConfigDescriptionParameterGroupDTO (org.openhab.core.config.core.dto.ConfigDescriptionParameterGroupDTO)1 ChannelGroupDefinitionDTO (org.openhab.core.thing.dto.ChannelGroupDefinitionDTO)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 ChannelGroupDefinition (org.openhab.core.thing.type.ChannelGroupDefinition)1 ChannelGroupType (org.openhab.core.thing.type.ChannelGroupType)1 ChannelType (org.openhab.core.thing.type.ChannelType)1