Search in sources :

Example 6 with SappException

use of com.github.paolodenti.jsapp.core.command.base.SappException in project openhab1-addons by openhab.

the class SappCentralExecuter method executeSapp75Command.

/**
     * runs 75 command
     */
public int executeSapp75Command(String ip, int port, byte address) throws SappException {
    synchronized (this) {
        SappCommand sappCommand = new Sapp75Command(address);
        sappCommand.run(ip, port);
        if (!sappCommand.isResponseOk()) {
            throw new SappException("command execution failed");
        }
        return sappCommand.getResponse().getDataAsWord();
    }
}
Also used : SappCommand(com.github.paolodenti.jsapp.core.command.base.SappCommand) Sapp75Command(com.github.paolodenti.jsapp.core.command.Sapp75Command) SappException(com.github.paolodenti.jsapp.core.command.base.SappException)

Example 7 with SappException

use of com.github.paolodenti.jsapp.core.command.base.SappException in project openhab1-addons by openhab.

the class SappBinding method execute.

/**
     * @{inheritDoc
     */
@Override
protected void execute() {
    if (isProperlyConfigured()) {
        // wait until provider is properly configured and all items are loaded
        SappBindingProvider provider = getFirstSappBindingProvider();
        if (provider != null) {
            if (provider.getSappUpdatePendingRequests().areUpdatePendingRequestsPresent()) {
                // reinit
                // items
                Set<String> toBeProcessed = provider.getSappUpdatePendingRequests().getAndClearPendingUpdateRequests();
                initializeAllItemsInProvider(provider, toBeProcessed);
            } else {
                if (!pollingEnabled) {
                    return;
                }
                SappCentralExecuter sappCentralExecuter = SappCentralExecuter.getInstance();
                for (String pnmasId : provider.getPnmasMap().keySet()) {
                    // each pnmas
                    SappPnmas pnmas = provider.getPnmasMap().get(pnmasId);
                    try {
                        PollingResult pollingResult = sappCentralExecuter.executePollingSappCommands(pnmas.getIp(), pnmas.getPort());
                        if (pollingResult.changedOutputs.size() != 0) {
                            for (Byte outputAddress : pollingResult.changedOutputs.keySet()) {
                                logger.debug("Output variation {} received, new value is {}", SappUtils.byteToUnsigned(outputAddress), pollingResult.changedOutputs.get(outputAddress));
                                provider.setOutputCachedValue(SappUtils.byteToUnsigned(outputAddress), pollingResult.changedOutputs.get(outputAddress).intValue());
                                updateState(pnmasId, SappAddressType.OUTPUT, SappUtils.byteToUnsigned(outputAddress), pollingResult.changedOutputs.get(outputAddress).intValue(), provider);
                            }
                        }
                        if (pollingResult.changedInputs.size() != 0) {
                            for (Byte inputAddress : pollingResult.changedInputs.keySet()) {
                                logger.debug("Input variation {} received, new value is {}", SappUtils.byteToUnsigned(inputAddress), pollingResult.changedInputs.get(inputAddress));
                                provider.setInputCachedValue(SappUtils.byteToUnsigned(inputAddress), pollingResult.changedInputs.get(inputAddress).intValue());
                                updateState(pnmasId, SappAddressType.INPUT, SappUtils.byteToUnsigned(inputAddress), pollingResult.changedInputs.get(inputAddress).intValue(), provider);
                            }
                        }
                        if (pollingResult.changedVirtuals.size() != 0) {
                            for (Integer virtualAddress : pollingResult.changedVirtuals.keySet()) {
                                logger.debug("Virtual variation {} received, new value is {}", virtualAddress, pollingResult.changedVirtuals.get(virtualAddress));
                                provider.setVirtualCachedValue(virtualAddress, pollingResult.changedVirtuals.get(virtualAddress).intValue());
                                updateState(pnmasId, SappAddressType.VIRTUAL, virtualAddress, pollingResult.changedVirtuals.get(virtualAddress).intValue(), provider);
                            }
                        }
                    } catch (SappException e) {
                        logger.error("polling failed on pnmas {}", pnmas);
                    }
                }
            }
        }
    }
}
Also used : SappPnmas(org.openhab.binding.sapp.internal.model.SappPnmas) PollingResult(org.openhab.binding.sapp.internal.executer.SappCentralExecuter.PollingResult) SappBindingProvider(org.openhab.binding.sapp.SappBindingProvider) SappException(com.github.paolodenti.jsapp.core.command.base.SappException) SappCentralExecuter(org.openhab.binding.sapp.internal.executer.SappCentralExecuter)

