Search in sources :

Example 46 with BindingConfigParseException

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

the class BenqProjectorGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    BenqProjectorBindingConfig config = new BenqProjectorBindingConfig();
    if (bindingConfig.equalsIgnoreCase("power")) {
        config.mode = BenqProjectorItemMode.POWER;
    } else if (bindingConfig.equalsIgnoreCase("mute")) {
        config.mode = BenqProjectorItemMode.MUTE;
    } else if (bindingConfig.equalsIgnoreCase("volume")) {
        config.mode = BenqProjectorItemMode.VOLUME;
    } else if (bindingConfig.equalsIgnoreCase("lamp_hours")) {
        config.mode = BenqProjectorItemMode.LAMP_HOURS;
    } else if (bindingConfig.equalsIgnoreCase("source_number")) {
        config.mode = BenqProjectorItemMode.SOURCE_NUMBER;
    } else if (bindingConfig.equalsIgnoreCase("source_string")) {
        config.mode = BenqProjectorItemMode.SOURCE_STRING;
    } else {
        throw new BindingConfigParseException("Unable to parse '" + bindingConfig + "' to create a valid item binding.");
    }
    logger.debug("Adding " + item.getName() + " as " + config.mode);
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 47 with BindingConfigParseException

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

the class AnelGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    if (bindingConfig == null || bindingConfig.trim().isEmpty()) {
        // empty binding - nothing to do
        return;
    }
    final String[] segments = bindingConfig.trim().split(":");
    if (segments.length != 2) {
        throw new BindingConfigParseException("Invalid binding format '" + bindingConfig + "', expected: '<anelId>:<property>'");
    }
    final String deviceId = segments[0];
    final String commandType = segments[1];
    try {
        AnelCommandType.validateBinding(commandType, item.getClass());
        final AnelCommandType cmdType = AnelCommandType.getCommandType(commandType);
        // if command type was validated successfully, add binding config
        addBindingConfig(item, new AnelBindingConfig(item.getClass(), cmdType, deviceId));
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException("'" + commandType + "' is not a valid Anel property");
    } catch (InvalidClassException e) {
        throw new BindingConfigParseException("Invalid class for Anel property '" + commandType + "'");
    }
}
Also used : InvalidClassException(java.io.InvalidClassException) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 48 with BindingConfigParseException

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

the class InsteonPLMGenericBindingProvider method processBindingConfiguration.

/**
     * Inherited from AbstractGenericBindingProvider.
     * Processes InsteonPLM binding configuration string.
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] parts = parseConfigString(bindingConfig);
    if (parts.length != 3) {
        throw new BindingConfigParseException("item config must have addr:prodKey#feature format");
    }
    InsteonAddress addr = new InsteonAddress(parts[0]);
    String[] params = parts[2].split(",");
    String feature = params[0];
    HashMap<String, String> args = new HashMap<String, String>();
    for (int i = 1; i < params.length; i++) {
        String[] kv = params[i].split("=");
        if (kv.length == 2) {
            args.put(kv[0], kv[1]);
        } else {
            logger.error("parameter {} does not have format a=b", params[i]);
        }
    }
    InsteonPLMBindingConfig config = new InsteonPLMBindingConfig(item.getName(), addr, feature, parts[1], args);
    addBindingConfig(item, config);
    logger.trace("processing item \"{}\" read from .items file with cfg string {}", item.getName(), bindingConfig);
    items.put(item.getName(), item);
}
Also used : HashMap(java.util.HashMap) InsteonAddress(org.openhab.binding.insteonplm.internal.device.InsteonAddress) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 49 with BindingConfigParseException

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

the class OceanicGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    if (bindingConfig != null) {
        OceanicBindingConfig config = new OceanicBindingConfig();
        String valueSelectorString = null;
        String pollingIntervalString = null;
        String[] configParts = bindingConfig.trim().split(":");
        if (configParts.length != 3) {
            throw new BindingConfigParseException("RME binding must contain three parts separated by ':'");
        }
        config.serialPort = configParts[0].trim();
        valueSelectorString = configParts[1].trim();
        pollingIntervalString = configParts[2].trim();
        try {
            OceanicValueSelector.validateBinding(valueSelectorString, item);
            config.valueSelector = valueSelectorString;
            config.pollingInterval = Integer.parseInt(pollingIntervalString);
            addBindingConfig(item, config);
        } catch (IllegalArgumentException e1) {
            throw new BindingConfigParseException("Invalid value selector '" + valueSelectorString + "'!");
        } catch (InvalidClassException e1) {
            throw new BindingConfigParseException("Invalid item type for value selector '" + valueSelectorString + "'!");
        }
    } else {
        logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
    }
}
Also used : InvalidClassException(java.io.InvalidClassException) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 50 with BindingConfigParseException

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

the class OctollerGenricBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    String[] configParts = bindingConfig.trim().split("#");
    if (configParts.length != 2) {
        throw new BindingConfigParseException("Two parameters needed (Host#Block)");
    }
    // Right now a gateway must be given!
    String[] hostParts = configParts[0].trim().split("@");
    if (hostParts.length != 2) {
        throw new BindingConfigParseException("Host paramter must contain device and gateway (deviceHost@gatewayHost)");
    }
    OctollerBindingConfig config = new OctollerBindingConfig();
    config.DeviceHost = hostParts[0].trim();
    config.GatewayHost = hostParts[1].trim();
    // Check for BlockName
    if (configParts[1].length() > 2 && configParts[1].startsWith("'") && configParts[1].endsWith("'")) {
        config.BlockName = configParts[1].substring(1, configParts[1].length() - 1).trim();
    } else {
        try {
            config.BlockID = Integer.parseInt(configParts[1]);
        } catch (Exception ex) {
            throw new BindingConfigParseException("Block parameter must be nummeric or the block name in single quotation marks");
        }
    }
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) 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