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;
}
}
}
Aggregations