@Override public String toString() { return "PlugwiseBindingConfigElement [id=" + id + ", type=" + type.toString() + ", interval=" + interval + "]"; }
/** * Parses the configuration string and update the provided config * * @param config * @param item * @param bindingConfig * @throws BindingConfigParseException */ private void parseBindingConfig(PlugwiseBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException { String commandAsString = null; String plugwiseID = null; String plugwiseCommand = null; int interval = 60; if (bindingConfig != null) { Matcher actionMatcher = ACTION_CONFIG_PATTERN.matcher(bindingConfig); Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig); if (!actionMatcher.matches() && !statusMatcher.matches()) { throw new BindingConfigParseException( "Plugwise binding configuration must consist of either three [config=" + statusMatcher + "] or four parts [config=" + actionMatcher + "]"); } else { if (actionMatcher.matches()) { commandAsString = actionMatcher.group(1); plugwiseID = actionMatcher.group(2); plugwiseCommand = actionMatcher.group(3); interval = Integer.valueOf(actionMatcher.group(4)); } else if (statusMatcher.matches()) { commandAsString = null; plugwiseID = statusMatcher.group(1); plugwiseCommand = statusMatcher.group(2); interval = Integer.valueOf(statusMatcher.group(3)); } PlugwiseCommandType type = PlugwiseCommandType.getCommandType(plugwiseCommand); if (PlugwiseCommandType.validateBinding(type, item)) { PlugwiseBindingConfigElement newElement = new PlugwiseBindingConfigElement(plugwiseID, type, interval); Command command = null; if (commandAsString == null) { // for those configuration strings that are not really linked to a openHAB command we // create a dummy Command to be able to store the configuration information // I have choosen to do that with NumberItems NumberItem dummy = new NumberItem(Integer.toString(counter)); command = createCommandFromString(dummy, Integer.toString(counter)); counter++; config.put(command, newElement); } else { command = createCommandFromString(item, commandAsString); config.put(command, newElement); } } else { String validItemType = PlugwiseCommandType.getValidItemTypes(plugwiseCommand); if (StringUtils.isEmpty(validItemType)) { throw new BindingConfigParseException( "'" + bindingConfig + "' is no valid binding type"); } else { throw new BindingConfigParseException( "'" + bindingConfig + "' is not bound to a valid item type. Valid item type(s): " + validItemType); } } } } else { return; } }