Search in sources :

Example 31 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 32 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 33 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)

Example 34 with BindingConfigParseException

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

the class NetatmoGenericBindingProvider 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);
    final NetatmoBindingConfig config = new NetatmoBindingConfig();
    final String[] configParts = bindingConfig.split("#");
    // Default value for backward compatibility
    String deviceType = NETATMO_WEATHER;
    if (configParts.length > 0) {
        final String[] sPart = configParts[0].split("=");
        switch(sPart.length) {
            case 1:
                break;
            case 2:
                deviceType = sPart[0];
                if (!(NETATMO_CAMERA.equals(deviceType) || NETATMO_WEATHER.equals(deviceType))) {
                    throw new BindingConfigParseException("The choosen name of the devicetype for the netatmo binding configuration is unknown - please verify your *.items file");
                }
                configParts[0] = sPart[1];
                break;
            default:
                throw new BindingConfigParseException("A netatmo binding configuration must start with the devicetype followed by '=', without weatherstation is default - please verify your *.items file");
        }
    }
    if (NETATMO_WEATHER.equals(deviceType)) {
        config.bWeather = true;
        String measureTypeString;
        switch(configParts.length) {
            case 2:
                config.deviceId = configParts[0].toLowerCase();
                measureTypeString = configParts[1];
                break;
            case 3:
                config.deviceId = configParts[0].toLowerCase();
                config.moduleId = configParts[1].toLowerCase();
                measureTypeString = configParts[2];
                break;
            case 4:
                config.userid = configParts[0];
                config.deviceId = configParts[1].toLowerCase();
                config.moduleId = configParts[2].toLowerCase();
                measureTypeString = configParts[3];
                break;
            default:
                throw new BindingConfigParseException("A Netatmo weather station binding configuration must consist of two, three or four parts - please verify your *.items file");
        }
        /*
             * use a ',' when including scale so that it does not break backwards
             * compatibility with case 4 above.
             */
        final String[] measureTypeParts = measureTypeString.split(",");
        switch(measureTypeParts.length) {
            case 1:
                config.measureType = NetatmoMeasureType.fromString(measureTypeParts[0]);
                config.netatmoScale = config.measureType.getDefaultScale();
                break;
            case 2:
                config.measureType = NetatmoMeasureType.fromString(measureTypeParts[0]);
                config.netatmoScale = NetatmoScale.fromString(measureTypeParts[1]);
                break;
            default:
                throw new BindingConfigParseException("The last part of the Netatmo binding configuration must be 'type' or 'type,scale'" + " - please verify your *.items file");
        }
    } else if (NETATMO_CAMERA.equals(deviceType)) {
        config.bCamera = true;
        switch(configParts.length) {
            case 2:
                config.homeId = configParts[0];
                config.attribute = NetatmoCameraAttributes.fromString(configParts[1]);
                break;
            case 3:
                config.homeId = configParts[0];
                // Check Format (Mac Adress with : is a camera, else it's a person)
                String sTmp = configParts[1];
                final String[] sItem = sTmp.split(":");
                if (sItem.length == 6) {
                    config.cameraId = sTmp;
                } else {
                    config.personId = sTmp;
                }
                config.attribute = NetatmoCameraAttributes.fromString(configParts[2]);
                break;
            default:
                throw new BindingConfigParseException("A Netatmo camera binding configuration must consist of two or three parts - please verify your *.items file");
        }
    } else {
        throw new BindingConfigParseException("The choosen name of the devicetype for the netatmo binding configuration is unknown - please verify your *.items file");
    }
    logger.debug("Adding binding: {}", config);
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 35 with BindingConfigParseException

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

the class NikobusGenericBindingProvider method parseItem.

/**
     * Parse an item from the provided configuration string.
     * 
     * @param item.getName()
     *            item name
     * @param config
     *            string to parse
     * @return parsed item
     * @throws BindingConfigParseException
     *             if no item could be created
     */
private AbstractNikobusItemConfig parseItem(Item item, String config) throws BindingConfigParseException {
    if (config == null || config.trim().length() == 0) {
        throw new BindingConfigParseException("Invalid config for item " + item.getName());
    }
    if (config.matches(BUTTON_CONFIG_PATTERN)) {
        return new Button(item.getName(), config);
    }
    if (config.matches(MODULE_CHANNEL_PATTERN)) {
        String address = config.split(":")[0];
        int channelNum = Integer.parseInt(config.split(":")[1]);
        int group = channelNum > 6 ? 2 : 1;
        String moduleKey = address + "-" + group;
        NikobusModule module = getModule(moduleKey);
        if (module == null) {
            log.trace("Creating channel group {}", moduleKey);
            module = new ModuleChannelGroup(address, group);
            allModules.add(module);
            modules.put(moduleKey, module);
        }
        return ((ModuleChannelGroup) module).addChannel(item.getName(), channelNum, item.getAcceptedCommandTypes());
    }
    throw new BindingConfigParseException("Could not determine item type from config: " + config);
}
Also used : Button(org.openhab.binding.nikobus.internal.config.Button) ModuleChannelGroup(org.openhab.binding.nikobus.internal.config.ModuleChannelGroup) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) NikobusModule(org.openhab.binding.nikobus.internal.core.NikobusModule)

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