use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class ClassicParser method parseAddress.
@Override
public String parseAddress(String... addressParts) throws BindingConfigParseException {
char group = addressParts[0].charAt(0);
int subAddress = 0;
try {
subAddress = Integer.parseInt(addressParts[1]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException("Sub address is not a number. Configured subaddress: " + addressParts[1]);
}
return getGroupAddress(group) + getSubAddress(subAddress) + "0F";
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class FLSParser method parseAddress.
@Override
public String parseAddress(String... addressParts) throws BindingConfigParseException {
String group = addressParts[0];
int subAddress = 0;
try {
subAddress = Integer.parseInt(addressParts[1]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException("Sub address is not a number. Configured subaddress: " + addressParts[1]);
}
return getGroupAddress(group) + getSubAddress(subAddress) + "00";
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class FLSParser method getGroupAddress.
private String getGroupAddress(String group) throws BindingConfigParseException {
StringBuffer addressBuffer = new StringBuffer(4);
addressBuffer.append("FFFF");
if ("I".equalsIgnoreCase(group)) {
addressBuffer.setCharAt(0, '0');
} else if ("II".equalsIgnoreCase(group)) {
addressBuffer.setCharAt(1, '0');
} else if ("III".equalsIgnoreCase(group)) {
addressBuffer.setCharAt(2, '0');
} else if ("IV".equalsIgnoreCase(group)) {
addressBuffer.setCharAt(3, '0');
} else {
throw new BindingConfigParseException("Unknown roman number given: " + group);
}
return addressBuffer.toString();
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class HttpGenericBindingProvider method parseInBindingConfig.
/**
* Parses a http-in configuration by using the regular expression
* <code>(.*?):(\\d*):(.*)</code>. Where the groups should contain the
* following content:
* <ul>
* <li>1 - url</li>
* <li>2 - refresh interval</li>
* <li>3 - the transformation rule</li>
* </ul>
*
* @param item
*
* @param bindingConfig the config string to parse
* @param config
* @return the filled {@link HttpBindingConfig}
*
* @throws BindingConfigParseException if the regular expression doesn't match
* the given <code>bindingConfig</code>
*/
protected HttpBindingConfig parseInBindingConfig(Item item, String bindingConfig, HttpBindingConfig config) throws BindingConfigParseException {
Matcher matcher = IN_BINDING_PATTERN.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't represent a valid in-binding-configuration. A valid configuration is matched by the RegExp '" + IN_BINDING_PATTERN + "'");
}
matcher.reset();
HttpBindingConfigElement configElement;
while (matcher.find()) {
configElement = new HttpBindingConfigElement();
configElement.url = matcher.group(1).replaceAll("\\\\\"", "");
configElement.headers = parseHttpHeaders(matcher.group(2));
configElement.refreshInterval = Integer.valueOf(matcher.group(3)).intValue();
configElement.transformation = matcher.group(4).replaceAll("\\\\\"", "\"");
config.put(IN_BINDING_KEY, configElement);
}
return config;
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class HttpGenericBindingProvider method parseBindingConfig.
/**
* Delegates parsing the <code>bindingConfig</code> with respect to the
* first character (<code><</code> or <code>></code>) to the
* specialized parsing methods
*
* @param item
* @param bindingConfig
*
* @throws BindingConfigParseException
*/
protected HttpBindingConfig parseBindingConfig(Item item, String bindingConfig) throws BindingConfigParseException {
HttpBindingConfig config = new HttpBindingConfig(item);
Matcher matcher = BASE_CONFIG_PATTERN.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't contain a valid binding configuration");
}
matcher.reset();
while (matcher.find()) {
String direction = matcher.group(1);
String bindingConfigPart = matcher.group(2);
if (direction.equals("<")) {
config = parseInBindingConfig(item, bindingConfigPart, config);
} else if (direction.equals(">")) {
config = parseOutBindingConfig(item, bindingConfigPart, config);
} else {
throw new BindingConfigParseException("Unknown command given! Configuration must start with '<' or '>' ");
}
}
return config;
}
Aggregations