Search in sources :

Example 1 with BindingConfigParseException

use of org.eclipse.smarthome.model.item.BindingConfigParseException in project smarthome by eclipse.

the class GenericItemChannelLinkProvider method createItemChannelLink.

private void createItemChannelLink(String context, String itemName, String channelUID, Configuration configuration) throws BindingConfigParseException {
    ChannelUID channelUIDObject = null;
    try {
        channelUIDObject = new ChannelUID(channelUID);
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException(e.getMessage());
    }
    ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUIDObject, configuration);
    Set<String> itemNames = contextMap.get(context);
    if (itemNames == null) {
        itemNames = new HashSet<>();
        contextMap.put(context, itemNames);
    }
    itemNames.add(itemName);
    if (previousItemNames != null) {
        previousItemNames.remove(itemName);
    }
    Set<ItemChannelLink> links = itemChannelLinkMap.get(itemName);
    if (links == null) {
        itemChannelLinkMap.put(itemName, links = new HashSet<>());
    }
    if (!links.contains(itemChannelLink)) {
        links.add(itemChannelLink);
        notifyListenersAboutAddedElement(itemChannelLink);
    } else {
        notifyListenersAboutUpdatedElement(itemChannelLink, itemChannelLink);
    }
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) HashSet(java.util.HashSet)

Example 2 with BindingConfigParseException

use of org.eclipse.smarthome.model.item.BindingConfigParseException in project smarthome by eclipse.

the class GenericItemProvider method internalDispatchBindings.

private void internalDispatchBindings(BindingConfigReader reader, String modelName, Item item, EList<ModelBinding> bindings) {
    for (ModelBinding binding : bindings) {
        String bindingType = binding.getType();
        String config = binding.getConfiguration();
        Configuration configuration = new Configuration();
        binding.getProperties().forEach(p -> configuration.put(p.getKey(), p.getValue()));
        BindingConfigReader localReader = reader;
        if (reader == null) {
            logger.trace("Given binding config reader is null > query cache to find appropriate reader!");
            localReader = bindingConfigReaders.get(bindingType);
        } else {
            if (!localReader.getBindingType().equals(binding.getType())) {
                logger.trace("The Readers' binding type '{}' and the Bindings' type '{}' doesn't match > continue processing next binding.", localReader.getBindingType(), binding.getType());
                continue;
            } else {
                logger.debug("Start processing binding configuration of Item '{}' with '{}' reader.", item, localReader.getClass().getSimpleName());
            }
        }
        if (localReader != null) {
            try {
                localReader.validateItemType(item.getType(), config);
                localReader.processBindingConfiguration(modelName, item.getType(), item.getName(), config, configuration);
            } catch (BindingConfigParseException e) {
                logger.error("Binding configuration of type '{}' of item '{}' could not be parsed correctly.", bindingType, item.getName(), e);
            } catch (Exception e) {
                // Catch badly behaving binding exceptions and continue processing
                logger.error("Binding configuration of type '{}' of item '{}' could not be parsed correctly.", bindingType, item.getName(), e);
            }
        } else {
            logger.trace("Couldn't find config reader for binding type '{}' > " + "parsing binding configuration of Item '{}' aborted!", bindingType, item);
        }
    }
}
Also used : ModelBinding(org.eclipse.smarthome.model.items.ModelBinding) Configuration(org.eclipse.smarthome.config.core.Configuration) BindingConfigReader(org.eclipse.smarthome.model.item.BindingConfigReader) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException)

Aggregations

BindingConfigParseException (org.eclipse.smarthome.model.item.BindingConfigParseException)2 HashSet (java.util.HashSet)1 Configuration (org.eclipse.smarthome.config.core.Configuration)1 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)1 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)1 BindingConfigReader (org.eclipse.smarthome.model.item.BindingConfigReader)1 ModelBinding (org.eclipse.smarthome.model.items.ModelBinding)1