Search in sources :

Example 1 with BindingConfigParseException

use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.

the class GC100IRGenericBindingProvider method parseBindingConfig.

/**
     * Parses the binding configuration and returns GC100BindingConfig instance.
     * 
     * @param item
     * @param bindingConfig
     * @return GC100BindingConfig instance
     * @throws BindingConfigParseException
     */
private GC100BindingConfig parseBindingConfig(Item item, String bindingConfig) throws BindingConfigParseException {
    Matcher matcher = CONFIG_PATTERN.matcher(bindingConfig);
    if (!matcher.matches())
        throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
    String gc100Instance = matcher.group(1);
    String module = matcher.group(2);
    String connector = matcher.group(3);
    String code = matcher.group(4);
    return new GC100BindingConfig(gc100Instance, Integer.parseInt(module), Integer.parseInt(connector), code);
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 2 with BindingConfigParseException

use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.

the class HDanywhereGenericBindingProvider method parseBindingConfig.

/**
     * Parses the configuration string and update the provided config
     * 
     * @param config
     * @param item
     * @param bindingConfig
     * @throws BindingConfigParseException
     */
private void parseBindingConfig(HDanywhereBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
    String host = null;
    int port = 0;
    int interval = 60;
    if (bindingConfig != null) {
        Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
        if (!statusMatcher.matches()) {
            throw new BindingConfigParseException("HDanywhere binding configuration must consist of either three [config=" + statusMatcher + "] parts");
        } else {
            host = statusMatcher.group(1);
            port = Integer.valueOf(statusMatcher.group(2));
            interval = Integer.valueOf(statusMatcher.group(3));
            HDanywhereBindingConfigElement newElement = new HDanywhereBindingConfigElement(host, port, interval);
            config.add(newElement);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 3 with BindingConfigParseException

use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.

the class HeatmiserGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    if (bindingConfig != null) {
        HeatmiserBindingConfig config = new HeatmiserBindingConfig();
        config.itemType = item.getClass();
        Matcher bindingMatcher = BINDING_PATTERN.matcher(bindingConfig);
        if (!bindingMatcher.matches()) {
            throw new BindingConfigParseException(getBindingType() + " binding configuration must consist of two parts [config=" + bindingMatcher + "]");
        } else {
            config.address = Integer.parseInt(bindingMatcher.group(1));
            config.function = Functions.valueOf(bindingMatcher.group(2));
            // Check the type for different functions
            switch(config.function) {
                case SETTEMP:
                case FROSTTEMP:
                case ROOMTEMP:
                case FLOORTEMP:
                    if (config.itemType != NumberItem.class && config.itemType != StringItem.class) {
                        logger.error("Only Number and String allowed for Heatmiser:{} function", config.function);
                        config = null;
                    }
                    break;
                case HOLDTIME:
                case HOLIDAYTIME:
                    if (config.itemType != SwitchItem.class && config.itemType != DateTimeItem.class) {
                        logger.error("Only Switch and DateTime allowed for Heatmiser:{} function", config.function);
                        config = null;
                    }
                    break;
                case HOLIDAYSET:
                    if (config.itemType != SwitchItem.class && config.itemType != NumberItem.class) {
                        logger.error("Only Switch and Number allowed for Heatmiser:{} function", config.function);
                        config = null;
                    }
                    break;
                case HOLDMODE:
                case HOLIDAYMODE:
                    if (config.itemType != SwitchItem.class) {
                        logger.error("Only Switch allowed for Heatmiser:{} function", config.function);
                        config = null;
                    }
                    break;
                case WATERSTATE:
                case HEATSTATE:
                case STATE:
                case ONOFF:
                    if (config.itemType != SwitchItem.class && config.itemType != StringItem.class) {
                        logger.error("Only Switch and String allowed for Heatmiser:{} function", config.function);
                        config = null;
                    }
                    break;
                default:
                    config = null;
                    logger.error("Unknown or unsupported Heatmiser function: {}", bindingConfig);
                    break;
            }
        }
        if (config != null) {
            addBindingConfig(item, config);
        }
    } else {
        logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) DateTimeItem(org.openhab.core.library.items.DateTimeItem) StringItem(org.openhab.core.library.items.StringItem) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 4 with BindingConfigParseException

use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.

the class NestGenericBindingProvider method validateItemType.

/**
     * {@inheritDoc}
     */
@Override
public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
    logger.trace("validateItemType called with bindingConfig={}", bindingConfig);
    Matcher matcher = CONFIG_PATTERN.matcher(bindingConfig);
    if (!matcher.matches() || matcher.groupCount() != 1) {
        throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
    }
    String property = matcher.group(1);
    logger.trace("validateItemType called with property={}", property);
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 5 with BindingConfigParseException

use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.

the class ProtocolGenericBindingProvider method parseBindingConfig.

/**
     * Parses the configuration string and update the provided config
     *
     * @param config - the Configuration that needs to be updated with the parsing results
     * @param item - the Item that this configuration is intented for
     * @param bindingConfig - the configuration string that will be parsed
     * @throws BindingConfigParseException
     */
private void parseBindingConfig(ProtocolBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
    String direction = null;
    Direction directionType = null;
    String commandAsString = null;
    String host = null;
    String port = null;
    String protocolCommand = null;
    if (bindingConfig != null) {
        Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig);
        Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
        if ((!actionMatcher.matches() && !statusMatcher.matches())) {
            throw new BindingConfigParseException(getBindingType() + " binding configuration must consist of four [config=" + statusMatcher + "] or five parts [config=" + actionMatcher + "]");
        } else {
            if (actionMatcher.matches()) {
                direction = actionMatcher.group(1);
                commandAsString = actionMatcher.group(2);
                host = actionMatcher.group(3);
                port = actionMatcher.group(4);
                protocolCommand = actionMatcher.group(5) != null ? actionMatcher.group(5) : actionMatcher.group(6);
            } else if (statusMatcher.matches()) {
                direction = statusMatcher.group(1);
                commandAsString = null;
                host = statusMatcher.group(2);
                port = statusMatcher.group(3);
                protocolCommand = statusMatcher.group(4) != null ? statusMatcher.group(4) : statusMatcher.group(5);
            }
            if (direction.equals(">")) {
                directionType = Direction.OUT;
            } else if (direction.equals("<")) {
                directionType = Direction.IN;
            }
            ProtocolBindingConfigElement newElement = new ProtocolBindingConfigElement(host, port, directionType, protocolCommand, item.getAcceptedDataTypes());
            Command command = null;
            if (commandAsString == null) {
                // for those configuration strings that are not really linked to a openHAB command we
                // create a dummy Command to be able to store the configuration information
                // I have choosen to do that with NumberItems
                NumberItem dummy = new NumberItem(Integer.toString(counter));
                command = createCommandFromString(dummy, Integer.toString(counter));
                counter++;
            } else {
                command = createCommandFromString(item, commandAsString);
            }
            config.put(command, newElement);
        }
    } else {
        return;
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) Matcher(java.util.regex.Matcher) Command(org.openhab.core.types.Command) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) Direction(org.openhab.binding.tcp.Direction)

Aggregations

BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)112 Matcher (java.util.regex.Matcher)37 Command (org.openhab.core.types.Command)11 NumberItem (org.openhab.core.library.items.NumberItem)9 SwitchItem (org.openhab.core.library.items.SwitchItem)9 SappAddressType (org.openhab.binding.sapp.internal.model.SappAddressType)7 InvalidClassException (java.io.InvalidClassException)6 HashMap (java.util.HashMap)4 ContactItem (org.openhab.core.library.items.ContactItem)4 S7Client (Moka7.S7Client)2 JSONParser (com.json.parsers.JSONParser)2 JsonParserFactory (com.json.parsers.JsonParserFactory)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 IllegalClassException (org.apache.commons.lang.IllegalClassException)2 BindingConfig (org.openhab.core.binding.BindingConfig)2 DimmerItem (org.openhab.core.library.items.DimmerItem)2 StringItem (org.openhab.core.library.items.StringItem)2 StringType (org.openhab.core.library.types.StringType)2 State (org.openhab.core.types.State)2