use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class TinkerforgeGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
// parse bindingconfig here ...
if (bindingConfig == null) {
logger.error("got bindingConfig null for item: {}", item.getName());
} else {
TinkerforgeBindingConfig config = new TinkerforgeBindingConfig();
DeviceOptions deviceOptions = new DeviceOptions();
String[] tokens = bindingConfig.trim().split(",");
for (String token : tokens) {
token = token.trim();
logger.debug("token: {}", token);
String[] confStatement = token.split("=");
if (confStatement.length != 2) {
throw new BindingConfigParseException("TinkerforgeGenericBindingProvider:processBindingConfiguration: invalid format, the entry must consist of key=value pair, but value was found." + token);
} else {
String key = confStatement[0];
String value = confStatement[1];
if (key.equals(ConfigKey.uid.name())) {
config.setUid(value);
} else if (key.equals(ConfigKey.subid.name())) {
config.setSubId(value);
} else if (key.equals(ConfigKey.name.name())) {
config.setName(value);
} else {
deviceOptions.put(key, value);
}
}
}
config.setDeviceOptions(deviceOptions);
config.setItem(item);
addBindingConfig(item, config);
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class TellstickGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
TellstickBindingConfig config = new TellstickBindingConfig();
config.setItemName(item.getName());
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length < 1) {
throw new BindingConfigParseException("Tellstick binding must contain two parts separated by ':'");
}
TellstickDevice device;
try {
device = findDevice(configParts[0].trim());
} catch (SupportedMethodsException e) {
throw new BindingConfigParseException(e.getMessage());
}
validateBinding(item, configParts, device);
if (device == null) {
config.setId(Integer.valueOf(configParts[0].trim()));
} else {
config.setId(device.getId());
}
config.setValueSelector(TellstickValueSelector.getValueSelector(configParts[1].trim()));
if (configParts.length > 2 && configParts[2].trim().length() > 0) {
config.setUsageSelector(TellstickValueSelector.getValueSelector(configParts[2].trim()));
}
if (configParts.length > 3) {
if (isIntegerRegex(configParts[3])) {
config.setResend(Integer.parseInt(configParts[3]));
} else if (configParts[3].matches("^([0-9]+)/([0-9]+)$")) {
// Parse ie '3/300' into resend=3 and resendInterval=300
String[] resendParts = configParts[3].split("/");
config.setResend(Integer.parseInt(resendParts[0]));
config.setResendInterval(Long.parseLong(resendParts[1]));
} else {
config.setProtocol(configParts[3]);
}
}
logger.debug("Context:" + context + " Item " + item + " Conf:" + config);
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class EpsonProjectorGenericBindingProvider method getCommandTypeFromString.
private EpsonProjectorCommandType getCommandTypeFromString(String commandTypeString, Item item) throws BindingConfigParseException {
EpsonProjectorCommandType commandType = null;
try {
EpsonProjectorCommandType.validateBinding(commandTypeString, item.getClass());
commandType = EpsonProjectorCommandType.getCommandType(commandTypeString);
} catch (IllegalArgumentException e) {
throw new BindingConfigParseException("Invalid command type '" + commandTypeString + "'!");
} catch (InvalidClassException e) {
throw new BindingConfigParseException("Invalid item type for command type '" + commandTypeString + "'!");
}
return commandType;
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class EpsonProjectorGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
EpsonProjectorBindingConfig config = new EpsonProjectorBindingConfig();
String[] configParts = bindingConfig.trim().split(":");
config.inBinding = true;
config.outBinding = true;
config.itemType = item.getClass();
if (bindingConfig.startsWith("<")) {
if (configParts.length != 3) {
throw new BindingConfigParseException("Epson projector in binding must contain 3 parts separated by ':'");
}
config.outBinding = false;
config.deviceID = configParts[0].trim().replace("<", "");
parseRefreshPeriod(configParts[2], config);
} else if (bindingConfig.startsWith(">")) {
if (configParts.length != 2) {
throw new BindingConfigParseException("Epson projector out binding must contain 2 parts separated by ':'");
}
config.inBinding = false;
config.deviceID = configParts[0].trim().replace(">", "");
} else {
if (configParts.length != 3) {
throw new BindingConfigParseException("Epson projector bi-directional binding must contain 3 parts separated by ':'");
}
config.deviceID = configParts[0].trim();
parseRefreshPeriod(configParts[2], config);
}
config.commandType = getCommandTypeFromString(configParts[1].trim(), item);
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class FHTGenericBindingProvider method processBindingConfiguration.
/**
* Binding in the type of
* {fht="housecode=<housecode>;address=<optional>;datapoint=<optional>"}
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
String[] configParts = bindingConfig.split(";");
String housecode = null;
String address = null;
Datapoint datapoint = null;
for (String s : configParts) {
String[] entryParts = s.split("=");
if ("housecode".equals(entryParts[0])) {
housecode = entryParts[1];
} else if ("address".equals(entryParts[0])) {
address = entryParts[1];
} else if ("datapoint".equals(entryParts[0])) {
datapoint = Datapoint.valueOf(entryParts[1]);
}
}
if (housecode == null) {
throw new BindingConfigParseException("housecode mustn't be null");
}
if (datapoint == null) {
throw new BindingConfigParseException("datapoint must be one of MEASURED_TEMP, DESIRED_TEMP, BATTERY, WINDOW or VALVE");
}
if ((datapoint == Datapoint.WINDOW || datapoint == Datapoint.VALVE) && address == null) {
throw new BindingConfigParseException("Address of window contact needed");
}
FHTBindingConfig config = new FHTBindingConfig(item, housecode, address, datapoint);
addBindingConfig(item, config);
}
Aggregations