Search in sources :

Example 11 with ZWaveNetworkEvent

use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent 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)

Example 12 with ZWaveNetworkEvent

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

the class ZWaveAssociationCommandClass method processAssociationReport.

/**
     * Processes a CONFIGURATIONCMD_REPORT / CONFIGURATIONCMD_SET message.
     *
     * @param serialMessage
     *            the incoming message to process.
     * @param offset
     *            the offset position from which to start message processing.
     */
protected void processAssociationReport(SerialMessage serialMessage, int offset) {
    // Extract the group index
    int group = serialMessage.getMessagePayloadByte(offset + 1);
    // The max associations supported (0 if the requested group is not supported)
    int maxAssociations = serialMessage.getMessagePayloadByte(offset + 2);
    // Number of outstanding requests (if the group is large, it may come in multiple frames)
    int following = serialMessage.getMessagePayloadByte(offset + 3);
    if (maxAssociations == 0) {
        // Unsupported association group. Nothing to do!
        if (updateAssociationsNode == group) {
            logger.debug("NODE {}: All association groups acquired.", this.getNode().getNodeId());
            updateAssociationsNode = 0;
            // This is used for network management, so send a network event
            this.getController().notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssociationUpdate, this.getNode().getNodeId(), ZWaveNetworkEvent.State.Success));
        }
        return;
    }
    logger.debug("NODE {}: association group {} has max associations " + maxAssociations, this.getNode().getNodeId(), group);
    // Are we waiting to synchronise the start of a new group?
    if (pendingAssociation == null) {
        pendingAssociation = new AssociationGroup(group);
    }
    if (serialMessage.getMessagePayload().length > (offset + 4)) {
        logger.debug("NODE {}: association group {} includes the following nodes:", this.getNode().getNodeId(), group);
        int numAssociations = serialMessage.getMessagePayload().length - (offset + 4);
        for (int cnt = 0; cnt < numAssociations; cnt++) {
            int node = serialMessage.getMessagePayloadByte(offset + 4 + cnt);
            logger.debug("Node {}", node);
            // Add the node to the group
            pendingAssociation.addNode(node);
        }
    }
    // If this is the end of the group, update the list then let the listeners know
    if (following == 0) {
        // Clear the current information for this group
        configAssociations.remove(group);
        // Update the group in the list
        configAssociations.put(group, pendingAssociation);
        pendingAssociation = null;
        // Send an event to the users
        ZWaveAssociationEvent zEvent = new ZWaveAssociationEvent(this.getNode().getNodeId(), group);
        List<Integer> members = getGroupMembers(group);
        if (members != null) {
            for (int node : members) {
                zEvent.addMember(node);
            }
        }
        this.getController().notifyEventListeners(zEvent);
    }
    // Is this the end of the list
    if (following == 0 && group == updateAssociationsNode) {
        // so we need to request the next group
        if (updateAssociationsNode < maxGroups) {
            updateAssociationsNode++;
            SerialMessage outputMessage = getAssociationMessage(updateAssociationsNode);
            if (outputMessage != null) {
                this.getController().sendData(outputMessage);
            }
        } else {
            logger.debug("NODE {}: All association groups acquired.", this.getNode().getNodeId());
            // we have reached our maxNodes, notify listeners we are done.
            updateAssociationsNode = 0;
            // This is used for network management, so send a network event
            this.getController().notifyEventListeners(new ZWaveNetworkEvent(ZWaveNetworkEvent.Type.AssociationUpdate, this.getNode().getNodeId(), ZWaveNetworkEvent.State.Success));
        }
    }
}
Also used : ZWaveNetworkEvent(org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent) AssociationGroup(org.openhab.binding.zwave.internal.protocol.AssociationGroup) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ZWaveEndpoint(org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)

Aggregations

ZWaveNetworkEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNetworkEvent)12 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)2 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)2 ZWaveNodeStatusEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent)2 ArrayList (java.util.ArrayList)1 AssociationGroup (org.openhab.binding.zwave.internal.protocol.AssociationGroup)1 ZWaveEndpoint (org.openhab.binding.zwave.internal.protocol.ZWaveEndpoint)1 ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)1 ZWaveInclusionEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveInclusionEvent)1 ZWaveInitializationCompletedEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveInitializationCompletedEvent)1 ZWaveTransactionCompletedEvent (org.openhab.binding.zwave.internal.protocol.event.ZWaveTransactionCompletedEvent)1 ZWaveNodeSerializer (org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer)1