Search in sources :

Example 1 with IntertechnoBindingConfig

use of org.openhab.binding.intertechno.IntertechnoBindingConfig in project openhab1-addons by openhab.

the class CULIntertechnoBinding method internalReceiveCommand.

/**
     *
     * @{inheritDoc
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    IntertechnoBindingConfig config = null;
    for (CULIntertechnoBindingProvider provider : providers) {
        config = provider.getConfigForItemName(itemName);
        if (config != null) {
            break;
        }
    }
    if (config != null && culHandlerLifecycle.isCulReady() && command instanceof OnOffType) {
        OnOffType type = (OnOffType) command;
        String commandValue = null;
        switch(type) {
            case ON:
                commandValue = config.getCommandValueON();
                break;
            case OFF:
                commandValue = config.getCommandValueOFF();
                break;
        }
        if (commandValue != null) {
            try {
                culHandlerLifecycle.getCul().send("is" + config.getAddress() + commandValue);
            } catch (CULCommunicationException e) {
                logger.error("Can't write to CUL", e);
            }
        } else {
            logger.error("Can't determine value to send for command " + command.toString());
        }
    }
}
Also used : CULIntertechnoBindingProvider(org.openhab.binding.intertechno.CULIntertechnoBindingProvider) OnOffType(org.openhab.core.library.types.OnOffType) IntertechnoBindingConfig(org.openhab.binding.intertechno.IntertechnoBindingConfig) CULCommunicationException(org.openhab.io.transport.cul.CULCommunicationException)

Example 2 with IntertechnoBindingConfig

use of org.openhab.binding.intertechno.IntertechnoBindingConfig in project openhab1-addons by openhab.

the class CULIntertechnoGenericBindingProvider method processBindingConfiguration.

/**
     * config of style
     * <code>{{@literal intertechno="type=<classic|fls|rev>;group=<group>;address=<address>"}}</code><br>
     * 
     * {@inheritDoc}
     */
@Override
public void processBindingConfiguration(String context, Item item, String bindingConfig) throws BindingConfigParseException {
    super.processBindingConfiguration(context, item, bindingConfig);
    String[] configParts = bindingConfig.split(";");
    String type = configParts[0].split("=")[1];
    List<String> addressParts = new ArrayList<String>(3);
    for (int i = 1; i < configParts.length; i++) {
        addressParts.add(configParts[i].split("=")[1]);
    }
    IntertechnoAddressParser parser = AddressParserFactory.getParser(type);
    String address = parser.parseAddress(addressParts.toArray(new String[addressParts.size()]));
    String commandOn = parser.getCommandValueON();
    String commandOff = parser.getCOmmandValueOFF();
    IntertechnoBindingConfig config = new IntertechnoBindingConfig(address, commandOn, commandOff);
    addBindingConfig(item, config);
}
Also used : IntertechnoAddressParser(org.openhab.binding.intertechno.internal.parser.IntertechnoAddressParser) ArrayList(java.util.ArrayList) IntertechnoBindingConfig(org.openhab.binding.intertechno.IntertechnoBindingConfig)

Aggregations

IntertechnoBindingConfig (org.openhab.binding.intertechno.IntertechnoBindingConfig)2 ArrayList (java.util.ArrayList)1 CULIntertechnoBindingProvider (org.openhab.binding.intertechno.CULIntertechnoBindingProvider)1 IntertechnoAddressParser (org.openhab.binding.intertechno.internal.parser.IntertechnoAddressParser)1 OnOffType (org.openhab.core.library.types.OnOffType)1 CULCommunicationException (org.openhab.io.transport.cul.CULCommunicationException)1