ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale); if (channelType != null) { stateDescription = channelType.getState(); if ((channelType.getItemType() != null) && ((stateDescription == null) || (stateDescription.getPattern() == null))) {
private StateDescription createLocalizedChannelState(Bundle bundle, ChannelType channelType, ChannelTypeUID channelTypeUID, Locale locale) { StateDescription state = channelType.getState(); if (state != null) { String pattern = this.thingTypeI18nUtil.getChannelStatePattern(bundle, channelTypeUID, state.getPattern(), locale); List<StateOption> localizedOptions = new ArrayList<>(); List<StateOption> options = state.getOptions(); for (StateOption stateOption : options) { String optionLabel = this.thingTypeI18nUtil.getChannelStateOption(bundle, channelTypeUID, stateOption.getValue(), stateOption.getLabel(), locale); localizedOptions.add(new StateOption(stateOption.getValue(), optionLabel)); } return new StateDescription(state.getMinimum(), state.getMaximum(), state.getStep(), pattern, state.isReadOnly(), localizedOptions); } return null; }
private ChannelTypeDTO convertToChannelTypeDTO(ChannelType channelType, Locale locale) { final ConfigDescription configDescription; if (channelType.getConfigDescriptionURI() != null) { configDescription = this.configDescriptionRegistry .getConfigDescription(channelType.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); } return new ChannelTypeDTO(channelType.getUID().toString(), channelType.getLabel(), channelType.getDescription(), channelType.getCategory(), channelType.getItemType(), channelType.getKind(), parameters, parameterGroups, channelType.getState(), channelType.getTags(), channelType.isAdvanced()); }
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; }
StateDescription state = createLocalizedStateDescription(bundle, channelType.getState(), channelTypeUID, locale); return new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), channelType.getKind(), label == null ? defaultLabel : label, description, channelType.getCategory(), channelType.getTags(), channelType.getState(), channelType.getEvent(), channelType.getConfigDescriptionURI(), channelType.getAutoUpdatePolicy());