use of org.openhab.binding.nikobus.internal.config.Button in project openhab1-addons by openhab.
the class NikobusGenericBindingProvider method parseItem.
/**
* Parse an item from the provided configuration string.
*
* @param item.getName()
* item name
* @param config
* string to parse
* @return parsed item
* @throws BindingConfigParseException
* if no item could be created
*/
private AbstractNikobusItemConfig parseItem(Item item, String config) throws BindingConfigParseException {
if (config == null || config.trim().length() == 0) {
throw new BindingConfigParseException("Invalid config for item " + item.getName());
}
if (config.matches(BUTTON_CONFIG_PATTERN)) {
return new Button(item.getName(), config);
}
if (config.matches(MODULE_CHANNEL_PATTERN)) {
String address = config.split(":")[0];
int channelNum = Integer.parseInt(config.split(":")[1]);
int group = channelNum > 6 ? 2 : 1;
String moduleKey = address + "-" + group;
NikobusModule module = getModule(moduleKey);
if (module == null) {
log.trace("Creating channel group {}", moduleKey);
module = new ModuleChannelGroup(address, group);
allModules.add(module);
modules.put(moduleKey, module);
}
return ((ModuleChannelGroup) module).addChannel(item.getName(), channelNum, item.getAcceptedCommandTypes());
}
throw new BindingConfigParseException("Could not determine item type from config: " + config);
}
use of org.openhab.binding.nikobus.internal.config.Button in project openhab1-addons by openhab.
the class NikobusGenericBindingProviderTest method parseButtonWithRefresh.
private void parseButtonWithRefresh(String name, String config, Button.PressType type, String address, String[] groups) throws BindingConfigParseException {
Item item = new SwitchItem(name);
provider.processBindingConfiguration("context", item, config);
Button button = (Button) provider.getItemConfig(name);
assertEquals(name, button.getName());
assertEquals(address, button.getAddress());
assertEquals(type, button.getType());
String[] modules = (String[]) Whitebox.getInternalState(button, "impactedModules");
assertEquals(groups.length, modules.length);
for (int i = 0; i < groups.length; i++) {
assertEquals(groups[i], modules[i]);
}
}
use of org.openhab.binding.nikobus.internal.config.Button in project openhab1-addons by openhab.
the class NikobusGenericBindingProviderTest method parseButton.
private void parseButton(String name, String config, Button.PressType type, String address) throws BindingConfigParseException {
Item item = new SwitchItem(name);
provider.processBindingConfiguration("context", item, config);
Button button = (Button) provider.getItemConfig(name);
assertEquals(name, button.getName());
assertEquals(address, button.getAddress());
assertEquals(type, button.getType());
}
Aggregations