Search in sources :

Example 1 with PollingResult

use of org.openhab.binding.sapp.internal.executer.SappCentralExecuter.PollingResult 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)

Aggregations

SappException (com.github.paolodenti.jsapp.core.command.base.SappException)1 SappBindingProvider (org.openhab.binding.sapp.SappBindingProvider)1 SappCentralExecuter (org.openhab.binding.sapp.internal.executer.SappCentralExecuter)1 PollingResult (org.openhab.binding.sapp.internal.executer.SappCentralExecuter.PollingResult)1 SappPnmas (org.openhab.binding.sapp.internal.model.SappPnmas)1