Search in sources :

Example 6 with ZWaveInclusionEvent

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

the class ZWaveController method notifyEventListeners.

/**
     * Notify our own event listeners of a Z-Wave event.
     *
     * @param event the event to send.
     */
public void notifyEventListeners(ZWaveEvent event) {
    logger.debug("NODE {}: Notifying event listeners: {}", event.getNodeId(), event.getClass().getSimpleName());
    ArrayList<ZWaveEventListener> copy = new ArrayList<ZWaveEventListener>(this.zwaveEventListeners);
    for (ZWaveEventListener listener : copy) {
        listener.ZWaveIncomingEvent(event);
    }
    // We also need to handle the inclusion internally within the controller
    if (event instanceof ZWaveInclusionEvent) {
        ZWaveInclusionEvent incEvent = (ZWaveInclusionEvent) event;
        switch(incEvent.getEvent()) {
            case // TODO: DB any potential negative consequences by changing from IncludeDone to
            IncludeSlaveFound:
                // IncludeSlaveFound?
                // Trigger by IncludeSlaveFound since security based devices need the initial exchange to take place
                // immediately or they will time out
                logger.debug("NODE {}: Including node.", incEvent.getNodeId());
                // First make sure this isn't an existing node
                if (getNode(incEvent.getNodeId()) != null) {
                    logger.debug("NODE {}: Newly included node already exists - not initialising.", incEvent.getNodeId());
                    break;
                }
                this.lastIncludeSlaveFoundEvent = incEvent;
                // Initialise the new node
                addNode(incEvent.getNodeId());
                break;
            case ExcludeDone:
                logger.debug("NODE {}: Excluding node.", incEvent.getNodeId());
                // Remove the node from the controller
                if (getNode(incEvent.getNodeId()) == null) {
                    logger.debug("NODE {}: Excluding node that doesn't exist.", incEvent.getNodeId());
                    break;
                }
                this.zwaveNodes.remove(incEvent.getNodeId());
                // Remove the XML file
                ZWaveNodeSerializer nodeSerializer = new ZWaveNodeSerializer();
                nodeSerializer.DeleteNode(event.getNodeId());
                break;
            default:
                break;
        }
    } else if (event instanceof ZWaveNetworkEvent) {
        ZWaveNetworkEvent networkEvent = (ZWaveNetworkEvent) event;
        switch(networkEvent.getEvent()) {
            case DeleteNode:
                if (getNode(networkEvent.getNodeId()) == null) {
                    logger.debug("NODE {}: Deleting a node that doesn't exist.", networkEvent.getNodeId());
                    break;
                }
                this.zwaveNodes.remove(networkEvent.getNodeId());
                // Remove the XML file
                ZWaveNodeSerializer nodeSerializer = new ZWaveNodeSerializer();
                nodeSerializer.DeleteNode(event.getNodeId());
                break;
            default:
                break;
        }
    } else if (event instanceof ZWaveNodeStatusEvent) {
        ZWaveNodeStatusEvent statusEvent = (ZWaveNodeStatusEvent) event;
        logger.debug("NODE {}: Node Status event - Node is {}", statusEvent.getNodeId(), statusEvent.getState());
        // Get the node
        ZWaveNode node = getNode(event.getNodeId());
        if (node == null) {
            logger.error("NODE {}: Node is unknown!", statusEvent.getNodeId());
            return;
        }
        // Handle node state changes
        switch(statusEvent.getState()) {
            case DEAD:
                break;
            case FAILED:
                break;
            case ALIVE:
                break;
        }
    }
}
Also used : ZWaveNodeStatusEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent) ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent) ZWaveNodeSerializer(org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer) ZWaveInclusionEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveInclusionEvent) ArrayList(java.util.ArrayList)

Aggregations

ZWaveInclusionEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveInclusionEvent)6 ArrayList (java.util.ArrayList)2 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)2 ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)2 ZWaveNodeSerializer (org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer)2 ZWaveAssociationEvent (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass.ZWaveAssociationEvent)1 ZWaveCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass)1 CommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass.CommandClass)1 ZWaveConfigurationParameterEvent (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveConfigurationCommandClass.ZWaveConfigurationParameterEvent)1 ZWaveSwitchAllCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSwitchAllCommandClass)1 ZWaveNetworkEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)1 ZWaveNodeInfoEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeInfoEvent)1 ZWaveNodeStatusEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent)1