Search in sources :

Example 21 with BindingConfigParseException

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

the class SappBindingConfigRollershutterItem method parseSappAddressControl.

private SappAddressRollershutterControl parseSappAddressControl(String bindingStringAddress) throws BindingConfigParseException {
    String pnmasId;
    SappAddressType addressType;
    int address;
    String subAddress;
    int activateValue;
    String[] bindingAddress = bindingStringAddress.split(":");
    if (bindingAddress.length != 4 && bindingAddress.length != 5) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // pnmasId
    pnmasId = bindingAddress[0];
    if (pnmasId.length() == 0) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // addressType
    addressType = SappAddressType.fromString(bindingAddress[1].toUpperCase());
    if (!validAddresses.keySet().contains(addressType)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // address
    try {
        address = Integer.parseInt(bindingAddress[2]);
        if (address < validAddresses.get(addressType).getLoRange() || address > validAddresses.get(addressType).getHiRange()) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // subaddress
    subAddress = bindingAddress[3].toUpperCase();
    if (!ArrayUtils.contains(validSubAddresses, subAddress)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // activateValue
    try {
        activateValue = Integer.parseInt(bindingAddress[4]);
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    return new SappAddressRollershutterControl(pnmasId, addressType, address, subAddress, activateValue);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappAddressRollershutterControl(org.openhab.binding.sapp.internal.model.SappAddressRollershutterControl) SappAddressType(org.openhab.binding.sapp.internal.model.SappAddressType)

Example 22 with BindingConfigParseException

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

the class SappBindingConfigSwitchItem method parseSappAddressStatus.

private SappAddressOnOffStatus parseSappAddressStatus(String bindingStringAddress) throws BindingConfigParseException {
    String pnmasId;
    SappAddressType addressType;
    int address;
    String subAddress;
    int onValue = 1;
    String[] bindingAddress = bindingStringAddress.split(":");
    if (bindingAddress.length != 4 && bindingAddress.length != 5) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // pnmasId
    pnmasId = bindingAddress[0];
    if (pnmasId.length() == 0) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // addressType
    addressType = SappAddressType.fromString(bindingAddress[1].toUpperCase());
    if (!validAddresses.keySet().contains(addressType)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // address
    try {
        address = Integer.parseInt(bindingAddress[2]);
        if (address < validAddresses.get(addressType).getLoRange() || address > validAddresses.get(addressType).getHiRange()) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // subaddress
    subAddress = bindingAddress[3].toUpperCase();
    if (!ArrayUtils.contains(validSubAddresses, subAddress)) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // onvalue, offvalue
    if (bindingAddress.length == 5) {
        try {
            onValue = Integer.parseInt(bindingAddress[4]);
        } catch (NumberFormatException e) {
            throw new BindingConfigParseException(errorMessage(bindingStringAddress));
        }
    }
    return new SappAddressOnOffStatus(pnmasId, addressType, address, subAddress, onValue);
}
Also used : SappAddressOnOffStatus(org.openhab.binding.sapp.internal.model.SappAddressOnOffStatus) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappAddressType(org.openhab.binding.sapp.internal.model.SappAddressType)

Example 23 with BindingConfigParseException

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

the class SallegraGenericBindingProvider 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 null input, item={}, bindingConfig={}", item, bindingConfig);
        return;
    }
    /*
         * remove unnecessary chars
         */
    String strippedBindingConfig = bindingConfig.replace("[", "").replace("]", "").trim();
    /*
         * get configpart
         */
    String[] configpart = strippedBindingConfig.split(":");
    SallegraBindingConfig config = null;
    /*
         * check for valid command
         */
    if (configpart.length == 3) {
        SallegraCommand cmdId = null;
        try {
            cmdId = SallegraCommand.valueOf(configpart[1].toUpperCase());
        } catch (IllegalArgumentException e) {
            throw new BindingConfigParseException("Unknown command: " + configpart[1]);
        }
        config = new SallegraBindingConfig(configpart[0], cmdId, configpart[2]);
        config.setItem(item.getName());
    } else {
        throw new BindingConfigParseException("Configuration must have at at least 2 or 3 configpart separated by ':'");
    }
    logger.debug("Found \"{}\" binding config for deviceId \"{}\". Command is \"{}\" and value is \"{}\"", configpart[0], configpart[1], configpart.length > 2 ? configpart[2] : "-");
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 24 with BindingConfigParseException

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

the class SamsungTvGenericBindingProvider method parseBindingConfig.

protected void parseBindingConfig(String bindingConfigs, SamsungTvBindingConfig 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("Samsung TV binding must contain three parts separated by ':'");
    }
    String command = StringUtils.trim(configParts[0]);
    String tvId = StringUtils.trim(configParts[1]);
    String tvCommand = StringUtils.trim(configParts[2]);
    Key key = Key.valueOf(tvCommand);
    if (key == null) {
        throw new BindingConfigParseException("Unregonized value '" + tvCommand + "'");
    }
    // if there are more commands to parse do that recursively ...
    if (StringUtils.isNotBlank(bindingConfigTail)) {
        parseBindingConfig(bindingConfigTail, config);
    }
    config.put(command, tvId + ":" + tvCommand);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) Key(de.quist.samy.remocon.Key)

Example 25 with BindingConfigParseException

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

the class EcobeeGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(final String context, final Item item, final String bindingConfig) throws BindingConfigParseException {
    logger.debug("Processing binding configuration: '{}'", bindingConfig);
    super.processBindingConfiguration(context, item, bindingConfig);
    boolean inBound = false;
    boolean outBound = false;
    if (bindingConfig.startsWith(IN_BOUND)) {
        inBound = true;
    } else if (bindingConfig.startsWith(OUT_BOUND)) {
        outBound = true;
    } else if (bindingConfig.startsWith(BIDIRECTIONAL)) {
        inBound = true;
        outBound = true;
    } else {
        throw new BindingConfigParseException("Item \"" + item.getName() + "\" does not start with " + IN_BOUND + ", " + OUT_BOUND + " or " + BIDIRECTIONAL + ".");
    }
    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 userid = null;
    String thermostatIdentifier = matcher.group(1);
    if (thermostatIdentifier.contains(".")) {
        String[] parts = thermostatIdentifier.split("\\.");
        userid = parts[0];
        thermostatIdentifier = parts[1];
    }
    if (inBound && !Selection.isThermostatIdentifier(thermostatIdentifier)) {
        throw new BindingConfigParseException("Only a single thermostat identifier is permitted in an in binding or bidirectional binding.");
    }
    String property = matcher.group(2);
    EcobeeBindingConfig config = new EcobeeBindingConfig(userid, thermostatIdentifier, property, inBound, outBound);
    addBindingConfig(item, 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