private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, ChannelTypeUID channelTypeUID, ChannelUID channelUID) { if (properties == null || properties.isEmpty()) { return properties; } ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID); if (channelType == null) { return properties; } List<ConfigDescription> configDescriptions = new ArrayList<>(2); if (channelType.getConfigDescriptionURI() != null) { ConfigDescription typeConfigDesc = configDescRegistry .getConfigDescription(channelType.getConfigDescriptionURI()); if (typeConfigDesc != null) { configDescriptions.add(typeConfigDesc); } } if (getConfigDescriptionURI(channelUID) != null) { ConfigDescription channelConfigDesc = configDescRegistry .getConfigDescription(getConfigDescriptionURI(channelUID)); if (channelConfigDesc != null) { configDescriptions.add(channelConfigDesc); } } if (configDescriptions.isEmpty()) { return properties; } return ConfigUtil.normalizeTypes(properties, configDescriptions); }
private @Nullable URI getChannelConfigDescriptionURI(URI uri) { String stringUID = uri.getSchemeSpecificPart(); if (uri.getFragment() != null) { stringUID = stringUID + "#" + uri.getFragment(); } ChannelUID channelUID = new ChannelUID(stringUID); ThingUID thingUID = channelUID.getThingUID(); // First, get the thing so we get access to the channel type via the channel Thing thing = thingRegistry.get(thingUID); if (thing == null) { return null; } Channel channel = thing.getChannel(channelUID.getId()); if (channel == null) { return null; } ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (channelType == null) { return null; } // Get the config description URI for this channel type URI configURI = channelType.getConfigDescriptionURI(); return configURI; }
private void applyDefaultConfiguration(final Configuration configuration, final ChannelType channelType) { if (((this.configDescriptionRegistry != null) && (configuration != null))) { URI _configDescriptionURI = channelType.getConfigDescriptionURI(); boolean _tripleNotEquals = (_configDescriptionURI != null); if (_tripleNotEquals) { final ConfigDescription configDescription = this.configDescriptionRegistry.getConfigDescription(channelType.getConfigDescriptionURI()); if ((configDescription != null)) { final Function1<ConfigDescriptionParameter, Boolean> _function = (ConfigDescriptionParameter it) -> { return Boolean.valueOf(((it.getDefault() != null) && (configuration.get(it.getName()) == null))); }; final Consumer<ConfigDescriptionParameter> _function_1 = (ConfigDescriptionParameter it) -> { final Object value = this.getDefaultValueAsCorrectType(it.getType(), it.getDefault()); if ((value != null)) { configuration.put(it.getName(), value); } }; IterableExtensions.<ConfigDescriptionParameter>filter(configDescription.getParameters(), _function).forEach(_function_1); } } } }
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 ChannelType createLocalizedChannelType(Bundle bundle, ChannelType channelType, Locale locale) { LocalizedChannelTypeKey localizedChannelTypeKey = getLocalizedChannelTypeKey(channelType.getUID(), locale); ChannelType cachedEntry = localizedChannelTypeCache.get(localizedChannelTypeKey); if (cachedEntry != null) { return cachedEntry; } if (this.thingTypeI18nUtil != null) { ChannelTypeUID channelTypeUID = channelType.getUID(); String label = this.thingTypeI18nUtil.getChannelLabel(bundle, channelTypeUID, channelType.getLabel(), locale); String description = this.thingTypeI18nUtil.getChannelDescription(bundle, channelTypeUID, channelType.getDescription(), locale); StateDescription state = createLocalizedChannelState(bundle, channelType, channelTypeUID, locale); ChannelType localizedChannelType = new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), label, description, channelType.getCategory(), channelType.getTags(), state, channelType.getConfigDescriptionURI()); localizedChannelTypeCache.put(localizedChannelTypeKey, localizedChannelType); return localizedChannelType; } return channelType; }
private boolean isInitializable(Thing thing, ThingType thingType) { if (!isComplete(thingType, thing.getUID(), tt -> tt.getConfigDescriptionURI(), thing.getConfiguration())) { return false; } for (Channel channel : thing.getChannels()) { ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID()); if (!isComplete(channelType, channel.getUID(), ct -> ct.getConfigDescriptionURI(), channel.getConfiguration())) { return false; } } return true; }
.state(channelTypeUID, label == null ? defaultLabel : label, channelType.getItemType()) .isAdvanced(channelType.isAdvanced()).withCategory(channelType.getCategory()) .withConfigDescriptionURI(channelType.getConfigDescriptionURI()).withTags(channelType.getTags()) .withStateDescription(state).withAutoUpdatePolicy(channelType.getAutoUpdatePolicy()); if (description != null) { .trigger(channelTypeUID, label == null ? defaultLabel : label) .isAdvanced(channelType.isAdvanced()).withCategory(channelType.getCategory()) .withConfigDescriptionURI(channelType.getConfigDescriptionURI()).withTags(channelType.getTags()) .withEventDescription(channelType.getEvent()); if (description != null) { channelType.getKind(), label == null ? defaultLabel : label, description, channelType.getCategory(), channelType.getTags(), channelType.getState(), channelType.getEvent(), channelType.getConfigDescriptionURI(), channelType.getAutoUpdatePolicy());
URI channelConfigDescriptionURI = channelType.getConfigDescriptionURI(); if (configDescriptionRegistry != null && channelConfigDescriptionURI != null) { ConfigDescription cd = configDescriptionRegistry.getConfigDescription(channelConfigDescriptionURI);