use of org.eclipse.smarthome.binding.homematic.internal.type.MetadataUtils.OptionsBuilder 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