use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class GC100IRGenericBindingProvider method parseBindingConfig.
/**
* Parses the binding configuration and returns GC100BindingConfig instance.
*
* @param item
* @param bindingConfig
* @return GC100BindingConfig instance
* @throws BindingConfigParseException
*/
private GC100BindingConfig 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 gc100Instance = matcher.group(1);
String module = matcher.group(2);
String connector = matcher.group(3);
String code = matcher.group(4);
return new GC100BindingConfig(gc100Instance, Integer.parseInt(module), Integer.parseInt(connector), code);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class HDanywhereGenericBindingProvider method parseBindingConfig.
/**
* Parses the configuration string and update the provided config
*
* @param config
* @param item
* @param bindingConfig
* @throws BindingConfigParseException
*/
private void parseBindingConfig(HDanywhereBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
String host = null;
int port = 0;
int interval = 60;
if (bindingConfig != null) {
Matcher statusMatcher = STATUS_CONFIG_PATTERN.matcher(bindingConfig);
if (!statusMatcher.matches()) {
throw new BindingConfigParseException("HDanywhere binding configuration must consist of either three [config=" + statusMatcher + "] parts");
} else {
host = statusMatcher.group(1);
port = Integer.valueOf(statusMatcher.group(2));
interval = Integer.valueOf(statusMatcher.group(3));
HDanywhereBindingConfigElement newElement = new HDanywhereBindingConfigElement(host, port, interval);
config.add(newElement);
}
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class HeatmiserGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
HeatmiserBindingConfig config = new HeatmiserBindingConfig();
config.itemType = item.getClass();
Matcher bindingMatcher = BINDING_PATTERN.matcher(bindingConfig);
if (!bindingMatcher.matches()) {
throw new BindingConfigParseException(getBindingType() + " binding configuration must consist of two parts [config=" + bindingMatcher + "]");
} else {
config.address = Integer.parseInt(bindingMatcher.group(1));
config.function = Functions.valueOf(bindingMatcher.group(2));
// Check the type for different functions
switch(config.function) {
case SETTEMP:
case FROSTTEMP:
case ROOMTEMP:
case FLOORTEMP:
if (config.itemType != NumberItem.class && config.itemType != StringItem.class) {
logger.error("Only Number and String allowed for Heatmiser:{} function", config.function);
config = null;
}
break;
case HOLDTIME:
case HOLIDAYTIME:
if (config.itemType != SwitchItem.class && config.itemType != DateTimeItem.class) {
logger.error("Only Switch and DateTime allowed for Heatmiser:{} function", config.function);
config = null;
}
break;
case HOLIDAYSET:
if (config.itemType != SwitchItem.class && config.itemType != NumberItem.class) {
logger.error("Only Switch and Number allowed for Heatmiser:{} function", config.function);
config = null;
}
break;
case HOLDMODE:
case HOLIDAYMODE:
if (config.itemType != SwitchItem.class) {
logger.error("Only Switch allowed for Heatmiser:{} function", config.function);
config = null;
}
break;
case WATERSTATE:
case HEATSTATE:
case STATE:
case ONOFF:
if (config.itemType != SwitchItem.class && config.itemType != StringItem.class) {
logger.error("Only Switch and String allowed for Heatmiser:{} function", config.function);
config = null;
}
break;
default:
config = null;
logger.error("Unknown or unsupported Heatmiser function: {}", bindingConfig);
break;
}
}
if (config != null) {
addBindingConfig(item, config);
}
} else {
logger.warn("bindingConfig is NULL (item=" + item + ") -> processing bindingConfig aborted!");
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class NestGenericBindingProvider method validateItemType.
/**
* {@inheritDoc}
*/
@Override
public void validateItemType(Item item, String bindingConfig) throws BindingConfigParseException {
logger.trace("validateItemType called with bindingConfig={}", bindingConfig);
Matcher matcher = CONFIG_PATTERN.matcher(bindingConfig);
if (!matcher.matches() || matcher.groupCount() != 1) {
throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
}
String property = matcher.group(1);
logger.trace("validateItemType called with property={}", property);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class ProtocolGenericBindingProvider method parseBindingConfig.
/**
* Parses the configuration string and update the provided config
*
* @param config - the Configuration that needs to be updated with the parsing results
* @param item - the Item that this configuration is intented for
* @param bindingConfig - the configuration string that will be parsed
* @throws BindingConfigParseException
*/
private void parseBindingConfig(ProtocolBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
String direction = null;
Direction directionType = null;
String commandAsString = null;
String host = null;
String port = null;
String protocolCommand = null;
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(getBindingType() + " binding configuration must consist of four [config=" + statusMatcher + "] or five parts [config=" + actionMatcher + "]");
} else {
if (actionMatcher.matches()) {
direction = actionMatcher.group(1);
commandAsString = actionMatcher.group(2);
host = actionMatcher.group(3);
port = actionMatcher.group(4);
protocolCommand = actionMatcher.group(5) != null ? actionMatcher.group(5) : actionMatcher.group(6);
} else if (statusMatcher.matches()) {
direction = statusMatcher.group(1);
commandAsString = null;
host = statusMatcher.group(2);
port = statusMatcher.group(3);
protocolCommand = statusMatcher.group(4) != null ? statusMatcher.group(4) : statusMatcher.group(5);
}
if (direction.equals(">")) {
directionType = Direction.OUT;
} else if (direction.equals("<")) {
directionType = Direction.IN;
}
ProtocolBindingConfigElement newElement = new ProtocolBindingConfigElement(host, port, directionType, protocolCommand, item.getAcceptedDataTypes());
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++;
} else {
command = createCommandFromString(item, commandAsString);
}
config.put(command, newElement);
}
} else {
return;
}
}
Aggregations