use of org.openhab.binding.satel.internal.types.ObjectType in project openhab1-addons by openhab.
the class IntegraStateBindingConfig method parseConfig.
/**
* Parses given binding configuration and creates configuration object.
*
* @param bindingConfig
* config to parse
* @return parsed config object or <code>null</code> if config does not
* match
* @throws BindingConfigParseException
* in case of parse errors
*/
public static IntegraStateBindingConfig parseConfig(String bindingConfig) throws BindingConfigParseException {
ConfigIterator iterator = new ConfigIterator(bindingConfig);
ObjectType objectType;
// parse object type, mandatory
try {
objectType = iterator.nextOfType(ObjectType.class, "object type");
} catch (Exception e) {
// wrong config type, skip parsing
return null;
}
// parse state type, mandatory except for output
StateType stateType = null;
int[] objectNumbers = {};
switch(objectType) {
case ZONE:
stateType = iterator.nextOfType(ZoneState.class, "zone state type");
break;
case PARTITION:
stateType = iterator.nextOfType(PartitionState.class, "partition state type");
break;
case OUTPUT:
stateType = OutputState.OUTPUT;
break;
case DOORS:
stateType = iterator.nextOfType(DoorsState.class, "doors state type");
break;
}
// parse object number, if provided
if (iterator.hasNext()) {
try {
String[] objectNumbersStr = iterator.next().split(",");
objectNumbers = new int[objectNumbersStr.length];
for (int i = 0; i < objectNumbersStr.length; ++i) {
int objectNumber = Integer.parseInt(objectNumbersStr[i]);
if (objectNumber < 1 || objectNumber > 256) {
throw new BindingConfigParseException(String.format("Invalid object number: %s", bindingConfig));
}
objectNumbers[i] = objectNumber;
}
} catch (NumberFormatException e) {
throw new BindingConfigParseException(String.format("Invalid object number: %s", bindingConfig));
}
}
return new IntegraStateBindingConfig(stateType, objectNumbers, iterator.parseOptions());
}
Aggregations