Search in sources :

Example 1 with OptionsBuilder

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;
}
Also used : ChannelKind(org.eclipse.smarthome.core.thing.type.ChannelKind) StateOption(org.eclipse.smarthome.core.types.StateOption) OptionsBuilder(org.eclipse.smarthome.binding.homematic.internal.type.MetadataUtils.OptionsBuilder) BigDecimal(java.math.BigDecimal) EventOption(org.eclipse.smarthome.core.types.EventOption) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) EventDescription(org.eclipse.smarthome.core.types.EventDescription) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Aggregations

BigDecimal (java.math.BigDecimal)1 OptionsBuilder (org.eclipse.smarthome.binding.homematic.internal.type.MetadataUtils.OptionsBuilder)1 ChannelKind (org.eclipse.smarthome.core.thing.type.ChannelKind)1 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)1 EventDescription (org.eclipse.smarthome.core.types.EventDescription)1 EventOption (org.eclipse.smarthome.core.types.EventOption)1 StateDescription (org.eclipse.smarthome.core.types.StateDescription)1 StateOption (org.eclipse.smarthome.core.types.StateOption)1