public ChannelType createLocalizedChannelType(Bundle bundle, ChannelType channelType, @Nullable Locale locale) { ChannelTypeUID channelTypeUID = channelType.getUID(); String defaultLabel = channelType.getLabel(); String label = thingTypeI18nUtil.getChannelLabel(bundle, channelTypeUID, defaultLabel, locale); String description = thingTypeI18nUtil.getChannelDescription(bundle, channelTypeUID, channelType.getDescription(), locale); switch (channelType.getKind()) { case STATE: StateDescription state = createLocalizedStateDescription(bundle, channelType.getState(), channelTypeUID, locale); .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) { stateBuilder.withDescription(description); TriggerChannelTypeBuilder triggerBuilder = ChannelTypeBuilder .trigger(channelTypeUID, label == null ? defaultLabel : label) .isAdvanced(channelType.isAdvanced()).withCategory(channelType.getCategory()) .withConfigDescriptionURI(channelType.getConfigDescriptionURI()).withTags(channelType.getTags()) .withEventDescription(channelType.getEvent()); if (description != null) { triggerBuilder.withDescription(description); return new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), channelType.getKind(), label == null ? defaultLabel : label, description, channelType.getCategory(), channelType.getTags(), channelType.getState(),
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; }
@Nullable @Override public ProfileTypeUID getSuggestedProfileTypeUID(@Nullable ChannelType channelType, @Nullable String itemType) { if (channelType == null) { return null; } switch (channelType.getKind()) { case STATE: return SystemProfiles.DEFAULT; case TRIGGER: if (DefaultSystemChannelTypeProvider.SYSTEM_RAWBUTTON.getUID().equals(channelType.getUID())) { if (CoreItemFactory.SWITCH.equalsIgnoreCase(itemType)) { return SystemProfiles.RAWBUTTON_TOGGLE_SWITCH; } } else if (DefaultSystemChannelTypeProvider.SYSTEM_RAWROCKER.getUID().equals(channelType.getUID())) { if (CoreItemFactory.SWITCH.equalsIgnoreCase(itemType)) { return SystemProfiles.RAWROCKER_ON_OFF; } else if (CoreItemFactory.DIMMER.equalsIgnoreCase(itemType)) { return SystemProfiles.RAWROCKER_DIMMER; } else if (CoreItemFactory.PLAYER.equalsIgnoreCase(itemType)) { return SystemProfiles.RAWROCKER_PLAY_PAUSE; } } break; default: throw new IllegalArgumentException("Unsupported channel kind: " + channelType.getKind()); } return null; }
static ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelType channelType, ConfigDescriptionRegistry configDescriptionRegistry) { ChannelBuilder channelBuilder = ChannelBuilder.create(channelUID, channelType.getItemType()) // .withType(channelType.getUID()) // .withDefaultTags(channelType.getTags()) // .withKind(channelType.getKind()) // .withLabel(channelType.getLabel()) // .withAutoUpdatePolicy(channelType.getAutoUpdatePolicy()); String description = channelType.getDescription(); if (description != null) { channelBuilder = channelBuilder.withDescription(description); URI channelConfigDescriptionURI = channelType.getConfigDescriptionURI(); if (configDescriptionRegistry != null && channelConfigDescriptionURI != null) { ConfigDescription cd = configDescriptionRegistry.getConfigDescription(channelConfigDescriptionURI);
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 void removeCachedChannelTypes(ChannelType channelType) { for (Iterator<Entry<LocalizedChannelTypeKey, ChannelType>> iterator = this.localizedChannelTypeCache.entrySet() .iterator(); iterator.hasNext();) { Entry<LocalizedChannelTypeKey, ChannelType> entry = iterator.next(); if (entry.getKey().uid.equals(channelType.getUID())) { iterator.remove(); } } }
final ChannelType resolvedChannelType = this.getChannelType(channelTypeUID); if ((resolvedChannelType != null)) { itemType = resolvedChannelType.getItemType(); parsedKind = resolvedChannelType.getKind(); if ((label == null)) { label = resolvedChannelType.getLabel(); autoUpdatePolicy = resolvedChannelType.getAutoUpdatePolicy(); this.applyDefaultConfiguration(configuration, resolvedChannelType); } else { String _id = it.getId(); ChannelUID _channelUID = new ChannelUID(thingTypeUID, thingUID, _id); Channel _build = ChannelBuilder.create(_channelUID, channelType.getItemType()).withType(it.getChannelTypeUID()).withAutoUpdatePolicy(channelType.getAutoUpdatePolicy()).build(); channels.add(_build); } else {
.createLocalizedChannelType(bundle, channelType, locale); if (channelLabel == null) { channelLabel = localizedChannelType.getLabel(); channelDescription = localizedChannelType.getDescription();
ChannelType channelType = thingTypeRegistry.getChannelType(channel, locale); if (channelType != null) { stateDescription = channelType.getState(); if ((channelType.getItemType() != null) && ((stateDescription == null) || (stateDescription.getPattern() == null))) { String pattern = null; if (channelType.getItemType().equalsIgnoreCase(CoreItemFactory.STRING)) { pattern = "%s"; } else if (channelType.getItemType().startsWith(CoreItemFactory.NUMBER)) { pattern = "%.0f";
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 boolean stateProfileMatchesProfileType(ProfileType profileType, ChannelType channelType) { if (profileType instanceof StateProfileType) { StateProfileType stateProfileType = (StateProfileType) profileType; if (stateProfileType.getSupportedItemTypesOfChannel().size() == 0) { return true; } Collection<String> supportedItemTypesOfChannelOnProfileType = stateProfileType .getSupportedItemTypesOfChannel(); if (supportedItemTypesOfChannelOnProfileType.contains(ItemUtil.getMainItemType(channelType.getItemType())) || supportedItemTypesOfChannelOnProfileType.contains(channelType.getItemType())) { return true; } } return false; }
@Override public ChannelType build() { return new ChannelType(channelTypeUID, advanced, null, ChannelKind.TRIGGER, label, description, category, tags.isEmpty() ? null : tags, null, eventDescription, configDescriptionURI); }
private String getLabel(Channel channel) { if (channel.getLabel() != null) { return channel.getLabel(); } else { final Locale locale = localeProvider.getLocale(); if (channel.getChannelTypeUID() != null) { final ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID(), locale); if (channelType != null) { return channelType.getLabel(); } } } return null; }
return Response.status(Status.NOT_FOUND).build(); if (channelType.getKind() != ChannelKind.TRIGGER) { return Response.noContent().build();
private String getCategory(Channel channel) { if (channel.getChannelTypeUID() != null) { ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID(), localeProvider.getLocale()); if (channelType != null) { return channelType.getCategory(); } } return 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 boolean triggerProfileMatchesProfileType(ProfileType profileType, ChannelType channelType) { if (profileType instanceof TriggerProfileType) { TriggerProfileType triggerProfileType = (TriggerProfileType) profileType; if (triggerProfileType.getSupportedChannelTypeUIDs().size() == 0) { return true; } if (triggerProfileType.getSupportedChannelTypeUIDs().contains(channelType.getUID())) { return true; } } return false; }
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 boolean channelTypeDefinesDimension(@Nullable ChannelTypeUID channelTypeUID) { if (channelTypeUID == null) { return false; } ChannelType channelType = channelTypeRegistry.getChannelType(channelTypeUID); return channelType != null && getDimension(channelType.getItemType()) != null; }