logger.error("NODE {}: Got error {}, while identifying node", this.node.getNodeId(), e.getLocalizedMessage());
}
break;
case PROTOINFO:
if (this.node.getNodeId() != this.controller.getOwnNodeId()) {
ZWaveNoOperationCommandClass zwaveCommandClass = (ZWaveNoOperationCommandClass) this.node
.getCommandClass(CommandClass.NO_OPERATION);
if (zwaveCommandClass == null)
break;
this.node.setNodeStage(NodeStage.PING);
this.controller.sendData(zwaveCommandClass.getNoOperationMessage());
} else {
logger.debug("NODE {}: Initialisation complete.", this.node.getNodeId());
initializationComplete = true;
this.node.setNodeStage(NodeStage.DONE); // nothing
// more
// to
// do
// for
// this
// node.
}
break;
case PING:
case WAKEUP:
// if restored from a config file, redo from the dynamic
// node stage.
if (this.isRestoredFromConfigfile()) {
this.node.setNodeStage(NodeStage.DYNAMIC);
advanceNodeStage(NodeStage.DONE);
break;
}
this.node.setNodeStage(NodeStage.DETAILS);
this.controller.requestNodeInfo(this.node.getNodeId());
break;
case DETAILS:
// try and get the manufacturerSpecific command class.
ZWaveManufacturerSpecificCommandClass manufacturerSpecific = (ZWaveManufacturerSpecificCommandClass) this.node
.getCommandClass(CommandClass.MANUFACTURER_SPECIFIC);
if (manufacturerSpecific != null) {
// if this node implements the Manufacturer Specific command
// class, we use it to get manufacturer info.
this.node.setNodeStage(NodeStage.MANSPEC01);
this.controller.sendData(manufacturerSpecific.getManufacturerSpecificMessage());
break;
}
logger.warn("NODE {}: does not support MANUFACTURER_SPECIFIC, proceeding to version node stage.",
this.node.getNodeId());
case MANSPEC01:
this.node.setNodeStage(NodeStage.VERSION);
// try and get the version command class.
ZWaveVersionCommandClass version = (ZWaveVersionCommandClass) this.node
.getCommandClass(CommandClass.VERSION);
boolean checkVersionCalled = false;
for (ZWaveCommandClass zwaveCommandClass : this.node.getCommandClasses()) {
if (version != null && zwaveCommandClass.getMaxVersion() > 1) {
version.checkVersion(zwaveCommandClass); // check version
// for this
// command
// class.
checkVersionCalled = true;
} else
zwaveCommandClass.setVersion(1);
}
if (checkVersionCalled) // wait for another call of advanceNodeStage
// before continuing.
break;
case VERSION:
this.node.setNodeStage(NodeStage.INSTANCES_ENDPOINTS);
// try and get the multi instance / channel command class.
ZWaveMultiInstanceCommandClass multiInstance = (ZWaveMultiInstanceCommandClass) this.node
.getCommandClass(CommandClass.MULTI_INSTANCE);
if (multiInstance != null) {
multiInstance.initEndpoints();
break;
}
logger.trace("NODE {}: does not support MULTI_INSTANCE, proceeding to static node stage.",
this.node.getNodeId());
case INSTANCES_ENDPOINTS:
this.node.setNodeStage(NodeStage.STATIC_VALUES);
case STATIC_VALUES:
if (queriesPending == -1) {
queriesPending = 0;
for (ZWaveCommandClass zwaveCommandClass : this.node.getCommandClasses()) {
logger.trace("NODE {}: Inspecting command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass().getLabel());
if (zwaveCommandClass instanceof ZWaveCommandClassInitialization) {
logger.debug("NODE {}: Found initializable command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass()
.getLabel());
ZWaveCommandClassInitialization zcci = (ZWaveCommandClassInitialization) zwaveCommandClass;
int instances = zwaveCommandClass.getInstances();
if (instances == 0) {
Collection<SerialMessage> initqueries = zcci.initialize();
for (SerialMessage serialMessage : initqueries) {
this.controller.sendData(serialMessage);
queriesPending++;
}
} else {
for (int i = 1; i <= instances; i++) {
Collection<SerialMessage> initqueries = zcci.initialize();
for (SerialMessage serialMessage : initqueries) {
this.controller
.sendData(this.node.encapsulate(serialMessage, zwaveCommandClass, i));
queriesPending++;
}
}
}
} else if (zwaveCommandClass instanceof ZWaveMultiInstanceCommandClass) {
ZWaveMultiInstanceCommandClass multiInstanceCommandClass = (ZWaveMultiInstanceCommandClass) zwaveCommandClass;
for (ZWaveEndpoint endpoint : multiInstanceCommandClass.getEndpoints()) {
for (ZWaveCommandClass endpointCommandClass : endpoint.getCommandClasses()) {
logger.trace(String.format("NODE %d: Inspecting command class %s for endpoint %d", this.node.getNodeId(), endpointCommandClass
.getCommandClass().getLabel(), endpoint.getEndpointId()));
if (endpointCommandClass instanceof ZWaveCommandClassInitialization) {
logger.debug("NODE {}: Found initializable command class {}", this.node.getNodeId(), endpointCommandClass
.getCommandClass().getLabel());
ZWaveCommandClassInitialization zcci2 = (ZWaveCommandClassInitialization) endpointCommandClass;
Collection<SerialMessage> initqueries = zcci2.initialize();
for (SerialMessage serialMessage : initqueries) {
this.controller.sendData(this.node.encapsulate(serialMessage,
endpointCommandClass, endpoint.getEndpointId()));
queriesPending++;
}
}
}
}
}
}
}
if (queriesPending-- > 0) // there is still something to be
// initialized.
break;
logger.trace("NODE {}: Done getting static values, proceeding to dynamic node stage.", this.node.getNodeId());
queriesPending = -1;
this.node.setNodeStage(NodeStage.DYNAMIC);
case DYNAMIC:
if (queriesPending == -1) {
queriesPending = 0;
for (ZWaveCommandClass zwaveCommandClass : this.node.getCommandClasses()) {
logger.trace("NODE {}: Inspecting command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass().getLabel());
if (zwaveCommandClass instanceof ZWaveCommandClassDynamicState) {
logger.debug("NODE {}: Found dynamic state command class {}", this.node.getNodeId(), zwaveCommandClass.getCommandClass()
.getLabel());
ZWaveCommandClassDynamicState zdds = (ZWaveCommandClassDynamicState) zwaveCommandClass;
int instances = zwaveCommandClass.getInstances();
if (instances == 0) {
Collection<SerialMessage> dynamicQueries = zdds.getDynamicValues();
for (SerialMessage serialMessage : dynamicQueries) {
this.controller.sendData(serialMessage);
queriesPending++;