Search in sources :

Example 36 with BindingConfigParseException

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

the class TinkerforgeGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    // parse bindingconfig here ...
    if (bindingConfig == null) {
        logger.error("got bindingConfig null for item: {}", item.getName());
    } else {
        TinkerforgeBindingConfig config = new TinkerforgeBindingConfig();
        DeviceOptions deviceOptions = new DeviceOptions();
        String[] tokens = bindingConfig.trim().split(",");
        for (String token : tokens) {
            token = token.trim();
            logger.debug("token: {}", token);
            String[] confStatement = token.split("=");
            if (confStatement.length != 2) {
                throw new BindingConfigParseException("TinkerforgeGenericBindingProvider:processBindingConfiguration: invalid format, the entry must consist of key=value pair, but value was found." + token);
            } else {
                String key = confStatement[0];
                String value = confStatement[1];
                if (key.equals(ConfigKey.uid.name())) {
                    config.setUid(value);
                } else if (key.equals(ConfigKey.subid.name())) {
                    config.setSubId(value);
                } else if (key.equals(ConfigKey.name.name())) {
                    config.setName(value);
                } else {
                    deviceOptions.put(key, value);
                }
            }
        }
        config.setDeviceOptions(deviceOptions);
        config.setItem(item);
        addBindingConfig(item, config);
    }
}
Also used : DeviceOptions(org.openhab.binding.tinkerforge.internal.config.DeviceOptions) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 37 with BindingConfigParseException

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

the class TellstickGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    TellstickBindingConfig config = new TellstickBindingConfig();
    config.setItemName(item.getName());
    String[] configParts = bindingConfig.trim().split(":");
    if (configParts.length < 1) {
        throw new BindingConfigParseException("Tellstick binding must contain two parts separated by ':'");
    }
    TellstickDevice device;
    try {
        device = findDevice(configParts[0].trim());
    } catch (SupportedMethodsException e) {
        throw new BindingConfigParseException(e.getMessage());
    }
    validateBinding(item, configParts, device);
    if (device == null) {
        config.setId(Integer.valueOf(configParts[0].trim()));
    } else {
        config.setId(device.getId());
    }
    config.setValueSelector(TellstickValueSelector.getValueSelector(configParts[1].trim()));
    if (configParts.length > 2 && configParts[2].trim().length() > 0) {
        config.setUsageSelector(TellstickValueSelector.getValueSelector(configParts[2].trim()));
    }
    if (configParts.length > 3) {
        if (isIntegerRegex(configParts[3])) {
            config.setResend(Integer.parseInt(configParts[3]));
        } else if (configParts[3].matches("^([0-9]+)/([0-9]+)$")) {
            // Parse ie '3/300' into resend=3 and resendInterval=300
            String[] resendParts = configParts[3].split("/");
            config.setResend(Integer.parseInt(resendParts[0]));
            config.setResendInterval(Long.parseLong(resendParts[1]));
        } else {
            config.setProtocol(configParts[3]);
        }
    }
    logger.debug("Context:" + context + " Item " + item + " Conf:" + config);
    addBindingConfig(item, config);
}
Also used : SupportedMethodsException(org.openhab.binding.tellstick.internal.device.SupportedMethodsException) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) TellstickDevice(org.openhab.binding.tellstick.internal.device.TellstickDevice) TellstickBindingConfig(org.openhab.binding.tellstick.TellstickBindingConfig)

Example 38 with BindingConfigParseException

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

the class EpsonProjectorGenericBindingProvider method getCommandTypeFromString.

private EpsonProjectorCommandType getCommandTypeFromString(String commandTypeString, Item item) throws BindingConfigParseException {
    EpsonProjectorCommandType commandType = null;
    try {
        EpsonProjectorCommandType.validateBinding(commandTypeString, item.getClass());
        commandType = EpsonProjectorCommandType.getCommandType(commandTypeString);
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException("Invalid command type '" + commandTypeString + "'!");
    } catch (InvalidClassException e) {
        throw new BindingConfigParseException("Invalid item type for command type '" + commandTypeString + "'!");
    }
    return commandType;
}
Also used : InvalidClassException(java.io.InvalidClassException) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 39 with BindingConfigParseException

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

the class EpsonProjectorGenericBindingProvider method processBindingConfiguration.

/**
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    EpsonProjectorBindingConfig config = new EpsonProjectorBindingConfig();
    String[] configParts = bindingConfig.trim().split(":");
    config.inBinding = true;
    config.outBinding = true;
    config.itemType = item.getClass();
    if (bindingConfig.startsWith("<")) {
        if (configParts.length != 3) {
            throw new BindingConfigParseException("Epson projector in binding must contain 3 parts separated by ':'");
        }
        config.outBinding = false;
        config.deviceID = configParts[0].trim().replace("<", "");
        parseRefreshPeriod(configParts[2], config);
    } else if (bindingConfig.startsWith(">")) {
        if (configParts.length != 2) {
            throw new BindingConfigParseException("Epson projector out binding must contain 2 parts separated by ':'");
        }
        config.inBinding = false;
        config.deviceID = configParts[0].trim().replace(">", "");
    } else {
        if (configParts.length != 3) {
            throw new BindingConfigParseException("Epson projector bi-directional binding must contain 3 parts separated by ':'");
        }
        config.deviceID = configParts[0].trim();
        parseRefreshPeriod(configParts[2], config);
    }
    config.commandType = getCommandTypeFromString(configParts[1].trim(), item);
    addBindingConfig(item, config);
}
Also used : BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException)

Example 40 with BindingConfigParseException

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

the class FHTGenericBindingProvider method processBindingConfiguration.

/**
     * Binding in the type of
     * {fht="housecode=<housecode>;address=<optional>;datapoint=<optional>"}
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] configParts = bindingConfig.split(";");
    String housecode = null;
    String address = null;
    Datapoint datapoint = null;
    for (String s : configParts) {
        String[] entryParts = s.split("=");
        if ("housecode".equals(entryParts[0])) {
            housecode = entryParts[1];
        } else if ("address".equals(entryParts[0])) {
            address = entryParts[1];
        } else if ("datapoint".equals(entryParts[0])) {
            datapoint = Datapoint.valueOf(entryParts[1]);
        }
    }
    if (housecode == null) {
        throw new BindingConfigParseException("housecode mustn't be null");
    }
    if (datapoint == null) {
        throw new BindingConfigParseException("datapoint must be one of MEASURED_TEMP, DESIRED_TEMP, BATTERY, WINDOW or VALVE");
    }
    if ((datapoint == Datapoint.WINDOW || datapoint == Datapoint.VALVE) && address == null) {
        throw new BindingConfigParseException("Address of window contact needed");
    }
    FHTBindingConfig config = new FHTBindingConfig(item, housecode, address, datapoint);
    addBindingConfig(item, config);
}
Also used : Datapoint(org.openhab.binding.fht.FHTBindingConfig.Datapoint) FHTBindingConfig(org.openhab.binding.fht.FHTBindingConfig) 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