use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SatelBindingConfigFactory method createBindingConfig.
/**
* Creates binding configuration class basing on given configuration string.
*
* @param bindingConfig
* configuration string
* @return an instance of {@link SatelBindingConfig}
* @throws BindingConfigParseException
* on any parsing error
*/
public SatelBindingConfig createBindingConfig(String bindingConfig) throws BindingConfigParseException {
try {
for (Class<? extends SatelBindingConfig> c : bindingConfigurationClasses) {
Method parseConfigMethod = c.getMethod("parseConfig", String.class);
SatelBindingConfig bc = (SatelBindingConfig) parseConfigMethod.invoke(null, bindingConfig);
if (bc != null) {
return bc;
}
}
// no more options, throw parse exception
} catch (Exception e) {
// throw parse exception in case of any error
}
throw new BindingConfigParseException(String.format("Invalid binding configuration: %s", bindingConfig));
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SerialBinding method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
int indexOf = bindingConfig.indexOf(',');
String serialPart = bindingConfig;
String pattern = null;
boolean base64 = false;
if (indexOf != -1) {
String substring = bindingConfig.substring(indexOf + 1);
serialPart = bindingConfig.substring(0, indexOf);
if (substring.startsWith("REGEX(")) {
pattern = substring.substring(6, substring.length() - 1);
}
if (substring.equals("BASE64")) {
base64 = true;
}
}
String[] portConfig = serialPart.split("@");
String port = portConfig[0];
int baudRate = 0;
if (portConfig.length > 1) {
baudRate = Integer.parseInt(portConfig[1]);
}
SerialDevice serialDevice = serialDevices.get(port);
if (serialDevice == null) {
if (baudRate > 0) {
serialDevice = new SerialDevice(port, baudRate);
} else {
serialDevice = new SerialDevice(port);
}
serialDevice.setTransformationService(transformationService);
serialDevice.setEventPublisher(eventPublisher);
try {
serialDevice.initialize();
} catch (InitializationException e) {
throw new BindingConfigParseException("Could not open serial port " + port + ": " + e.getMessage());
} catch (Throwable e) {
throw new BindingConfigParseException("Could not open serial port " + port + ": " + e.getMessage());
}
itemMap.put(item.getName(), port);
serialDevices.put(port, serialDevice);
}
serialDevice.addConfig(item.getName(), item.getClass(), pattern, base64);
Set<String> itemNames = contextMap.get(context);
if (itemNames == null) {
itemNames = new HashSet<String>();
contextMap.put(context, itemNames);
}
itemNames.add(item.getName());
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SappBindingConfigSwitchItem method parseSappAddressControl.
private SappAddressOnOffControl parseSappAddressControl(String bindingStringAddress) throws BindingConfigParseException {
String pnmasId;
SappAddressType addressType;
int address;
String subAddress;
int onValue = 1;
int offValue = 0;
String[] bindingAddress = bindingStringAddress.split(":");
if (bindingAddress.length != 4 && bindingAddress.length != 6) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
// pnmasId
pnmasId = bindingAddress[0];
if (pnmasId.length() == 0) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
// addressType
addressType = SappAddressType.fromString(bindingAddress[1].toUpperCase());
if (!validAddresses.keySet().contains(addressType)) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
if (addressType != SappAddressType.VIRTUAL) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
// address
try {
address = Integer.parseInt(bindingAddress[2]);
if (address < validAddresses.get(addressType).getLoRange() || address > validAddresses.get(addressType).getHiRange()) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
} catch (NumberFormatException e) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
// subaddress
subAddress = bindingAddress[3].toUpperCase();
if (!ArrayUtils.contains(validSubAddresses, subAddress)) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
// onvalue, offvalue
if (bindingAddress.length == 6) {
try {
onValue = Integer.parseInt(bindingAddress[4]);
offValue = Integer.parseInt(bindingAddress[5]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
}
return new SappAddressOnOffControl(pnmasId, addressType, address, subAddress, onValue, offValue);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SamsungAcGenericBindingProvider method parseBindingConfig.
private SamsungAcBindingConfig parseBindingConfig(Item item, String bindingConfig) throws BindingConfigParseException {
Matcher matcher = CONFIG_PATTERN.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
}
String acInstance = matcher.group(1);
CommandEnum property = CommandEnum.valueOf(matcher.group(2));
return new SamsungAcBindingConfig(acInstance, item.getName(), property);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SysteminfoGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (item == null) {
throw new BindingConfigParseException("item is not permitted to be null");
} else if (bindingConfig == null) {
throw new BindingConfigParseException("bindingConfig is not permitted to be null");
}
SysteminfoBindingConfig config = new SysteminfoBindingConfig();
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length < 2) {
throw new BindingConfigParseException("Systeminfo binding must contain at least 2 parts separated by ':'");
}
String commandType = configParts[0].trim();
if (configParts.length > 3) {
try {
int index1 = bindingConfig.indexOf(":");
int index2 = bindingConfig.indexOf(":", index1 + 1);
if (index1 > 0 && index2 > index1 + 1) {
config.target = bindingConfig.substring(index2 + 1);
} else {
throw new BindingConfigParseException("Systeminfo binding must contain 2-3 parts separated by ':'");
}
} catch (Exception e) {
throw new BindingConfigParseException("Systeminfo binding must contain 2-3 parts separated by ':'");
}
}
try {
config.commandType = SysteminfoCommandType.getCommandType(commandType);
} catch (IllegalArgumentException e) {
throw new BindingConfigParseException("'" + commandType + "' is not a valid command type");
}
try {
config.refreshInterval = Integer.valueOf(configParts[1]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException("'" + configParts[1] + "' is not a valid refresh interval");
}
if (config.target == null) {
if (configParts.length > 2) {
config.target = configParts[2].trim();
}
}
addBindingConfig(item, config);
}
Aggregations