use of org.eclipse.smarthome.core.thing.type.ChannelKind 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.ChannelKind in project smarthome by eclipse.
the class HomematicTypeGeneratorImpl method createChannelType.
/**
* Creates the ChannelType for the given datapoint.
*/
private ChannelType createChannelType(HmDatapoint dp, ChannelTypeUID channelTypeUID) {
ChannelType channelType;
if (dp.getName().equals(DATAPOINT_NAME_LOWBAT) || dp.getName().equals(DATAPOINT_NAME_LOWBAT_IP)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_LOW_BATTERY;
} else if (dp.getName().equals(VIRTUAL_DATAPOINT_NAME_SIGNAL_STRENGTH)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_SIGNAL_STRENGTH;
} else if (dp.getName().equals(VIRTUAL_DATAPOINT_NAME_BUTTON)) {
channelType = DefaultSystemChannelTypeProvider.SYSTEM_BUTTON;
} else {
String itemType = MetadataUtils.getItemType(dp);
String category = MetadataUtils.getCategory(dp, itemType);
String label = MetadataUtils.getLabel(dp);
String description = MetadataUtils.getDatapointDescription(dp);
List<StateOption> options = null;
if (dp.isEnumType()) {
options = MetadataUtils.generateOptions(dp, new OptionsBuilder<StateOption>() {
@Override
public StateOption createOption(String value, String description) {
return new StateOption(value, description);
}
});
}
StateDescription state = null;
if (dp.isNumberType()) {
BigDecimal min = MetadataUtils.createBigDecimal(dp.getMinValue());
BigDecimal max = MetadataUtils.createBigDecimal(dp.getMaxValue());
BigDecimal step = MetadataUtils.createBigDecimal(dp.getStep());
if (step == null) {
step = MetadataUtils.createBigDecimal(dp.isFloatType() ? new Float(0.1) : 1L);
}
state = new StateDescription(min, max, step, MetadataUtils.getStatePattern(dp), dp.isReadOnly(), options);
} else {
state = new StateDescription(null, null, null, MetadataUtils.getStatePattern(dp), dp.isReadOnly(), options);
}
ChannelKind channelKind = ChannelKind.STATE;
EventDescription eventDescription = null;
if (dp.isTrigger()) {
itemType = null;
channelKind = ChannelKind.TRIGGER;
eventDescription = new EventDescription(MetadataUtils.generateOptions(dp, new OptionsBuilder<EventOption>() {
@Override
public EventOption createOption(String value, String description) {
return new EventOption(value, description);
}
}));
}
channelType = new ChannelType(channelTypeUID, !MetadataUtils.isStandard(dp), itemType, channelKind, label, description, category, null, state, eventDescription, configDescriptionUriChannel);
}
return channelType;
}
Aggregations