use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class BenqProjectorGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
BenqProjectorBindingConfig config = new BenqProjectorBindingConfig();
if (bindingConfig.equalsIgnoreCase("power")) {
config.mode = BenqProjectorItemMode.POWER;
} else if (bindingConfig.equalsIgnoreCase("mute")) {
config.mode = BenqProjectorItemMode.MUTE;
} else if (bindingConfig.equalsIgnoreCase("volume")) {
config.mode = BenqProjectorItemMode.VOLUME;
} else if (bindingConfig.equalsIgnoreCase("lamp_hours")) {
config.mode = BenqProjectorItemMode.LAMP_HOURS;
} else if (bindingConfig.equalsIgnoreCase("source_number")) {
config.mode = BenqProjectorItemMode.SOURCE_NUMBER;
} else if (bindingConfig.equalsIgnoreCase("source_string")) {
config.mode = BenqProjectorItemMode.SOURCE_STRING;
} else {
throw new BindingConfigParseException("Unable to parse '" + bindingConfig + "' to create a valid item binding.");
}
logger.debug("Adding " + item.getName() + " as " + config.mode);
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class AnelGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig == null || bindingConfig.trim().isEmpty()) {
// empty binding - nothing to do
return;
}
final String[] segments = bindingConfig.trim().split(":");
if (segments.length != 2) {
throw new BindingConfigParseException("Invalid binding format '" + bindingConfig + "', expected: '<anelId>:<property>'");
}
final String deviceId = segments[0];
final String commandType = segments[1];
try {
AnelCommandType.validateBinding(commandType, item.getClass());
final AnelCommandType cmdType = AnelCommandType.getCommandType(commandType);
// if command type was validated successfully, add binding config
addBindingConfig(item, new AnelBindingConfig(item.getClass(), cmdType, deviceId));
} catch (IllegalArgumentException e) {
throw new BindingConfigParseException("'" + commandType + "' is not a valid Anel property");
} catch (InvalidClassException e) {
throw new BindingConfigParseException("Invalid class for Anel property '" + commandType + "'");
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class InsteonPLMGenericBindingProvider method processBindingConfiguration.
/**
* Inherited from AbstractGenericBindingProvider.
* Processes InsteonPLM binding configuration string.
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
String[] parts = parseConfigString(bindingConfig);
if (parts.length != 3) {
throw new BindingConfigParseException("item config must have addr:prodKey#feature format");
}
InsteonAddress addr = new InsteonAddress(parts[0]);
String[] params = parts[2].split(",");
String feature = params[0];
HashMap<String, String> args = new HashMap<String, String>();
for (int i = 1; i < params.length; i++) {
String[] kv = params[i].split("=");
if (kv.length == 2) {
args.put(kv[0], kv[1]);
} else {
logger.error("parameter {} does not have format a=b", params[i]);
}
}
InsteonPLMBindingConfig config = new InsteonPLMBindingConfig(item.getName(), addr, feature, parts[1], args);
addBindingConfig(item, config);
logger.trace("processing item \"{}\" read from .items file with cfg string {}", item.getName(), bindingConfig);
items.put(item.getName(), item);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class OceanicGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
OceanicBindingConfig config = new OceanicBindingConfig();
String valueSelectorString = null;
String pollingIntervalString = null;
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length != 3) {
throw new BindingConfigParseException("RME binding must contain three parts separated by ':'");
}
config.serialPort = configParts[0].trim();
valueSelectorString = configParts[1].trim();
pollingIntervalString = configParts[2].trim();
try {
OceanicValueSelector.validateBinding(valueSelectorString, item);
config.valueSelector = valueSelectorString;
config.pollingInterval = Integer.parseInt(pollingIntervalString);
addBindingConfig(item, config);
} catch (IllegalArgumentException e1) {
throw new BindingConfigParseException("Invalid value selector '" + valueSelectorString + "'!");
} catch (InvalidClassException e1) {
throw new BindingConfigParseException("Invalid item type for value selector '" + valueSelectorString + "'!");
}
} 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 OctollerGenricBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
String[] configParts = bindingConfig.trim().split("#");
if (configParts.length != 2) {
throw new BindingConfigParseException("Two parameters needed (Host#Block)");
}
// Right now a gateway must be given!
String[] hostParts = configParts[0].trim().split("@");
if (hostParts.length != 2) {
throw new BindingConfigParseException("Host paramter must contain device and gateway (deviceHost@gatewayHost)");
}
OctollerBindingConfig config = new OctollerBindingConfig();
config.DeviceHost = hostParts[0].trim();
config.GatewayHost = hostParts[1].trim();
// Check for BlockName
if (configParts[1].length() > 2 && configParts[1].startsWith("'") && configParts[1].endsWith("'")) {
config.BlockName = configParts[1].substring(1, configParts[1].length() - 1).trim();
} else {
try {
config.BlockID = Integer.parseInt(configParts[1]);
} catch (Exception ex) {
throw new BindingConfigParseException("Block parameter must be nummeric or the block name in single quotation marks");
}
}
addBindingConfig(item, config);
}
Aggregations