use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class PulseaudioGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
PulseaudioBindingConfig config = new PulseaudioBindingConfig();
String[] configParts = bindingConfig.split(":");
if (item instanceof StringItem) {
if (configParts.length != 1 && configParts.length != 3) {
throw new BindingConfigParseException("Pulseaudio binding configuration for StringItems must consist of one or three part [config=" + configParts + "]");
}
config.serverId = StringUtils.trim(configParts[0]);
config.itemType = item.getClass();
addBindingConfig(item, config);
return;
} else if (configParts.length < 2 || configParts.length > 3) {
throw new BindingConfigParseException("Pulseaudio binding configuration must consist of two or three parts [config=" + configParts + "]");
}
config.serverId = StringUtils.trim(configParts[0]);
config.itemName = StringUtils.trim(configParts[1]);
if (configParts.length == 3) {
config.command = StringUtils.trim(configParts[2]);
}
config.itemType = item.getClass();
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class RFXComGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
RFXComBindingConfig config = new RFXComBindingConfig();
String valueSelectorString = null;
if (bindingConfig.startsWith("<")) {
String[] configParts = bindingConfig.trim().split(":");
if (configParts.length != 2) {
throw new BindingConfigParseException("RFXCOM binding must contain two parts separated by ':'");
}
config.id = configParts[0].trim().replace("<", "");
config.inBinding = true;
valueSelectorString = configParts[1].trim();
} else if (bindingConfig.startsWith(">")) {
String[] configParts = bindingConfig.trim().split(":");
config.id = configParts[0].trim().replace(">", "");
config.inBinding = false;
String[] types = configParts[1].trim().split("\\.");
if (types.length != 2) {
throw new BindingConfigParseException("RFXCOM out binding second field should contain 2 parts separated by '.'");
}
try {
config.packetType = RFXComMessageFactory.convertPacketType(types[0].trim());
} catch (IllegalArgumentException e) {
throw new BindingConfigParseException("Invalid packet type '" + types[0] + "'!");
}
try {
config.subType = RFXComMessageFactory.getMessageInterface(config.packetType).convertSubType(types[1].trim());
} catch (Exception e) {
throw new BindingConfigParseException("Invalid sub type '" + types[1] + "' in type '" + config.packetType + "'!");
}
valueSelectorString = configParts[2].trim();
} else {
throw new BindingConfigParseException("RFXCOM binding should start < or > character!");
}
try {
RFXComValueSelector.validateBinding(valueSelectorString, item.getClass());
config.valueSelector = RFXComValueSelector.getValueSelector(valueSelectorString);
} catch (IllegalArgumentException e1) {
throw new BindingConfigParseException("Invalid value selector '" + valueSelectorString + "'!");
} catch (InvalidClassException e1) {
throw new BindingConfigParseException("Invalid item type for value selector '" + valueSelectorString + "'!");
}
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class PlugwiseBinding method postUpdate.
/**
* Method to post updates to the OH runtime.
*
*
* @param MAC of the Plugwise device concerned
* @param ctype is the Plugwise Command type
* @param value is the value (to be converted) to post
*/
public void postUpdate(String MAC, PlugwiseCommandType ctype, Object value) {
if (MAC != null && ctype != null && value != null) {
for (PlugwiseBindingProvider provider : providers) {
Set<String> qualifiedItems = provider.getItemNames(MAC, ctype);
// Make sure we also capture those devices that were pre-defined with a friendly name in a .cfg or alike
Set<String> qualifiedItemsFriendly = provider.getItemNames(stick.getDevice(MAC).getName(), ctype);
qualifiedItems.addAll(qualifiedItemsFriendly);
State type = null;
try {
type = createStateForType(ctype, value);
} catch (BindingConfigParseException e) {
logger.error("Error parsing a value {} to a state variable of type {}", value.toString(), ctype.getTypeClass().toString());
}
for (String item : qualifiedItems) {
if (type instanceof State) {
eventPublisher.postUpdate(item, type);
} else {
throw new IllegalClassException("Cannot process update of type " + (type == null ? "null" : type.toString()));
}
}
}
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class PlugwiseGenericBindingProvider method parseBindingConfig.
/**
* Parses the configuration string and update the provided config
*
* @param config
* @param item
* @param bindingConfig
* @throws BindingConfigParseException
*/
private void parseBindingConfig(PlugwiseBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
String commandAsString = null;
String plugwiseID = null;
String plugwiseCommand = null;
int interval = 60;
if (bindingConfig == null) {
logger.warn("bindingConfig for item '{}' is null", item.getName());
return;
}
Matcher actionWithJobMatcher = ACTION_CONFIG_WITH_JOB_PATTERN.matcher(bindingConfig);
Matcher statusWithJobMatcher = STATUS_CONFIG_WITH_JOB_PATTERN.matcher(bindingConfig);
Matcher actionWithoutJobMatcher = ACTION_CONFIG_WITHOUT_JOB_PATTERN.matcher(bindingConfig);
Matcher statusWithoutJobMatcher = STATUS_CONFIG_WITHOUT_JOB_PATTERN.matcher(bindingConfig);
if (!actionWithJobMatcher.matches() && !statusWithJobMatcher.matches() && !actionWithoutJobMatcher.matches() && !statusWithoutJobMatcher.matches()) {
throw new //
BindingConfigParseException(//
"Plugwise binding configuration must consist of either:\n" + "* 2 parts: [config=" + statusWithoutJobMatcher + //
"]\n" + "* 3 parts: [config=" + statusWithJobMatcher + //
"]\n" + " [config=" + actionWithoutJobMatcher + //
"]\n" + "* 4 parts: [config=" + actionWithJobMatcher + "]");
}
if (actionWithJobMatcher.matches()) {
commandAsString = actionWithJobMatcher.group(1);
plugwiseID = actionWithJobMatcher.group(2);
plugwiseCommand = actionWithJobMatcher.group(3);
interval = Integer.valueOf(actionWithJobMatcher.group(4));
} else if (statusWithJobMatcher.matches()) {
commandAsString = null;
plugwiseID = statusWithJobMatcher.group(1);
plugwiseCommand = statusWithJobMatcher.group(2);
interval = Integer.valueOf(statusWithJobMatcher.group(3));
} else if (actionWithoutJobMatcher.matches()) {
commandAsString = actionWithoutJobMatcher.group(1);
plugwiseID = actionWithoutJobMatcher.group(2);
plugwiseCommand = actionWithoutJobMatcher.group(3);
interval = -1;
} else if (statusWithoutJobMatcher.matches()) {
commandAsString = null;
plugwiseID = statusWithoutJobMatcher.group(1);
plugwiseCommand = statusWithoutJobMatcher.group(2);
interval = -1;
}
PlugwiseCommandType type = PlugwiseCommandType.getCommandType(plugwiseCommand);
if (PlugwiseCommandType.validateBinding(type, item)) {
PlugwiseBindingConfigElement newElement = new PlugwiseBindingConfigElement(plugwiseID, type, interval);
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++;
config.put(command, newElement);
} else {
command = createCommandFromString(item, commandAsString);
config.put(command, newElement);
}
} else {
String validItemType = PlugwiseCommandType.getValidItemTypes(plugwiseCommand);
if (StringUtils.isEmpty(validItemType)) {
throw new BindingConfigParseException("'" + bindingConfig + "' is no valid binding type");
} else {
throw new BindingConfigParseException("'" + bindingConfig + "' is not bound to a valid item type. Valid item type(s): " + validItemType);
}
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SnmpGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
if (bindingConfig != null) {
SnmpBindingConfig newConfig = new SnmpBindingConfig();
Matcher matcher = BASE_CONFIG_PATTERN.matcher(bindingConfig);
if (!matcher.matches()) {
throw new BindingConfigParseException("bindingConfig '" + bindingConfig + "' doesn't contain a valid binding configuration");
}
matcher.reset();
while (matcher.find()) {
String bindingConfigPart = matcher.group(1);
if (StringUtils.isNotBlank(bindingConfigPart)) {
parseBindingConfig(newConfig, item, bindingConfigPart);
}
}
addBindingConfig(item, newConfig);
} else {
logger.warn("bindingConfig is NULL (item={}) -> processing bindingConfig aborted!", item);
}
}
Aggregations