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);
}
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SwegonVentilationGenericBindingProvider method processBindingConfiguration.
/**
* {@inheritDoc}
*/
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
super.processBindingConfiguration(context, item, bindingConfig);
SwegonVentilationBindingConfig config = new SwegonVentilationBindingConfig();
config.itemType = item.getClass();
String commandType = bindingConfig.trim();
try {
SwegonVentilationCommandType.validateBinding(commandType, config.itemType);
config.commandType = SwegonVentilationCommandType.getCommandType(commandType);
} catch (IllegalArgumentException e) {
throw new BindingConfigParseException("'" + commandType + "' is not a valid command type");
} catch (InvalidClassException e) {
throw new BindingConfigParseException("Not valid class for command type '" + commandType + "'");
}
addBindingConfig(item, config);
}
use of org.openhab.model.item.binding.BindingConfigParseException in project openhab1-addons by openhab.
the class SonosGenericBindingProvider method parseBindingConfig.
private void parseBindingConfig(SonosBindingConfig config, Item item, String bindingConfig) throws BindingConfigParseException {
String sonosID = null;
String commandAsString = null;
String sonosCommand = 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("Sonos binding configuration must consist of either two [config=" + statusMatcher + "] or three parts [config=" + actionMatcher + "]");
} else {
if (actionMatcher.matches()) {
commandAsString = actionMatcher.group(1);
sonosID = actionMatcher.group(2);
sonosCommand = actionMatcher.group(3);
} else if (statusMatcher.matches()) {
commandAsString = null;
sonosID = statusMatcher.group(1);
sonosCommand = statusMatcher.group(2);
}
SonosBindingConfigElement newElement = new SonosBindingConfigElement(sonosCommand, sonosID, item.getAcceptedDataTypes());
Command command = null;
if (commandAsString == null) {
command = createCommandFromString(null, Integer.toString(counter));
counter++;
config.put(command, newElement);
} else {
command = createCommandFromString(item, commandAsString);
config.put(command, newElement);
}
}
} else {
return;
}
}
Aggregations