Search in sources :

Example 26 with BindingConfigParseException

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

the class EcobeeGenericBindingProvider 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() != 2) {
        throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
    }
    String property = matcher.group(2);
    logger.trace("validateItemType called with property={}", property);
}
Also used : Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 27 with BindingConfigParseException

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

the class EnergenieGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    try {
        if (bindingConfig != null) {
            String[] configParts = bindingConfig.split(";");
            if (configParts.length < 2 || configParts.length > 2) {
                throw new BindingConfigParseException("energenie binding configuration must have 2 parts");
            }
            String itemType = item.toString();
            if (item instanceof SwitchItem) {
                if ((configParts[1].equals("1")) || (configParts[1].equals("2")) || (configParts[1].equals("3")) || (configParts[1].equals("4"))) {
                    BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
                    addBindingConfig(item, energenieBindingConfig);
                } else {
                    throw new BindingConfigParseException("Your SwitchItem configuration does not contain channelNumbers");
                }
            } else if (item instanceof NumberItem) {
                ChannelTypeDef channelType = ChannelTypeDef.valueOf(configParts[1].trim());
                if (channelType != null) {
                    BindingConfig energenieBindingConfig = new EnergenieBindingConfig(configParts[0], configParts[1], itemType);
                    addBindingConfig(item, energenieBindingConfig);
                } else {
                    throw new BindingConfigParseException("Your NumberItem configuration does not contain channelTypes");
                }
            }
        } else {
            logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.warn("bindingConfig is invalid (item=" + item + ") -> processing bindingConfig aborted!");
    }
}
Also used : NumberItem(org.openhab.core.library.items.NumberItem) BindingConfig(org.openhab.core.binding.BindingConfig) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SwitchItem(org.openhab.core.library.items.SwitchItem) ChannelTypeDef(org.openhab.binding.energenie.internal.EnergenieBindingConfig.ChannelTypeDef)

Example 28 with BindingConfigParseException

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

the class Enigma2GenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     * 
     * [deviceId:command:value]
     * 
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    if (bindingConfig == null || item == null) {
        logger.error("invalid input for processBindingConfiguration, item={}, bindingConfig={}", item, bindingConfig);
        return;
    }
    /*
         * remove unnecessary chars
         */
    String strippedBindingConfig = bindingConfig.replace("[", "").replace("]", "").trim();
    /*
         * get elements
         */
    String[] elements = strippedBindingConfig.split(":");
    Enigma2BindingConfig config = null;
    /*
         * check for valid command
         */
    Enigma2Command cmdId = null;
    try {
        cmdId = Enigma2Command.valueOf(elements[1].toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException("Unknown command: " + elements[1]);
    }
    if (elements.length == 2) {
        config = new Enigma2BindingConfig(item, elements[0], cmdId, null);
    } else if (elements.length == 3) {
        config = new Enigma2BindingConfig(item, elements[0], cmdId, elements[2]);
    } else {
        throw new BindingConfigParseException("Configuration must have at at least 2 or 3 elements separated by ':'");
    }
    logger.debug("Found \"{}\" binding config for deviceId \"{}\". Command is \"{}\" and value is \"{}\"", elements[0], elements[1], elements.length > 2 ? elements[2] : "-");
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 29 with BindingConfigParseException

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

the class LgtvGenericBindingProvider method parseBindingConfig.

protected void parseBindingConfig(String bindingConfigs, LgtvBindingConfig config) throws BindingConfigParseException {
    String bindingConfig = StringUtils.substringBefore(bindingConfigs, ",");
    String bindingConfigTail = StringUtils.substringAfter(bindingConfigs, ",");
    String[] configParts = bindingConfig.trim().split(":");
    if (configParts.length != 3) {
        throw new BindingConfigParseException("Lgtv binding must contain three parts separated by ':'");
    }
    String command = StringUtils.trim(configParts[0]);
    String deviceId = StringUtils.trim(configParts[1]);
    String deviceCommand = StringUtils.trim(configParts[2]);
    if (!deviceCommand.startsWith(ADVANCED_COMMAND_KEY)) {
        try {
            LgTvCommand.valueOf(deviceCommand);
        } catch (Exception e) {
            throw new BindingConfigParseException("Unregonized command '" + deviceCommand + "'");
        }
    }
    // if there are more commands to parse do that recursively ...
    if (StringUtils.isNotBlank(bindingConfigTail)) {
        parseBindingConfig(bindingConfigTail, config);
    }
    config.put(command, deviceId + ":" + deviceCommand);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 30 with BindingConfigParseException

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

the class LcnGenericBindingProvider method processBindingConfiguration.

/**
     * Item processing for the LCN bindings.
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    Matcher matcher = PATTERN_BINDING_GENERAL.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException(bindingConfig + "' contains no valid binding!");
    }
    matcher.reset();
    LcnBindingConfig bc = new LcnBindingConfig(item);
    while (matcher.find()) {
        String binding = matcher.group(1);
        if (binding != null && !binding.trim().isEmpty()) {
            String openHabCmd = null;
            String connId, lcnTarget;
            Matcher openHabMatcher = PATTERN_BINDING_WITH_OPENHAB.matcher(binding);
            Matcher pureMatcher = PATTERN_BINDING_PURE.matcher(binding);
            if (openHabMatcher.matches()) {
                openHabCmd = openHabMatcher.group(1);
                connId = openHabMatcher.group(2);
                lcnTarget = openHabMatcher.group(3);
            } else if (pureMatcher.matches()) {
                connId = pureMatcher.group(1);
                lcnTarget = pureMatcher.group(2);
            } else {
                throw new BindingConfigParseException("Invalid binding configuration for " + binding + "!");
            }
            String lcnShort = resolveMappings(lcnTarget, openHabCmd);
            if (lcnShort == null || lcnShort.equals(openHabCmd)) {
                lcnShort = lcnTarget;
            }
            Command cmd = openHabCmd == null ? TypeParser.parseCommand(new StringItem("").getAcceptedCommandTypes(), "") : openHabCmd.equals("%i") ? new StringType("%i") : TypeParser.parseCommand(item.getAcceptedCommandTypes(), openHabCmd);
            bc.add(new LcnBindingConfig.Mapping(cmd, connId, lcnShort));
        }
    }
    // Finished
    this.addBindingConfig(item, bc);
    for (LcnAddrMod addr : bc.getRelatedModules()) {
        HashSet<String> l = this.itemNamesByModulCache.get(addr);
        if (l == null) {
            l = new HashSet<String>();
            this.itemNamesByModulCache.put(addr, l);
        }
        l.add(item.getName());
    }
}
Also used : Matcher(java.util.regex.Matcher) Command(org.openhab.core.types.Command) StringType(org.openhab.core.library.types.StringType) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) StringItem(org.openhab.core.library.items.StringItem) LcnAddrMod(org.openhab.binding.lcn.common.LcnAddrMod)

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