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);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class ProtocolGenericBindingProvider method parseAndAddBindingConfig.
private void parseAndAddBindingConfig(Item item, String bindingConfig) throws BindingConfigParseException {
ProtocolBindingConfig newConfig = new ProtocolBindingConfig();
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 bindingConfigPart = matcher.group(1);
if (StringUtils.isNotBlank(bindingConfigPart)) {
parseBindingConfig(newConfig, item, bindingConfigPart);
addBindingConfig(item, newConfig);
}
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class ZWaveGenericBindingProvider method processBindingConfiguration.
/**
* Processes Z-Wave binding configuration string.
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
logger.trace("processBindingConfiguration({}, {})", item.getName(), bindingConfig);
super.processBindingConfiguration(context, item, bindingConfig);
String[] segments = bindingConfig.split(":");
if (segments.length < 1 || segments.length > 3) {
throw new BindingConfigParseException("Invalid number of segments in binding: " + bindingConfig);
}
int nodeId;
try {
nodeId = Integer.parseInt(segments[0]);
} catch (Exception e) {
logger.error("{}: Invalid node ID '{}'", item.getName(), segments[0]);
throw new BindingConfigParseException(segments[0] + " is not a valid node id.");
}
if (nodeId <= 0 || nodeId > 232) {
logger.error("{}: Invalid node ID '{}'", item.getName(), nodeId);
throw new BindingConfigParseException(nodeId + " is not a valid node number.");
}
int endpoint = 0;
Integer refreshInterval = null;
Map<String, String> arguments = new HashMap<String, String>();
for (int i = 1; i < segments.length; i++) {
try {
if (segments[i].contains("=")) {
for (String keyValuePairString : segments[i].split(",")) {
String[] pair = keyValuePairString.split("=");
String key = pair[0].trim().toLowerCase();
String value = pair[1].trim().toLowerCase();
if (key.equals("refresh_interval")) {
refreshInterval = Integer.parseInt(value);
} else {
arguments.put(key, value);
}
// Sanity check the command class
if (key.equals("command")) {
if (ZWaveCommandClass.CommandClass.getCommandClass(pair[1]) == null && value.equals("info") == false) {
logger.error("{}: Invalid command class '{}'", item.getName(), pair[1].toUpperCase());
throw new BindingConfigParseException("Invalid command class " + pair[1].toUpperCase());
}
}
}
} else {
try {
endpoint = Integer.parseInt(segments[i]);
} catch (Exception e) {
logger.error("{}: Invalid endpoint ID '{}'", item.getName(), segments[i]);
throw new BindingConfigParseException(segments[i] + " is not a valid endpoint.");
}
}
} catch (Exception e) {
throw new BindingConfigParseException(segments[i] + " is not a valid argument.");
}
}
ZWaveBindingConfig config = new ZWaveBindingConfig(nodeId, endpoint, refreshInterval, arguments);
addBindingConfig(item, config);
items.put(item.getName(), item);
}
Aggregations