use of org.openhab.core.types.EventOption in project openhab-core by openhab.
the class EventDescriptionConverter method unmarshal.
@Override
public final Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
List<EventOption> eventOptions = null;
NodeList nodes = (NodeList) context.convertAnother(context, NodeList.class);
NodeIterator nodeIterator = new NodeIterator(nodes.getList());
NodeList optionNodes = (NodeList) nodeIterator.next();
if (optionNodes != null) {
eventOptions = toListOfEventOptions(optionNodes);
}
nodeIterator.assertEndOfType();
EventDescription eventDescription = new EventDescription(eventOptions);
return eventDescription;
}
use of org.openhab.core.types.EventOption in project openhab-addons by openhab.
the class HomematicTypeGeneratorImpl method createChannelType.
/**
* Creates the ChannelType for the given datapoint.
*/
public static 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);
}
});
}
StateDescriptionFragmentBuilder stateFragment = StateDescriptionFragmentBuilder.create();
if (dp.isNumberType()) {
BigDecimal min = MetadataUtils.createBigDecimal(dp.getMinValue());
BigDecimal max = MetadataUtils.createBigDecimal(dp.getMaxValue());
if (ITEM_TYPE_DIMMER.equals(itemType) && (max.compareTo(new BigDecimal("1.0")) == 0 || max.compareTo(new BigDecimal("1.01")) == 0)) {
// For dimmers with a max value of 1.01 or 1.0 the values must be corrected
min = MetadataUtils.createBigDecimal(0);
max = MetadataUtils.createBigDecimal(100);
}
stateFragment.withMinimum(min).withMaximum(max).withPattern(MetadataUtils.getStatePattern(dp)).withReadOnly(dp.isReadOnly());
} else {
stateFragment.withPattern(MetadataUtils.getStatePattern(dp)).withReadOnly(dp.isReadOnly());
}
if (options != null) {
stateFragment.withOptions(options);
}
ChannelTypeBuilder channelTypeBuilder;
EventDescription eventDescription = null;
if (dp.isTrigger()) {
eventDescription = new EventDescription(MetadataUtils.generateOptions(dp, new OptionsBuilder<EventOption>() {
@Override
public EventOption createOption(String value, String description) {
return new EventOption(value, description);
}
}));
channelTypeBuilder = ChannelTypeBuilder.trigger(channelTypeUID, label).withEventDescription(eventDescription);
} else {
channelTypeBuilder = ChannelTypeBuilder.state(channelTypeUID, label, itemType).withStateDescriptionFragment(stateFragment.build());
}
channelType = channelTypeBuilder.isAdvanced(!MetadataUtils.isStandard(dp)).withDescription(description).withCategory(category).withConfigDescriptionURI(configDescriptionUriChannel).build();
}
return channelType;
}
Aggregations