/** * Creates a new channel definition builder. * * @param channelDefinition the channel definition the builder should be initialized by */ public ChannelDefinitionBuilder(final ChannelDefinition channelDefinition) { this(channelDefinition.getId(), channelDefinition.getChannelTypeUID()); this.properties = channelDefinition.getProperties(); this.label = channelDefinition.getLabel(); this.description = channelDefinition.getDescription(); this.autoUpdatePolicy = channelDefinition.getAutoUpdatePolicy(); }
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; }
private static Channel createChannel(ChannelDefinition channelDefinition, ThingUID thingUID, String groupId, ConfigDescriptionRegistry configDescriptionRegistry) { ChannelType type = withChannelTypeRegistry(channelTypeRegistry -> { return (channelTypeRegistry != null) ? channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID()) : null; }); if (type == null) { logger.warn( "Could not create channel '{}' for thing type '{}', because channel type '{}' could not be found.", channelDefinition.getId(), thingUID, channelDefinition.getChannelTypeUID()); return null; } ChannelUID channelUID = new ChannelUID(thingUID, groupId, channelDefinition.getId()); ChannelBuilder channelBuilder = createChannelBuilder(channelUID, type, configDescriptionRegistry); // If we want to override the label, add it... final String label = channelDefinition.getLabel(); if (label != null) { channelBuilder = channelBuilder.withLabel(label); } // If we want to override the description, add it... final String description = channelDefinition.getDescription(); if (description != null) { channelBuilder = channelBuilder.withDescription(description); } channelBuilder = channelBuilder.withProperties(channelDefinition.getProperties()); return channelBuilder.build(); }
public ChannelGroupType createLocalizedChannelGroupType(Bundle bundle, ChannelGroupType channelGroupType, @Nullable Locale locale) { ChannelGroupTypeUID channelGroupTypeUID = channelGroupType.getUID(); String defaultLabel = channelGroupType.getLabel(); String label = thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupTypeUID, defaultLabel, locale); String description = thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupTypeUID, channelGroupType.getDescription(), locale); List<ChannelDefinition> localizedChannelDefinitions = channelI18nUtil.createLocalizedChannelDefinitions(bundle, channelGroupType.getChannelDefinitions(), channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, channelGroupTypeUID, channelDefinition, channelDefinition.getLabel(), locale), channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, channelGroupTypeUID, channelDefinition, channelDefinition.getDescription(), locale), locale); ChannelGroupTypeBuilder builder = ChannelGroupTypeBuilder .instance(channelGroupTypeUID, label == null ? defaultLabel : label) .isAdvanced(channelGroupType.isAdvanced()).withCategory(channelGroupType.getCategory()) .withChannelDefinitions(localizedChannelDefinitions); if (description != null) { builder.withDescription(description); } return builder.build(); }
thingType.getChannelDefinitions(), channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, thingTypeUID, channelDefinition, channelDefinition.getLabel(), locale), channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, thingTypeUID, channelDefinition, channelDefinition.getDescription(), locale),