Example 8 with SappException

use of com.github.paolodenti.jsapp.core.command.base.SappException in project openhab1-addons by openhab.

the class SappCentralExecuter method executePollingSappCommands.

/**
     * runs polling on virtuals, inputs, outputs
     */
public PollingResult executePollingSappCommands(String ip, int port) throws SappException {
    synchronized (this) {
        PollingResult pollingResult = new PollingResult();
        SappConnection sappConnection = null;
        try {
            sappConnection = new SappConnection(ip, port);
            sappConnection.openConnection();
            SappCommand sappCommand;
            sappCommand = new Sapp80Command();
            sappCommand.run(sappConnection);
            if (!sappCommand.isResponseOk()) {
                throw new SappException("Sapp80Command command execution failed");
            }
            pollingResult.changedOutputs = sappCommand.getResponse().getDataAsByteWordMap();
            sappCommand = new Sapp81Command();
            sappCommand.run(sappConnection);
            if (!sappCommand.isResponseOk()) {
                throw new SappException("Sapp81Command command execution failed");
            }
            pollingResult.changedInputs = sappCommand.getResponse().getDataAsByteWordMap();
            sappCommand = new Sapp82Command();
            sappCommand.run(sappConnection);
            if (!sappCommand.isResponseOk()) {
                throw new SappException("Sapp82Command command execution failed");
            }
            pollingResult.changedVirtuals = sappCommand.getResponse().getDataAsWordWordMap();
            return pollingResult;
        } catch (IOException e) {
            throw new SappException(e.getMessage());
        } finally {
            if (sappConnection != null) {
                sappConnection.closeConnection();
            }
        }
    }
}
Also used : SappCommand(com.github.paolodenti.jsapp.core.command.base.SappCommand) SappConnection(com.github.paolodenti.jsapp.core.command.base.SappConnection) Sapp82Command(com.github.paolodenti.jsapp.core.command.Sapp82Command) IOException(java.io.IOException) Sapp80Command(com.github.paolodenti.jsapp.core.command.Sapp80Command) SappException(com.github.paolodenti.jsapp.core.command.base.SappException) Sapp81Command(com.github.paolodenti.jsapp.core.command.Sapp81Command)

Aggregations

SappException (com.github.paolodenti.jsapp.core.command.base.SappException)8 SappCommand (com.github.paolodenti.jsapp.core.command.base.SappCommand)5 SappBindingProvider (org.openhab.binding.sapp.SappBindingProvider)2 SappCentralExecuter (org.openhab.binding.sapp.internal.executer.SappCentralExecuter)2 SappPnmas (org.openhab.binding.sapp.internal.model.SappPnmas)2 DecimalType (org.openhab.core.library.types.DecimalType)2 Sapp74Command (com.github.paolodenti.jsapp.core.command.Sapp74Command)1 Sapp75Command (com.github.paolodenti.jsapp.core.command.Sapp75Command)1 Sapp7CCommand (com.github.paolodenti.jsapp.core.command.Sapp7CCommand)1 Sapp7DCommand (com.github.paolodenti.jsapp.core.command.Sapp7DCommand)1 Sapp80Command (com.github.paolodenti.jsapp.core.command.Sapp80Command)1 Sapp81Command (com.github.paolodenti.jsapp.core.command.Sapp81Command)1 Sapp82Command (com.github.paolodenti.jsapp.core.command.Sapp82Command)1 SappConnection (com.github.paolodenti.jsapp.core.command.base.SappConnection)1 IOException (java.io.IOException)1 SappBindingConfigContactItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigContactItem)1 SappBindingConfigDimmerItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigDimmerItem)1 SappBindingConfigNumberItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigNumberItem)1 SappBindingConfigRollershutterItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigRollershutterItem)1 SappBindingConfigSwitchItem (org.openhab.binding.sapp.internal.configs.SappBindingConfigSwitchItem)1