use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class KoubachiGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
String[] configParts = bindingConfig.split(":");
if (configParts.length < 3 || configParts.length > 4) {
throw new BindingConfigParseException("A Koubachi binding configuration for a property must consist of three or four parts - please verify your *.items file");
} else if (configParts[2].equals("action") && configParts.length != 4) {
throw new BindingConfigParseException("A Koubachi binding configuration for an action must consist of four parts - please verify your *.items file");
}
KoubachiBindingConfig config = new KoubachiBindingConfig();
config.resourceType = KoubachiResourceType.valueOf(configParts[0].toUpperCase());
config.resourceId = configParts[1];
if (configParts.length == 3) {
// this is a binding for a property
config.propertyName = configParts[2];
} else {
// this is a binding for a care action
config.actionType = configParts[3];
}
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SmarthomaticGenericBindingProvider method parseConfig.
private SmarthomaticBindingConfig parseConfig(Item item, String bindingConfig) throws BindingConfigParseException {
SmarthomaticBindingConfig config = new SmarthomaticBindingConfig();
Matcher matcher = CONFIG_PATTERN.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException("Config for item '" + item.getName() + "' could not be parsed.");
}
bindingConfig = matcher.group(1);
config.setItemName(item.getName());
config.setItem(item);
matcher = TRANSFORMATION_PATTERN.matcher(bindingConfig);
if (matcher.matches()) {
bindingConfig = matcher.group(1);
String transformation = matcher.group(2);
config.getConfigParams().put("transformation", transformation);
}
// parse bindingconfig here ...
StringTokenizer confItems = new StringTokenizer(bindingConfig, ",");
while (confItems.hasMoreTokens()) {
String[] token = confItems.nextToken().split("=");
String key = token[0];
String value = token[1];
config.getConfigParams().put(key, value);
// Strip all whitespaces from token[0]
key = key.replaceAll("\\s", "");
if ("deviceId".equals(key)) {
config.setDeviceId(value.replaceAll("\\s", ""));
} else if ("messageGroupId".equals(key)) {
config.setMessageGroupId(value.replaceAll("\\s", ""));
} else if ("messageId".equals(key)) {
config.setMessageId(value.replaceAll("\\s", ""));
} else if ("messagePart".equals(key)) {
config.setMessagePartId(value.replaceAll("\\s", ""));
} else if ("messageItem".equals(key)) {
config.setMessageItemId(value.replaceAll("\\s", ""));
}
}
return config;
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SappGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
logger.debug("processing binding configuration for context {}", context);
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
if (item instanceof SwitchItem && !(item instanceof DimmerItem)) {
SappBindingConfigSwitchItem sappBindingConfigSwitchItem = new SappBindingConfigSwitchItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigSwitchItem);
} else if (item instanceof ContactItem) {
SappBindingConfigContactItem sappBindingConfigContactItem = new SappBindingConfigContactItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigContactItem);
} else if (item instanceof NumberItem) {
SappBindingConfigNumberItem sappBindingConfigNumberItem = new SappBindingConfigNumberItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigNumberItem);
} else if (item instanceof RollershutterItem) {
SappBindingConfigRollershutterItem sappBindingConfigRollershutterItem = new SappBindingConfigRollershutterItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigRollershutterItem);
} else if (item instanceof DimmerItem) {
SappBindingConfigDimmerItem sappBindingConfigDimmerItem = new SappBindingConfigDimmerItem(item, bindingConfig);
addBindingConfig(item, sappBindingConfigDimmerItem);
} else {
throw new BindingConfigParseException("item '" + item.getName() + "' is of type '" + item.getClass().getSimpleName() + " - not yet implemented, please check your *.items configuration");
}
} else {
logger.warn("bindingConfig is NULL (item={}) -> processing bindingConfig aborted!", item);
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SappBindingConfigDimmerItem method parseSappAddressStatus.
private SappAddressDimmer parseSappAddressStatus(String bindingStringAddress) throws BindingConfigParseException {
String pnmasId;
SappAddressType addressType;
int address;
String subAddress;
int increment;
String[] bindingAddress = bindingStringAddress.split(":");
if (bindingAddress.length != 5) {
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));
}
// 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));
}
// increment
try {
increment = Integer.parseInt(bindingAddress[4]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
return new SappAddressDimmer(pnmasId, addressType, address, subAddress, 0, 100, increment);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SappBindingConfigRollershutterItem method parseSappAddressStatus.
private SappAddressRollershutterStatus parseSappAddressStatus(String bindingStringAddress) throws BindingConfigParseException {
String pnmasId;
SappAddressType addressType;
int address;
String subAddress;
int openValue;
int closedValue;
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));
}
// 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));
}
// openValue
try {
openValue = Integer.parseInt(bindingAddress[4]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
// closedValue
try {
closedValue = Integer.parseInt(bindingAddress[5]);
} catch (NumberFormatException e) {
throw new BindingConfigParseException(errorMessage(bindingStringAddress));
}
return new SappAddressRollershutterStatus(pnmasId, addressType, address, subAddress, openValue, closedValue);
}
Aggregations