Search in sources :

Example 1 with ZWaveController

use of org.openhab.binding.zwave.internal.protocol.ZWaveController in project openhab1-addons by openhab.

the class ZWaveActiveBinding method initialise.

/**
     * Initialises the binding. This is called after the 'updated' method
     * has been called and all configuration has been passed.
     *
     * @throws ConfigurationException
     */
private void initialise() throws ConfigurationException {
    try {
        logger.debug("Initialising zwave binding");
        this.setProperlyConfigured(true);
        this.deactivate();
        this.zController = new ZWaveController(masterController, isSUC, port, timeout, softReset);
        this.converterHandler = new ZWaveConverterHandler(this.zController, this.eventPublisher);
        zController.addEventListener(this);
        // The network monitor service needs to know the controller...
        this.networkMonitor = new ZWaveNetworkMonitor(this.zController);
        if (healtime != null) {
            this.networkMonitor.setHealTime(healtime);
        }
        if (aliveCheckPeriod != null) {
            this.networkMonitor.setPollPeriod(aliveCheckPeriod);
        }
        if (softReset != false) {
            this.networkMonitor.resetOnError(softReset);
        }
        // The config service needs to know the controller and the network monitor...
        this.zConfigurationService = new ZWaveConfiguration(this.zController, this.networkMonitor);
        zController.addEventListener(this.zConfigurationService);
        return;
    } catch (SerialInterfaceException ex) {
        this.setProperlyConfigured(false);
        throw new ConfigurationException("port", ex.getLocalizedMessage(), ex);
    }
}
Also used : ZWaveConverterHandler(org.openhab.binding.zwave.internal.converter.ZWaveConverterHandler) ConfigurationException(org.osgi.service.cm.ConfigurationException) ZWaveController(org.openhab.binding.zwave.internal.protocol.ZWaveController) ZWaveConfiguration(org.openhab.binding.zwave.internal.config.ZWaveConfiguration) SerialInterfaceException(org.openhab.binding.zwave.internal.protocol.SerialInterfaceException)

Example 2 with ZWaveController

use of org.openhab.binding.zwave.internal.protocol.ZWaveController in project openhab1-addons by openhab.

the class ZWaveActiveBinding method deactivate.

/**
     * Deactivates the binding. The Controller is stopped and the serial interface
     * is closed as well.
     */
@Override
public void deactivate() {
    if (this.converterHandler != null) {
        this.converterHandler = null;
    }
    if (this.zConfigurationService != null) {
        this.zController.removeEventListener(this.zConfigurationService);
        this.zConfigurationService = null;
    }
    ZWaveController controller = this.zController;
    if (controller != null) {
        this.zController = null;
        controller.close();
        controller.removeEventListener(this);
    }
}
Also used : ZWaveController(org.openhab.binding.zwave.internal.protocol.ZWaveController)

Example 3 with ZWaveController

use of org.openhab.binding.zwave.internal.protocol.ZWaveController in project openhab1-addons by openhab.

the class ZWaveApplicationStatusClass method handleApplicationCommandRequest.

/**
     * {@inheritDoc}
     */
@Override
public void handleApplicationCommandRequest(SerialMessage serialMessage, int offset, int endpoint) {
    logger.debug("NODE {}: Application Status message", getNode());
    int status = serialMessage.getMessagePayloadByte(offset++);
    switch(status) {
        case ApplicationStatusBusy:
            logger.trace("NODE {}: Process Application Status Busy status", getNode());
            int busyStatus = serialMessage.getMessagePayloadByte(offset++);
            int retry = DEFAULT_RETRY;
            switch(busyStatus) {
                case StatusBusyTryAgainLaterInSeconds:
                    int seconds = serialMessage.getMessagePayloadByte(offset++);
                    logger.debug("NODE {}: is busy and wants us to try again in {} seconds", getNode(), seconds);
                    retry = seconds * 1000;
                case StatusBusyTryAgainLater:
                    logger.debug("NODE {}: is busy and wants us to try again later", getNode());
                    final ZWaveNode node = this.getNode();
                    final ZWaveController controller = this.getController();
                    scheduler.schedule(new Runnable() {

                        @Override
                        public void run() {
                            if (node == null || node.getNodeState() != ZWaveNodeState.ALIVE) {
                                return;
                            }
                            controller.pollNode(node);
                        }
                    }, retry, TimeUnit.MILLISECONDS);
                    break;
                case StatusBusyQueued:
                    logger.warn("NODE {}: is busy and has queued the request", getNode());
                    break;
                default:
                    logger.warn("NODE {}: unknown busy status {} ", getNode(), busyStatus);
                    break;
            }
            break;
        case ApplicationStatusRejected:
            logger.warn("NODE {}: has rejected the request", getNode());
            break;
        default:
            logger.warn(String.format("Unsupported status 0x%02X for command class %s (0x%02X).", status, this.getCommandClass().getLabel(), this.getCommandClass().getKey()));
    }
}
Also used : ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveController(org.openhab.binding.zwave.internal.protocol.ZWaveController) ZWaveEndpoint(org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)

Aggregations

ZWaveController (org.openhab.binding.zwave.internal.protocol.ZWaveController)3 ZWaveConfiguration (org.openhab.binding.zwave.internal.config.ZWaveConfiguration)1 ZWaveConverterHandler (org.openhab.binding.zwave.internal.converter.ZWaveConverterHandler)1 SerialInterfaceException (org.openhab.binding.zwave.internal.protocol.SerialInterfaceException)1 ZWaveEndpoint (org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)1 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1