use of org.eclipse.smarthome.core.thing.type.ThingTypeBuilder in project smarthome by eclipse.
the class ThingTypeI18nLocalizationService method createLocalizedThingType.
public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, Locale locale) {
final String label = this.thingTypeI18nUtil.getLabel(bundle, thingType.getUID(), thingType.getLabel(), locale);
final String description = this.thingTypeI18nUtil.getDescription(bundle, thingType.getUID(), thingType.getDescription(), locale);
final List<ChannelDefinition> localizedChannelDefinitions = new ArrayList<>(thingType.getChannelDefinitions().size());
for (final ChannelDefinition channelDefinition : thingType.getChannelDefinitions()) {
String channelLabel = this.thingTypeI18nUtil.getChannelLabel(bundle, thingType.getUID(), channelDefinition, channelDefinition.getLabel(), locale);
String channelDescription = this.thingTypeI18nUtil.getChannelDescription(bundle, thingType.getUID(), channelDefinition, channelDefinition.getDescription(), locale);
if (channelLabel == null || channelDescription == null) {
ChannelType channelType = channelTypeRegistry.getChannelType(channelDefinition.getChannelTypeUID(), locale);
if (channelType != null) {
if (channelLabel == null) {
channelLabel = this.thingTypeI18nUtil.getChannelLabel(bundle, channelType.getUID(), channelType.getLabel(), locale);
}
if (channelDescription == null) {
channelDescription = this.thingTypeI18nUtil.getChannelDescription(bundle, channelType.getUID(), channelType.getDescription(), locale);
}
}
}
localizedChannelDefinitions.add(new ChannelDefinition(channelDefinition.getId(), channelDefinition.getChannelTypeUID(), channelDefinition.getProperties(), channelLabel, channelDescription));
}
final List<ChannelGroupDefinition> localizedChannelGroupDefinitions = new ArrayList<>(thingType.getChannelGroupDefinitions().size());
for (final ChannelGroupDefinition channelGroupDefinition : thingType.getChannelGroupDefinitions()) {
String channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, thingType.getUID(), channelGroupDefinition, channelGroupDefinition.getLabel(), locale);
String channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, thingType.getUID(), channelGroupDefinition, channelGroupDefinition.getDescription(), locale);
if (channelGroupLabel == null || channelGroupDescription == null) {
ChannelGroupType channelGroupType = channelTypeRegistry.getChannelGroupType(channelGroupDefinition.getTypeUID(), locale);
if (channelGroupType != null) {
if (channelGroupLabel == null) {
channelGroupLabel = this.thingTypeI18nUtil.getChannelGroupLabel(bundle, channelGroupType.getUID(), channelGroupType.getLabel(), locale);
}
if (channelGroupDescription == null) {
channelGroupDescription = this.thingTypeI18nUtil.getChannelGroupDescription(bundle, channelGroupType.getUID(), channelGroupType.getDescription(), locale);
}
}
}
localizedChannelGroupDefinitions.add(new ChannelGroupDefinition(channelGroupDefinition.getId(), channelGroupDefinition.getTypeUID(), channelGroupLabel, channelGroupDescription));
}
ThingTypeBuilder builder = ThingTypeBuilder.instance(thingType).withLabel(label).withDescription(description).withChannelDefinitions(localizedChannelDefinitions).withChannelGroupDefinitions(localizedChannelGroupDefinitions);
if (thingType instanceof BridgeType) {
return builder.buildBridge();
}
return builder.build();
}
use of org.eclipse.smarthome.core.thing.type.ThingTypeBuilder in project smarthome by eclipse.
the class DsDeviceThingTypeProvider method getThingType.
@Override
public ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale) {
try {
SupportedThingTypes supportedThingType = SupportedThingTypes.valueOf(thingTypeUID.getId());
ThingTypeBuilder thingTypeBuilder = ThingTypeBuilder.instance(thingTypeUID, getLabelText(thingTypeUID.getId(), locale)).withSupportedBridgeTypeUIDs(Arrays.asList(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE.getAsString())).withDescription(getDescText(thingTypeUID.getId(), locale));
try {
if (supportedThingType.havePowerSensors) {
thingTypeBuilder.withConfigDescriptionURI(new URI(DEVICE_WITH_POWER_SENSORS));
} else {
thingTypeBuilder.withConfigDescriptionURI(new URI(DEVICE_WITHOUT_POWER_SENSORS));
}
} catch (URISyntaxException e) {
logger.debug("An URISyntaxException occurred: ", e);
}
if (SupportedThingTypes.GR.equals(supportedThingType)) {
thingTypeBuilder.withChannelDefinitions(Arrays.asList(new ChannelDefinition(DsChannelTypeProvider.SHADE, new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.SHADE))));
}
if (SupportedThingTypes.circuit.equals(supportedThingType)) {
List<ChannelDefinition> channelDefinitions = new ArrayList<ChannelDefinition>(3);
for (MeteringTypeEnum meteringType : MeteringTypeEnum.values()) {
channelDefinitions.add(new ChannelDefinition(DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false), new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false))));
}
thingTypeBuilder.withChannelDefinitions(channelDefinitions);
}
return thingTypeBuilder.build();
} catch (IllegalArgumentException e) {
// ignore
}
return null;
}
Aggregations