Search in sources :

Example 1 with AutoUpdatePolicy

use of org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy 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 AutoUpdatePolicy

use of org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy in project smarthome by eclipse.

the class ChannelConverter method unmarshalType.

protected ChannelXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException {
    String id = attributes.get("id");
    String typeId = attributes.get("typeId");
    String label = (String) nodeIterator.nextValue("label", false);
    String description = (String) nodeIterator.nextValue("description", false);
    List<NodeValue> properties = getProperties(nodeIterator);
    AutoUpdatePolicy autoUpdatePolicy = readAutoUpdatePolicy(nodeIterator);
    ChannelXmlResult channelXmlResult = new ChannelXmlResult(id, typeId, label, description, properties, autoUpdatePolicy);
    return channelXmlResult;
}
Also used : NodeValue(org.eclipse.smarthome.config.xml.util.NodeValue) AutoUpdatePolicy(org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy)

Example 3 with AutoUpdatePolicy

use of org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy in project smarthome by eclipse.

the class AutoUpdateManager method shouldAutoUpdate.

private Recommendation shouldAutoUpdate(String itemName) {
    Recommendation ret = Recommendation.REQUIRED;
    List<ChannelUID> linkedChannelUIDs = new ArrayList<>();
    for (ItemChannelLink link : itemChannelLinkRegistry.getAll()) {
        if (link.getItemName().equals(itemName)) {
            linkedChannelUIDs.add(link.getLinkedUID());
        }
    }
    // check if there is any channel ONLINE
    List<ChannelUID> onlineChannelUIDs = new ArrayList<>();
    for (ChannelUID channelUID : linkedChannelUIDs) {
        Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (// 
        thing == null || // 
        thing.getChannel(channelUID.getId()) == null || // 
        thing.getHandler() == null || // 
        !ThingStatus.ONLINE.equals(thing.getStatus())) {
            continue;
        }
        onlineChannelUIDs.add(channelUID);
    }
    if (!linkedChannelUIDs.isEmpty() && onlineChannelUIDs.isEmpty()) {
        // none of the linked channels is able to process the command
        return Recommendation.REVERT;
    }
    for (ChannelUID channelUID : onlineChannelUIDs) {
        Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing == null) {
            continue;
        }
        AutoUpdatePolicy policy = AutoUpdatePolicy.DEFAULT;
        Channel channel = thing.getChannel(channelUID.getId());
        if (channel != null) {
            AutoUpdatePolicy channelpolicy = channel.getAutoUpdatePolicy();
            if (channelpolicy != null) {
                policy = channelpolicy;
            } else {
                ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
                if (channelType != null && channelType.getAutoUpdatePolicy() != null) {
                    policy = channelType.getAutoUpdatePolicy();
                }
            }
        }
        switch(policy) {
            case VETO:
                ret = Recommendation.DONT;
                break;
            case DEFAULT:
                if (ret == Recommendation.REQUIRED || ret == Recommendation.RECOMMENDED) {
                    ret = Recommendation.OPTIMISTIC;
                }
                break;
            case RECOMMEND:
                if (ret == Recommendation.REQUIRED) {
                    ret = Recommendation.RECOMMENDED;
                }
                break;
        }
    }
    return ret;
}
Also used : AutoUpdatePolicy(org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ChannelType(org.eclipse.smarthome.core.thing.type.ChannelType) Thing(org.eclipse.smarthome.core.thing.Thing)

Aggregations

AutoUpdatePolicy (org.eclipse.smarthome.core.thing.type.AutoUpdatePolicy)3 ChannelType (org.eclipse.smarthome.core.thing.type.ChannelType)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 NodeValue (org.eclipse.smarthome.config.xml.util.NodeValue)1 Channel (org.eclipse.smarthome.core.thing.Channel)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1 Thing (org.eclipse.smarthome.core.thing.Thing)1 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)1 ChannelKind (org.eclipse.smarthome.core.thing.type.ChannelKind)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 EventDescription (org.eclipse.smarthome.core.types.EventDescription)1 StateDescription (org.eclipse.smarthome.core.types.StateDescription)1