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;
}
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());
}
}
Aggregations