use of org.openhab.core.thing.type.ThingTypeBuilder in project openhab-addons by openhab.
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 ChannelDefinitionBuilder(DsChannelTypeProvider.SHADE, new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.SHADE)).build()));
}
if (SupportedThingTypes.circuit.equals(supportedThingType)) {
List<ChannelDefinition> channelDefinitions = new ArrayList<>(3);
for (MeteringTypeEnum meteringType : MeteringTypeEnum.values()) {
channelDefinitions.add(new ChannelDefinitionBuilder(DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false), new ChannelTypeUID(DigitalSTROMBindingConstants.BINDING_ID, DsChannelTypeProvider.getMeteringChannelID(meteringType, MeteringUnitsEnum.WH, false))).build());
}
thingTypeBuilder.withChannelDefinitions(channelDefinitions);
}
return thingTypeBuilder.build();
} catch (IllegalArgumentException e) {
// ignore
}
return null;
}
use of org.openhab.core.thing.type.ThingTypeBuilder in project openhab-addons by openhab.
the class MqttChannelTypeProvider method derive.
public ThingTypeBuilder derive(ThingTypeUID newTypeId, ThingTypeUID baseTypeId) {
ThingType baseType = typeRegistry.getThingType(baseTypeId);
ThingTypeBuilder result = ThingTypeBuilder.instance(newTypeId, baseType.getLabel()).withChannelGroupDefinitions(baseType.getChannelGroupDefinitions()).withChannelDefinitions(baseType.getChannelDefinitions()).withExtensibleChannelTypeIds(baseType.getExtensibleChannelTypeIds()).withSupportedBridgeTypeUIDs(baseType.getSupportedBridgeTypeUIDs()).withProperties(baseType.getProperties()).isListed(false);
String representationProperty = baseType.getRepresentationProperty();
if (representationProperty != null) {
result = result.withRepresentationProperty(representationProperty);
}
URI configDescriptionURI = baseType.getConfigDescriptionURI();
if (configDescriptionURI != null) {
result = result.withConfigDescriptionURI(configDescriptionURI);
}
String category = baseType.getCategory();
if (category != null) {
result = result.withCategory(category);
}
String description = baseType.getDescription();
if (description != null) {
result = result.withDescription(description);
}
return result;
}
use of org.openhab.core.thing.type.ThingTypeBuilder in project openhab-core by openhab.
the class ThingTypeI18nLocalizationService method createLocalizedThingType.
public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, @Nullable Locale locale) {
ThingTypeUID thingTypeUID = thingType.getUID();
String label = thingTypeI18nUtil.getLabel(bundle, thingTypeUID, thingType.getLabel(), locale);
String description = thingTypeI18nUtil.getDescription(bundle, thingTypeUID, thingType.getDescription(), locale);
List<ChannelDefinition> localizedChannelDefinitions = channelI18nUtil.createLocalizedChannelDefinitions(bundle, thingType.getChannelDefinitions(), channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, thingTypeUID, channelDefinition, channelDefinition.getLabel(), locale), channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, thingTypeUID, channelDefinition, channelDefinition.getDescription(), locale), locale);
List<ChannelGroupDefinition> localizedChannelGroupDefinitions = channelGroupI18nUtil.createLocalizedChannelGroupDefinitions(bundle, thingType.getChannelGroupDefinitions(), channelGroupDefinition -> thingTypeI18nUtil.getChannelGroupLabel(bundle, thingTypeUID, channelGroupDefinition, channelGroupDefinition.getLabel(), locale), channelGroupDefinition -> thingTypeI18nUtil.getChannelGroupDescription(bundle, thingTypeUID, channelGroupDefinition, channelGroupDefinition.getDescription(), locale), locale);
ThingTypeBuilder builder = ThingTypeBuilder.instance(thingType);
if (label != null) {
builder.withLabel(label);
}
if (description != null) {
builder.withDescription(description);
}
builder.withChannelDefinitions(localizedChannelDefinitions).withChannelGroupDefinitions(localizedChannelGroupDefinitions);
if (thingType instanceof BridgeType) {
return builder.buildBridge();
}
return builder.build();
}
Aggregations