Search in sources :

Example 1 with ThingTypeBuilder

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;
}
Also used : ChannelDefinitionBuilder(org.openhab.core.thing.type.ChannelDefinitionBuilder) ThingTypeBuilder(org.openhab.core.thing.type.ThingTypeBuilder) MeteringTypeEnum(org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with ThingTypeBuilder

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;
}
Also used : ThingTypeBuilder(org.openhab.core.thing.type.ThingTypeBuilder) ThingType(org.openhab.core.thing.type.ThingType) URI(java.net.URI)

Example 3 with ThingTypeBuilder

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();
}
Also used : ThingTypeBuilder(org.openhab.core.thing.type.ThingTypeBuilder) ChannelDefinition(org.openhab.core.thing.type.ChannelDefinition) ThingTypeUID(org.openhab.core.thing.ThingTypeUID) ChannelGroupDefinition(org.openhab.core.thing.type.ChannelGroupDefinition) BridgeType(org.openhab.core.thing.type.BridgeType)

Aggregations

ThingTypeBuilder (org.openhab.core.thing.type.ThingTypeBuilder)3 URI (java.net.URI)2 ChannelDefinition (org.openhab.core.thing.type.ChannelDefinition)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 MeteringTypeEnum (org.openhab.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.MeteringTypeEnum)1 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)1 BridgeType (org.openhab.core.thing.type.BridgeType)1 ChannelDefinitionBuilder (org.openhab.core.thing.type.ChannelDefinitionBuilder)1 ChannelGroupDefinition (org.openhab.core.thing.type.ChannelGroupDefinition)1 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)1 ThingType (org.openhab.core.thing.type.ThingType)1