Search in sources :

Example 56 with BindingConfigParseException

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

the class WithingsGenericBindingProvider method processBindingConfiguration.

@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] configElements = bindingConfig.split(":");
    String accountId = null;
    MeasureType measureType = null;
    if (configElements.length == 1) {
        measureType = MeasureType.valueOf(configElements[0].toUpperCase());
    } else if (configElements.length == 2) {
        accountId = configElements[0];
        measureType = MeasureType.valueOf(configElements[1].toUpperCase());
    } else {
        throw new BindingConfigParseException("Unknown Binding configuration '{}'. The Binding " + "configuration should consists of either one or two elements.");
    }
    if (measureType == null) {
        throw new BindingConfigParseException("Could not convert string '" + bindingConfig + "' to according measure type.");
    }
    WithingsBindingConfig config = new WithingsBindingConfig(accountId, measureType);
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) MeasureType(org.openhab.binding.withings.internal.model.MeasureType) WithingsBindingConfig(org.openhab.binding.withings.WithingsBindingConfig)

Example 57 with BindingConfigParseException

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

the class XbmcGenericBindingProvider method parseOutgoingBindingConfig.

private XbmcBindingConfig parseOutgoingBindingConfig(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 xbmcInstance = matcher.group(1);
    String property = matcher.group(2);
    return new XbmcBindingConfig(xbmcInstance, property, false, true);
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 58 with BindingConfigParseException

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

the class XbmcGenericBindingProvider method parseIncomingBindingConfig.

private XbmcBindingConfig parseIncomingBindingConfig(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 xbmcInstance = matcher.group(1);
    String property = matcher.group(2);
    return new XbmcBindingConfig(xbmcInstance, property, true, false);
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 59 with BindingConfigParseException

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

the class GPIOGenericBindingProvider method processBindingConfiguration.

@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    /* Not sure when must be called, other bindings seems to call it at the beginning */
    super.processBindingConfiguration(context, item, bindingConfig);
    GPIOPinBindingConfig config = new GPIOPinBindingConfig();
    /* Configuration string should be in the form "pin:NUMBER [debounse:NUMBER] [activelow:yes|no]" */
    String[] properties = bindingConfig.split(" ");
    if (properties.length > 3) {
        logger.error("Wrong number of arguments (" + properties.length + ") in configuration string '" + bindingConfig + "'");
        throw new BindingConfigParseException("Wrong number of agruments (" + properties.length + ") in configuration string '" + bindingConfig + "'");
    }
    for (String property : properties) {
        String[] keyValueStructure = property.split(":");
        if (keyValueStructure.length != 2) {
            logger.error("Incorrect key:value structure (" + property + ") in configuration string '" + bindingConfig + "'");
            throw new BindingConfigParseException("Incorrect key:value structure (" + property + ") in configuration string '" + bindingConfig + "'");
        }
        String key = keyValueStructure[0];
        String value = keyValueStructure[1];
        if (key.compareToIgnoreCase("pin") == 0) {
            try {
                config.pinNumber = Integer.parseInt(value);
                if (config.pinNumber < 0) {
                    logger.error("Unsupported, negative value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
                    throw new BindingConfigParseException("Unsupported, negative value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
                }
            } catch (NumberFormatException e) {
                logger.error("Unsupported, not numeric value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported, not numeric value for pin number (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else if (key.compareToIgnoreCase("force") == 0) {
            config.pinForce = false;
            if (value.compareToIgnoreCase("yes") == 0 || value.compareToIgnoreCase("true") == 0) {
                config.pinForce = true;
            } else if (value.compareToIgnoreCase("no") != 0 && value.compareToIgnoreCase("false") != 0) {
                logger.error("Unsupported value for force (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported value for force (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else if (key.compareToIgnoreCase("debounce") == 0) {
            try {
                config.debounceInterval = Long.parseLong(value);
                if (config.debounceInterval < 0) {
                    logger.error("Unsupported, negative value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
                    throw new BindingConfigParseException("Unsupported, negative value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
                }
            } catch (NumberFormatException e) {
                logger.error("Unsupported, not numeric value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported, not numeric value for debounce (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else if (key.compareToIgnoreCase("activelow") == 0) {
            if (value.compareToIgnoreCase("yes") == 0) {
                config.activeLow = GPIOPin.ACTIVELOW_ENABLED;
            } else if (value.compareToIgnoreCase("no") != 0) {
                logger.error("Unsupported value for activelow (" + value + ") in configuration string '" + bindingConfig + "'");
                throw new BindingConfigParseException("Unsupported value for activelow (" + value + ") in configuration string '" + bindingConfig + "'");
            }
        } else {
            logger.error("Unsupported key (" + key + ") in configuration string '" + bindingConfig + "'");
            throw new BindingConfigParseException("Unsupported key (" + key + ") in configuration string '" + bindingConfig + "'");
        }
    }
    /* Pin number wasn't configured */
    if (config.pinNumber == GPIOBindingProvider.PINNUMBER_UNDEFINED) {
        logger.error("Mandatory parameter (pin) is missing in configuration string '" + bindingConfig + "'");
        throw new BindingConfigParseException("Mandatory parameter (pin) is missing in configuration string '" + bindingConfig + "'");
    }
    if (item instanceof ContactItem) {
        config.direction = GPIOPin.DIRECTION_IN;
    } else {
        /* Item type 'Switch' */
        config.direction = GPIOPin.DIRECTION_OUT;
    }
    addBindingConfig(item, config);
}
Also used : ContactItem(org.openhab.core.library.items.ContactItem) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 60 with BindingConfigParseException

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

the class HarmonyHubGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    Matcher m = bindingPattern.matcher(bindingConfig);
    logger.debug("matching {} against {}", bindingConfig, bindingPattern);
    if (m.find()) {
        HarmonyHubBindingDirection direction = HarmonyHubBindingDirection.getHarmonyHubBindingDirection(m.group(1));
        String qualifier = m.group(3);
        HarmonyHubBindingType type = HarmonyHubBindingType.getHarmonyHubBindingType(m.group(4));
        String param1 = null;
        String param2 = null;
        if (m.group(6) != null) {
            String[] params = m.group(6).split(":");
            if (params.length > 0) {
                param1 = params[0];
            }
            if (params.length > 1) {
                param2 = params[1];
            }
        }
        logger.debug("processBindingConfiguration parsed result q:{} t:{} p1:{} p2:{}", qualifier, type, param1, param2);
        if (direction == null) {
            throw new BindingConfigParseException("Unknown direction " + m.group(1));
        }
        if (type == null) {
            throw new BindingConfigParseException("Unknown action " + m.group(3));
        }
        if (!direction.equals(type.getDirection()) && type.getDirection() != HarmonyHubBindingDirection.BOTH) {
            throw new BindingConfigParseException("wrong direction for action");
        }
        HarmonyHubBindingConfig config = new HarmonyHubBindingConfig(type, qualifier, type.getLabel(), param1, param2, item.getClass());
        addBindingConfig(item, config);
        super.processBindingConfiguration(context, item, bindingConfig);
    } else {
        throw new BindingConfigParseException("Config string did not match pattern { harmonyhub=\"<binding>[ (qualifier:)<binding> ...]\" }");
    }
}
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