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(); } } }
@Override public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) { Collection<Entry<Bundle, List<ChannelType>>> channelTypesList = this.bundleChannelTypesMap.entrySet(); if (channelTypesList != null) { for (Entry<Bundle, List<ChannelType>> channelTypes : channelTypesList) { for (ChannelType channelType : channelTypes.getValue()) { if (channelType.getUID().equals(channelTypeUID)) { return createLocalizedChannelType(channelTypes.getKey(), channelType, locale); } } } } else { } 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 ChannelType createLocalizedChannelType(Bundle bundle, ChannelType channelType, Locale locale) { LocalizedChannelTypeKey localizedChannelTypeKey = getLocalizedChannelTypeKey(channelType.getUID(), locale); ChannelType cachedEntry = localizedChannelTypeCache.get(localizedChannelTypeKey); if (cachedEntry != null) { return cachedEntry; } ChannelType localizedChannelType = localize(bundle, channelType, locale); if (localizedChannelType != null) { localizedChannelTypeCache.put(localizedChannelTypeKey, localizedChannelType); return localizedChannelType; } else { return channelType; } }
channelMap.put(ZigBeeBindingConstants.CHANNEL_ELECTRICAL_RMSCURRENT, ZigBeeConverterMeasurementRmsCurrent.class); channelMap.put(DefaultSystemChannelTypeProvider.SYSTEM_BUTTON.getUID(), ZigBeeConverterGenericButton.class);
@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; }
@Override public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) { final Bundle bundle = bundleResolver.resolveBundle(DefaultSystemChannelTypeProvider.class); for (final ChannelType channelType : CHANNEL_TYPES) { if (channelTypeUID.equals(channelType.getUID())) { return createLocalizedChannelType(bundle, channelType, locale); } } return null; }
protected List<ChannelDefinition> toChannelDefinitions(List<ChannelXmlResult> channelTypeReferences, Map<String, ChannelType> channelTypes) throws ConversionException { List<ChannelDefinition> channelTypeDefinitions = null; if ((channelTypeReferences != null) && (channelTypeReferences.size() > 0)) { channelTypeDefinitions = new ArrayList<>(channelTypeReferences.size()); if (channelTypes != null) { for (ChannelXmlResult channelTypeReference : channelTypeReferences) { String id = channelTypeReference.getId(); String typeId = channelTypeReference.getTypeId(); String typeUID = String.format("%s:%s", this.channelGroupTypeUID.getBindingId(), typeId); ChannelType channelType = channelTypes.get(typeUID); if (channelType != null) { ChannelDefinition channelDefinition = new ChannelDefinition(id, channelType.getUID()); channelTypeDefinitions.add(channelDefinition); } else { throw new ConversionException("The channel type for '" + typeUID + "' is missing!"); } } } else { throw new ConversionException("Missing the definition of channel types!"); } } return channelTypeDefinitions; }
@Override public synchronized void addingFinished() { Map<String, ChannelType> channelTypes = new HashMap<>(10); // create channel types for (ChannelTypeXmlResult type : this.channelTypeRefs) { ChannelType channelType = type.toChannelType(); channelTypes.put(channelType.getUID().getAsString(), channelType); this.channelTypeProvider.addChannelType(this.bundle, channelType); } // create channel group types for (ChannelGroupTypeXmlResult type : this.channelGroupTypeRefs) { this.channelTypeProvider.addChannelGroupType(this.bundle, type.toChannelGroupType(channelTypes)); } // create thing and bridge types for (ThingTypeXmlResult type : this.thingTypeRefs) { this.thingTypeProvider.addThingType(this.bundle, type.toThingType()); } // release temporary cache this.thingTypeRefs.clear(); this.channelGroupTypeRefs.clear(); this.channelTypeRefs.clear(); }
@Override public synchronized void addingFinished() { Map<String, ChannelType> channelTypes = new HashMap<>(10); // create channel types for (ChannelTypeXmlResult type : this.channelTypeRefs) { ChannelType channelType = type.toChannelType(); channelTypes.put(channelType.getUID().getAsString(), channelType); this.channelTypeProvider.add(this.bundle, channelType); } // create channel group types for (ChannelGroupTypeXmlResult type : this.channelGroupTypeRefs) { this.channelGroupTypeProvider.add(this.bundle, type.toChannelGroupType()); } // create thing and bridge types for (ThingTypeXmlResult type : this.thingTypeRefs) { this.thingTypeProvider.add(this.bundle, type.toThingType()); } // release temporary cache this.thingTypeRefs.clear(); this.channelGroupTypeRefs.clear(); this.channelTypeRefs.clear(); }
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 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()); }
static ChannelBuilder createChannelBuilder(ChannelUID channelUID, ChannelType channelType, ConfigDescriptionRegistry configDescriptionRegistry) { .withType(channelType.getUID()) //
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);