use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent in project openhab1-addons by openhab.
the class ZWaveNodeStageAdvancer method ZWaveIncomingEvent.
@Override
public void ZWaveIncomingEvent(ZWaveEvent event) {
// If we've already completed initialisation, then we're done!
if (currentStage == ZWaveNodeInitStage.DONE) {
return;
}
// Process transaction complete events
if (event instanceof ZWaveTransactionCompletedEvent) {
ZWaveTransactionCompletedEvent completeEvent = (ZWaveTransactionCompletedEvent) event;
SerialMessage serialMessage = completeEvent.getCompletedMessage();
byte[] payload = serialMessage.getMessagePayload();
// Make sure this is addressed to us
if (payload.length == 0 || node.getNodeId() != (payload[0] & 0xFF)) {
// This will allow battery devices stuck in WAIT state to get moving.
if (controller.getSendQueueLength() < 2 && currentStage == ZWaveNodeInitStage.WAIT) {
logger.debug("NODE {}: Node advancer - WAIT: The WAIT is over!", node.getNodeId());
currentStage = currentStage.getNextStage();
handleNodeQueue(null);
}
return;
}
switch(serialMessage.getMessageClass()) {
case SendData:
case IdentifyNode:
case RequestNodeInfo:
case GetRoutingInfo:
case IsFailedNodeID:
logger.debug("NODE {}: Node advancer - {}: Transaction complete ({}:{}) success({})", node.getNodeId(), currentStage.toString(), serialMessage.getMessageClass(), serialMessage.getMessageType(), completeEvent.getState());
// If this frame was successfully sent, then handle the stage advancer
if (((ZWaveTransactionCompletedEvent) event).getState() == true) {
handleNodeQueue(serialMessage);
}
break;
default:
break;
}
} else if (event instanceof ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) {
// WAKEUP EVENT - only act if this is a wakeup notification
if (((ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) event).getEvent() != ZWaveWakeUpCommandClass.WAKE_UP_NOTIFICATION) {
return;
}
// A wakeup event is received. Make sure it's for this node
if (node.getNodeId() != event.getNodeId()) {
return;
}
logger.debug("NODE {}: Wakeup during initialisation.", node.getNodeId());
wakeupCount++;
advanceNodeStage(null);
} else if (event instanceof ZWaveNodeStatusEvent) {
ZWaveNodeStatusEvent statusEvent = (ZWaveNodeStatusEvent) event;
// A network status event is received. Make sure it's for this node.
if (node.getNodeId() != event.getNodeId()) {
return;
}
logger.debug("NODE {}: Node Status event during initialisation - Node is {}", statusEvent.getNodeId(), statusEvent.getState());
switch(statusEvent.getState()) {
case DEAD:
case FAILED:
break;
case ALIVE:
advanceNodeStage(null);
break;
}
logger.trace("NODE {}: Node Status event during initialisation processed", statusEvent.getNodeId());
} else if (event instanceof ZWaveNodeInfoEvent) {
logger.debug("NODE {}: {} NIF event during initialisation stage {}", event.getNodeId(), node.getNodeId(), currentStage);
if (node.getNodeId() != event.getNodeId()) {
return;
}
if (currentStage == ZWaveNodeInitStage.PING) {
logger.debug("NODE {}: NIF event during initialisation stage PING - advancing", event.getNodeId());
setCurrentStage(currentStage.getNextStage());
}
logger.debug("NODE {}: NIF event during initialisation stage {}", event.getNodeId(), currentStage);
advanceNodeStage(null);
/*
* } else if (event instanceof ZWaveCommandClassValueEvent) {
* // This code is used to detect an event during the IDLE stage.
* // This is used to kick start the initialisation for battery nodes that do not support
* // the WAKE_UP class and don't send the ApplicationUpdateMessage when they are initialised.
* logger.debug("NODE {}: {} CC event during initialisation stage {}", event.getNodeId(), node.getNodeId(),
* currentStage);
* // A command class event is received. Make sure it's for this node.
* if (node.getNodeId() != event.getNodeId() || currentStage != ZWaveNodeInitStage.PING) {
* return;
* }
* logger.debug("NODE {}: CC event during initialisation stage PING - advancing", event.getNodeId());
* setCurrentStage(currentStage.getNextStage());
* logger.debug("NODE {}: CC event during initialisation stage PING - now {} - next", event.getNodeId(),
* currentStage);
* advanceNodeStage(null);
*/
}
}
use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent in project openhab1-addons by openhab.
the class ZWaveNetworkMonitor method ZWaveIncomingEvent.
/**
* Capture events that might be useful during the heal process We need to
* know when a network event happens - these are specific events that are
* used in the heal process (routing etc). We need to know if a device wakes
* up so we can heal it (if needed) We need to know when a PING transaction
* completes.
*/
@Override
public void ZWaveIncomingEvent(ZWaveEvent event) {
// Handle network events
if (event instanceof ZWaveNetworkEvent) {
ZWaveNetworkEvent nwEvent = (ZWaveNetworkEvent) event;
// Get the heal class for this notification
HealNode node = healNodes.get(nwEvent.getNodeId());
if (node == null) {
return;
}
// Is this the event we're waiting for
if (nwEvent.getEvent() != node.event) {
return;
}
switch(nwEvent.getState()) {
case Success:
node.retryCnt = 0;
node.state = node.stateNext;
break;
case Failure:
logger.debug("NODE {}: Network heal received FAILURE event", node.nodeId);
break;
}
// been a successful route set - remove this node
if (node.retryCnt == 0 && node.routeList != null && node.routeList.size() > 0) {
node.routeList.remove(0);
}
// Continue....
nextHealStage(node);
} else if (event instanceof ZWaveTransactionCompletedEvent) {
SerialMessage serialMessage = ((ZWaveTransactionCompletedEvent) event).getCompletedMessage();
if (serialMessage.getMessageClass() != SerialMessageClass.SendData && serialMessage.getMessageType() != SerialMessageType.Request) {
return;
}
byte[] payload = serialMessage.getMessagePayload();
if (payload.length < 3) {
return;
}
HealNode node = healNodes.get(payload[0] & 0xFF);
if (node == null) {
return;
}
// See if this node is waiting for a PING
if (node.state == HealState.PING && payload.length >= 3 && (payload[2] & 0xFF) == ZWaveCommandClass.CommandClass.NO_OPERATION.getKey()) {
node.state = node.stateNext;
node.retryCnt = 0;
nextHealStage(node);
return;
}
} else if (event instanceof ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) {
// We only care about the wake-up notification
if (((ZWaveWakeUpCommandClass.ZWaveWakeUpEvent) event).getEvent() != ZWaveWakeUpCommandClass.WAKE_UP_NOTIFICATION) {
return;
}
// A wakeup event is received. Find the node in the node list
HealNode node = healNodes.get(event.getNodeId());
if (node == null) {
return;
}
// and only process if there's something to do
if (!node.state.isActive()) {
return;
}
logger.debug("NODE {}: Heal WakeUp EVENT {}", node.nodeId, node.state);
nextHealStage(node);
} else if (event instanceof ZWaveNodeStatusEvent) {
ZWaveNodeStatusEvent statusEvent = (ZWaveNodeStatusEvent) event;
logger.debug("NODE {}: Node Status event - Node is {}", statusEvent.getNodeId(), statusEvent.getState());
switch(statusEvent.getState()) {
case DEAD:
case FAILED:
ZWaveNode node = zController.getNode(statusEvent.getNodeId());
if (node == null) {
logger.error("NODE {}: Status event received, but node not found.", statusEvent.getNodeId());
return;
}
// If this is a DEAD notification, then ask the controller if it's really FAILED
if (statusEvent.getState() == ZWaveNodeState.DEAD) {
zController.requestIsFailedNode(node.getNodeId());
}
// The node is dead, but we may have already started a Heal
// If so, it won't be started again!
startNodeHeal(node.getNodeId());
break;
case ALIVE:
break;
}
} else if (event instanceof ZWaveInitializationCompletedEvent) {
logger.debug("Network initialised - starting network monitor.");
// Remember that we've initialised the binding.
initialised = true;
// Calculate the next heal time
networkHealNightlyTime = calculateNextHeal();
networkHealNextTime = networkHealNightlyTime;
// Set the next PING time
pingNodeTime = System.currentTimeMillis() + pollPeriod;
}
}
use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent 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;
}
}
}
use of org.openhab.binding.zwave.internal.protocol.event.ZWaveNodeStatusEvent in project openhab1-addons by openhab.
the class ZWaveNode method setNodeState.
/**
* Sets the node to be 'undead'.
*/
public void setNodeState(ZWaveNodeState state) {
// Make sure we only handle real state changes
if (state == nodeState) {
return;
}
switch(state) {
case ALIVE:
logger.debug("NODE {}: Node has risen from the DEAD. Init stage is {}:{}.", nodeId, this.getNodeInitializationStage().toString());
// Reset the resend counter
this.resendCount = 0;
break;
case DEAD:
// The only valid state change from FAILED is to ALIVE
if (nodeState == ZWaveNodeState.FAILED) {
return;
}
case FAILED:
this.deadCount++;
this.deadTime = Calendar.getInstance().getTime();
logger.debug("NODE {}: Node is DEAD.", this.nodeId);
break;
}
// Don't alert state changes while we're still initialising
if (nodeStageAdvancer.isInitializationComplete() == true) {
ZWaveEvent zEvent = new ZWaveNodeStatusEvent(this.getNodeId(), ZWaveNodeState.DEAD);
controller.notifyEventListeners(zEvent);
} else {
logger.debug("NODE {}: Initialisation incomplete, not signalling state change.", this.nodeId);
}
nodeState = state;
}
Aggregations