Search in sources :

Example 1 with TriggerChannelTypeBuilder

use of org.eclipse.smarthome.core.thing.type.TriggerChannelTypeBuilder in project smarthome by eclipse.

the class ChannelTypeI18nLocalizationService method createLocalizedChannelType.

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);
            CommandDescription command = createLocalizedCommandDescription(bundle, channelType.getCommandDescription(), channelTypeUID, locale);
            StateChannelTypeBuilder stateBuilder = ChannelTypeBuilder.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()).withCommandDescription(command);
            if (description != null) {
                stateBuilder.withDescription(description);
            }
            return stateBuilder.build();
        case TRIGGER:
            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 triggerBuilder.build();
        default:
            return new ChannelType(channelTypeUID, channelType.isAdvanced(), channelType.getItemType(), channelType.getKind(), label == null ? defaultLabel : label, description, channelType.getCategory(), channelType.getTags(), channelType.getState(), channelType.getEvent(), channelType.getConfigDescriptionURI(), channelType.getAutoUpdatePolicy());
    }
}
Also used : TriggerChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.TriggerChannelTypeBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Aggregations

ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1 StateChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder)1 TriggerChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.TriggerChannelTypeBuilder)1 CommandDescription (org.eclipse.smarthome.core.types.CommandDescription)1 StateDescription (org.eclipse.smarthome.core.types.StateDescription)1