Search in sources :

Example 1 with StateChannelTypeBuilder

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

the class ChannelTypeConverter method unmarshalType.

@Override
protected ChannelTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    boolean advanced = readBoolean(attributes, "advanced", false);
    boolean system = readBoolean(attributes, "system", false);
    String uid = system ? XmlHelper.getSystemUID(super.getID(attributes)) : super.getUID(attributes, context);
    ChannelTypeUID channelTypeUID = new ChannelTypeUID(uid);
    String itemType = readItemType(nodeIterator);
    String kind = readKind(nodeIterator);
    String label = super.readLabel(nodeIterator);
    String description = super.readDescription(nodeIterator);
    String category = readCategory(nodeIterator);
    Set<String> tags = readTags(nodeIterator);
    StateDescription stateDescription = readStateDescription(nodeIterator);
    CommandDescription commandDescription = readCommandDescription(nodeIterator);
    EventDescription eventDescription = readEventDescription(nodeIterator);
    AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator);
    Object[] configDescriptionObjects = super.getConfigDescriptionObjects(nodeIterator);
    if (kind == null) {
        // Default for kind is 'state'
        kind = "state";
    }
    ChannelKind cKind = ChannelKind.parse(kind);
    URI configDescriptionURI = (URI) configDescriptionObjects[0];
    ChannelType channelType = null;
    if (cKind == ChannelKind.STATE) {
        StateChannelTypeBuilder builder = ChannelTypeBuilder.state(channelTypeUID, label, itemType).isAdvanced(advanced).withDescription(description).withCategory(category).withTags(tags).withConfigDescriptionURI(configDescriptionURI).withStateDescription(stateDescription).withAutoUpdatePolicy(autoUpdatePolicy).withCommandDescription(commandDescription);
        channelType = builder.build();
    } else if (cKind == ChannelKind.TRIGGER) {
        channelType = ChannelTypeBuilder.trigger(channelTypeUID, label).isAdvanced(advanced).withDescription(description).withCategory(category).withTags(tags).withConfigDescriptionURI(configDescriptionURI).withEventDescription(eventDescription).build();
    }
    ChannelTypeXmlResult channelTypeXmlResult = new ChannelTypeXmlResult(channelType, (ConfigDescription) configDescriptionObjects[1], system);
    return channelTypeXmlResult;
}
Also used : CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) ChannelKind(org.eclipse.smarthome.core.thing.type.ChannelKind) URI(java.net.URI) StateChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder) AutoUpdatePolicy(org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) EventDescription(org.eclipse.smarthome.core.types.EventDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 2 with StateChannelTypeBuilder

use of org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder 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)2 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)2 StateChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder)2 CommandDescription (org.eclipse.smarthome.core.types.CommandDescription)2 StateDescription (org.eclipse.smarthome.core.types.StateDescription)2 URI (java.net.URI)1 AutoUpdatePolicy (org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy)1 ChannelKind (org.eclipse.smarthome.core.thing.type.ChannelKind)1 TriggerChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.TriggerChannelTypeBuilder)1 EventDescription (org.eclipse.smarthome.core.types.EventDescription)1