Search in sources :

Example 1 with Button

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);
}
Also used : Button(org.openhab.binding.nikobus.internal.config.Button) ModuleChannelGroup(org.openhab.binding.nikobus.internal.config.ModuleChannelGroup) BindingConfigParseException(org.openhab.model.item.binding.BindingConfigParseException) NikobusModule(org.openhab.binding.nikobus.internal.core.NikobusModule)

Example 2 with Button

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]);
    }
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) Button(org.openhab.binding.nikobus.internal.config.Button) SwitchItem(org.openhab.core.library.items.SwitchItem)

Example 3 with Button

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());
}
Also used : SwitchItem(org.openhab.core.library.items.SwitchItem) Item(org.openhab.core.items.Item) Button(org.openhab.binding.nikobus.internal.config.Button) SwitchItem(org.openhab.core.library.items.SwitchItem)

Aggregations

Button (org.openhab.binding.nikobus.internal.config.Button)3 Item (org.openhab.core.items.Item)2 SwitchItem (org.openhab.core.library.items.SwitchItem)2 ModuleChannelGroup (org.openhab.binding.nikobus.internal.config.ModuleChannelGroup)1 NikobusModule (org.openhab.binding.nikobus.internal.core.NikobusModule)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1