String datapointConfig = datapointConfigs[i].trim();
KNXBindingConfigItem configItem = new KNXBindingConfigItem();
configItem.itemName = item.getName();
if (datapointConfig.split("<").length > 2) {
throw new BindingConfigParseException("Only one readable GA allowed.");
}
Class<? extends Type> typeClass = item.getAcceptedCommandTypes().size() > 0 ?
item.getAcceptedCommandTypes().get(i) : item.getAcceptedDataTypes().size() > 1 ?
item.getAcceptedDataTypes().get(i) : item.getAcceptedDataTypes().get(0);
String[] dataPoints = datapointConfig.split("\\+");
for (int j = 0; j < dataPoints.length; ++j) {
String dataPoint = dataPoints[j].trim();
// If dataPoint is empty, we most likely have "pure" listening DP (+x/y/z).
// Just skip it, it will be handle in the next iteration.
if (dataPoint.isEmpty()) {
continue;
}
// check for the readable flag
boolean isReadable = false;
if (dataPoint.startsWith("<")) {
isReadable = true;
dataPoint = dataPoint.substring(1);
}
// find the DPT for this entry
String[] segments = dataPoint.split(":");
String dptID = (segments.length == 1) ? getDefaultDPTId(typeClass) : segments[0];
if (dptID == null || dptID.trim().isEmpty()) {
throw new BindingConfigParseException(
"No DPT could be determined for the type '" + typeClass.getSimpleName() + "'.");
}
// check if this DPT is supported
if (KNXCoreTypeMapper.toTypeClass(dptID) == null) {
throw new BindingConfigParseException(
"DPT " + dptID + " is not supported by the KNX binding.");
}
String ga = (segments.length == 1) ? segments[0].trim() : segments[1].trim();
// create group address and datapoint
GroupAddress groupAddress = new GroupAddress(ga);
Datapoint dp;
if (j != 0 || item.getAcceptedCommandTypes().size() == 0) {
dp = new StateDP(groupAddress, item.getName(), 0, dptID);
} else {
dp = new CommandDP(groupAddress, item.getName(), 0, dptID);
}
// assign datapoint to configuration item
if (configItem.mainDataPoint == null) {
configItem.mainDataPoint = dp;
}
if (isReadable) {
configItem.readableDataPoint = dp;
}
if(!configItem.allDataPoints.contains(dp)) {
configItem.allDataPoints.add(dp);
} else {
throw new BindingConfigParseException(
"Datapoint '"+dp.getDPT() + "' already exists for item '"+item.getName()+"'.");
}
}
config.add(configItem);
} catch (IndexOutOfBoundsException e) {
throw new BindingConfigParseException(
"No more than " + i + " datapoint definitions are allowed for this item.");
} catch (KNXFormatException e) {
throw new BindingConfigParseException(e.getMessage());
}
}
return config;
}