Search in sources :

Example 76 with BindingConfigParseException

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

the class ClassicParser method parseAddress.

@Override
public String parseAddress(String... addressParts) throws BindingConfigParseException {
    char group = addressParts[0].charAt(0);
    int subAddress = 0;
    try {
        subAddress = Integer.parseInt(addressParts[1]);
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException("Sub address is not a number. Configured subaddress: " + addressParts[1]);
    }
    return getGroupAddress(group) + getSubAddress(subAddress) + "0F";
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 77 with BindingConfigParseException

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

the class FLSParser method parseAddress.

@Override
public String parseAddress(String... addressParts) throws BindingConfigParseException {
    String group = addressParts[0];
    int subAddress = 0;
    try {
        subAddress = Integer.parseInt(addressParts[1]);
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException("Sub address is not a number. Configured subaddress: " + addressParts[1]);
    }
    return getGroupAddress(group) + getSubAddress(subAddress) + "00";
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 78 with BindingConfigParseException

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

the class FLSParser method getGroupAddress.

private String getGroupAddress(String group) throws BindingConfigParseException {
    StringBuffer addressBuffer = new StringBuffer(4);
    addressBuffer.append("FFFF");
    if ("I".equalsIgnoreCase(group)) {
        addressBuffer.setCharAt(0, '0');
    } else if ("II".equalsIgnoreCase(group)) {
        addressBuffer.setCharAt(1, '0');
    } else if ("III".equalsIgnoreCase(group)) {
        addressBuffer.setCharAt(2, '0');
    } else if ("IV".equalsIgnoreCase(group)) {
        addressBuffer.setCharAt(3, '0');
    } else {
        throw new BindingConfigParseException("Unknown roman number given: " + group);
    }
    return addressBuffer.toString();
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 79 with BindingConfigParseException

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

the class HttpGenericBindingProvider method parseInBindingConfig.

/**
     * Parses a http-in configuration by using the regular expression
     * <code>(.*?):(\\d*):(.*)</code>. Where the groups should contain the
     * following content:
     * <ul>
     * <li>1 - url</li>
     * <li>2 - refresh interval</li>
     * <li>3 - the transformation rule</li>
     * </ul>
     *
     * @param item
     *
     * @param bindingConfig the config string to parse
     * @param config
     * @return the filled {@link HttpBindingConfig}
     *
     * @throws BindingConfigParseException if the regular expression doesn't match
     *             the given <code>bindingConfig</code>
     */
protected HttpBindingConfig parseInBindingConfig(Item item, String bindingConfig, HttpBindingConfig config) throws BindingConfigParseException {
    Matcher matcher = IN_BINDING_PATTERN.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't represent a valid in-binding-configuration. A valid configuration is matched by the RegExp '" + IN_BINDING_PATTERN + "'");
    }
    matcher.reset();
    HttpBindingConfigElement configElement;
    while (matcher.find()) {
        configElement = new HttpBindingConfigElement();
        configElement.url = matcher.group(1).replaceAll("\\\\\"", "");
        configElement.headers = parseHttpHeaders(matcher.group(2));
        configElement.refreshInterval = Integer.valueOf(matcher.group(3)).intValue();
        configElement.transformation = matcher.group(4).replaceAll("\\\\\"", "\"");
        config.put(IN_BINDING_KEY, configElement);
    }
    return config;
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 80 with BindingConfigParseException

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

the class HttpGenericBindingProvider method parseBindingConfig.

/**
     * Delegates parsing the <code>bindingConfig</code> with respect to the
     * first character (<code>&lt;</code> or <code>&gt;</code>) to the
     * specialized parsing methods
     *
     * @param item
     * @param bindingConfig
     *
     * @throws BindingConfigParseException
     */
protected HttpBindingConfig parseBindingConfig(Item item, String bindingConfig) throws BindingConfigParseException {
    HttpBindingConfig config = new HttpBindingConfig(item);
    Matcher matcher = BASE_CONFIG_PATTERN.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't contain a valid binding configuration");
    }
    matcher.reset();
    while (matcher.find()) {
        String direction = matcher.group(1);
        String bindingConfigPart = matcher.group(2);
        if (direction.equals("<")) {
            config = parseInBindingConfig(item, bindingConfigPart, config);
        } else if (direction.equals(">")) {
            config = parseOutBindingConfig(item, bindingConfigPart, config);
        } else {
            throw new BindingConfigParseException("Unknown command given! Configuration must start with '<' or '>' ");
        }
    }
    return config;
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

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