Search in sources :

Example 1 with EventOption

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;
}
Also used : NodeIterator(org.openhab.core.config.xml.util.NodeIterator) NodeList(org.openhab.core.config.xml.util.NodeList) EventDescription(org.openhab.core.types.EventDescription) EventOption(org.openhab.core.types.EventOption)

Example 2 with EventOption

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

Aggregations

EventDescription (org.openhab.core.types.EventDescription)2 EventOption (org.openhab.core.types.EventOption)2 BigDecimal (java.math.BigDecimal)1 OptionsBuilder (org.openhab.binding.homematic.internal.type.MetadataUtils.OptionsBuilder)1 NodeIterator (org.openhab.core.config.xml.util.NodeIterator)1 NodeList (org.openhab.core.config.xml.util.NodeList)1 ChannelType (org.openhab.core.thing.type.ChannelType)1 ChannelTypeBuilder (org.openhab.core.thing.type.ChannelTypeBuilder)1 StateDescriptionFragmentBuilder (org.openhab.core.types.StateDescriptionFragmentBuilder)1 StateOption (org.openhab.core.types.StateOption)1