Search in sources :

Example 1 with ChannelKind

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;
}
Also used : CommandDescription(org.eclipse.smarthome.core.types.CommandDescription) ChannelKind(org.eclipse.smarthome.core.thing.type.ChannelKind) URI(java.net.URI) StateChannelTypeBuilder(org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder) AutoUpdatePolicy(org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) EventDescription(org.eclipse.smarthome.core.types.EventDescription) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) StateDescription(org.eclipse.smarthome.core.types.StateDescription)

Example 2 with ChannelKind

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;
}
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

ChannelKind (org.eclipse.smarthome.core.thing.type.ChannelKind)2 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)2 EventDescription (org.eclipse.smarthome.core.types.EventDescription)2 StateDescription (org.eclipse.smarthome.core.types.StateDescription)2 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 OptionsBuilder (org.eclipse.smarthome.binding.homematic.internal.type.MetadataUtils.OptionsBuilder)1 AutoUpdatePolicy (org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy)1 ChannelTypeUID (org.eclipse.smarthome.core.thing.type.ChannelTypeUID)1 StateChannelTypeBuilder (org.eclipse.smarthome.core.thing.type.StateChannelTypeBuilder)1 CommandDescription (org.eclipse.smarthome.core.types.CommandDescription)1 EventOption (org.eclipse.smarthome.core.types.EventOption)1 StateOption (org.eclipse.smarthome.core.types.StateOption)1