Search in sources :

Example 16 with BindingConfigParseException

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

the class KoubachiGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] configParts = bindingConfig.split(":");
    if (configParts.length < 3 || configParts.length > 4) {
        throw new BindingConfigParseException("A Koubachi binding configuration for a property must consist of three or four parts - please verify your *.items file");
    } else if (configParts[2].equals("action") && configParts.length != 4) {
        throw new BindingConfigParseException("A Koubachi binding configuration for an action  must consist of four parts - please verify your *.items file");
    }
    KoubachiBindingConfig config = new KoubachiBindingConfig();
    config.resourceType = KoubachiResourceType.valueOf(configParts[0].toUpperCase());
    config.resourceId = configParts[1];
    if (configParts.length == 3) {
        // this is a binding for a property
        config.propertyName = configParts[2];
    } else {
        // this is a binding for a care action
        config.actionType = configParts[3];
    }
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 17 with BindingConfigParseException

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

the class SmarthomaticGenericBindingProvider method parseConfig.

private SmarthomaticBindingConfig parseConfig(Item item, String bindingConfig) throws BindingConfigParseException {
    SmarthomaticBindingConfig config = new SmarthomaticBindingConfig();
    Matcher matcher = CONFIG_PATTERN.matcher(bindingConfig);
    if (!matcher.matches()) {
        throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
    }
    bindingConfig = matcher.group(1);
    config.setItemName(item.getName());
    config.setItem(item);
    matcher = TRANSFORMATION_PATTERN.matcher(bindingConfig);
    if (matcher.matches()) {
        bindingConfig = matcher.group(1);
        String transformation = matcher.group(2);
        config.getConfigParams().put("transformation", transformation);
    }
    // parse bindingconfig here ...
    StringTokenizer confItems = new StringTokenizer(bindingConfig, ",");
    while (confItems.hasMoreTokens()) {
        String[] token = confItems.nextToken().split("=");
        String key = token[0];
        String value = token[1];
        config.getConfigParams().put(key, value);
        // Strip all whitespaces from token[0]
        key = key.replaceAll("\\s", "");
        if ("deviceId".equals(key)) {
            config.setDeviceId(value.replaceAll("\\s", ""));
        } else if ("messageGroupId".equals(key)) {
            config.setMessageGroupId(value.replaceAll("\\s", ""));
        } else if ("messageId".equals(key)) {
            config.setMessageId(value.replaceAll("\\s", ""));
        } else if ("messagePart".equals(key)) {
            config.setMessagePartId(value.replaceAll("\\s", ""));
        } else if ("messageItem".equals(key)) {
            config.setMessageItemId(value.replaceAll("\\s", ""));
        }
    }
    return config;
}
Also used : StringTokenizer(java.util.StringTokenizer) Matcher(java.util.regex.Matcher) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 18 with BindingConfigParseException

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

the class SappGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    logger.debug("processing binding configuration for context {}", context);
    super.processBindingConfiguration(context, item, bindingConfig);
    if (bindingConfig != null) {
        if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
            SappBindingConfigSwitchItem sappBindingConfigSwitchItem = new SappBindingConfigSwitchItem(item, bindingConfig);
            addBindingConfig(item, sappBindingConfigSwitchItem);
        } else if (item instanceof ContactItem) {
            SappBindingConfigContactItem sappBindingConfigContactItem = new SappBindingConfigContactItem(item, bindingConfig);
            addBindingConfig(item, sappBindingConfigContactItem);
        } else if (item instanceof NumberItem) {
            SappBindingConfigNumberItem sappBindingConfigNumberItem = new SappBindingConfigNumberItem(item, bindingConfig);
            addBindingConfig(item, sappBindingConfigNumberItem);
        } else if (item instanceof RollershutterItem) {
            SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = new SappBindingConfigRollershutterItem(item, bindingConfig);
            addBindingConfig(item, sappBindingConfigRollershutterItem);
        } else if (item instanceof DimmerItem) {
            SappBindingConfigDimmerItem sappBindingConfigDimmerItem = new SappBindingConfigDimmerItem(item, bindingConfig);
            addBindingConfig(item, sappBindingConfigDimmerItem);
        } else {
            throw new BindingConfigParseException("item '" + item.getName() + "' is of type '" + item.getClass().getSimpleName() + " - not yet implemented, please check your *.items configuration");
        }
    } else {
        logger.warn("bindingConfig is NULL (item={}) -> processing bindingConfig aborted!", item);
    }
}
Also used : SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) NumberItem(org.openhab.core.library.items.NumberItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) ContactItem(org.openhab.core.library.items.ContactItem) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) DimmerItem(org.openhab.core.library.items.DimmerItem) SappBindingConfigDimmerItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem) SappBindingConfigNumberItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem) RollershutterItem(org.openhab.core.library.items.RollershutterItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem) SappBindingConfigRollershutterItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem) SappBindingConfigContactItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem) SwitchItem(org.openhab.core.library.items.SwitchItem) SappBindingConfigSwitchItem(org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem)

Example 19 with BindingConfigParseException

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

the class SappBindingConfigDimmerItem method parseSappAddressStatus.

private SappAddressDimmer parseSappAddressStatus(String bindingStringAddress) throws BindingConfigParseException {
    String pnmasId;
    SappAddressType addressType;
    int address;
    String subAddress;
    int increment;
    String[] bindingAddress = bindingStringAddress.split(":");
    if (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));
    }
    // increment
    try {
        increment = Integer.parseInt(bindingAddress[4]);
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    return new SappAddressDimmer(pnmasId, addressType, address, subAddress, 0, 100, increment);
}
Also used : SappAddressDimmer(org.openhab.binding.sapp.internal.model.SappAddressDimmer) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappAddressType(org.openhab.binding.sapp.internal.model.SappAddressType)

Example 20 with BindingConfigParseException

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

the class SappBindingConfigRollershutterItem method parseSappAddressStatus.

private SappAddressRollershutterStatus parseSappAddressStatus(String bindingStringAddress) throws BindingConfigParseException {
    String pnmasId;
    SappAddressType addressType;
    int address;
    String subAddress;
    int openValue;
    int closedValue;
    String[] bindingAddress = bindingStringAddress.split(":");
    if (bindingAddress.length != 4 && bindingAddress.length != 6) {
        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));
    }
    // openValue
    try {
        openValue = Integer.parseInt(bindingAddress[4]);
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    // closedValue
    try {
        closedValue = Integer.parseInt(bindingAddress[5]);
    } catch (NumberFormatException e) {
        throw new BindingConfigParseException(errorMessage(bindingStringAddress));
    }
    return new SappAddressRollershutterStatus(pnmasId, addressType, address, subAddress, openValue, closedValue);
}
Also used : SappAddressRollershutterStatus(org.openhab.binding.sapp.internal.model.SappAddressRollershutterStatus) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) SappAddressType(org.openhab.binding.sapp.internal.model.SappAddressType)

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