nodeNumber = nodeNumber.substring(0, next);
}
int nodeId = Integer.parseInt(nodeNumber);
// Return the detailed configuration for this node
ZWaveNode node = zController.getNode(nodeId);
if (node == null)
return null;
// Open the product database
ZWaveProductDatabase database = new ZWaveProductDatabase();
// Process the request
if (arg.equals("")) {
record = new OpenHABConfigurationRecord(domain, "Name", "Name", false);
record.value = node.getName();
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Location", "Location", false);
record.value = node.getLocation();
records.add(record);
if(node.getManufacturer() != Integer.MAX_VALUE) {
if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) == true) {
// Add links to configuration if the node supports the various command classes
if(database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.CONFIGURATION.getKey()) == true) {
record = new OpenHABConfigurationRecord(domain + "parameters/", "Configuration Parameters");
record.addAction("Refresh", "Refresh");
records.add(record);
}
if(database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey()) == true) {
record = new OpenHABConfigurationRecord(domain + "associations/", "Association Groups");
record.addAction("Refresh", "Refresh");
records.add(record);
}
if(database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.WAKE_UP.getKey()) == true) {
record = new OpenHABConfigurationRecord(domain + "wakeup/", "Wakeup Period");
record.addAction("Refresh", "Refresh");
records.add(record);
}
}
}
// Is this a controller
if(nodeId == zController.getOwnNodeId()) {
record = new OpenHABConfigurationRecord(domain + "controller/", "Controller");
records.add(record);
}
record = new OpenHABConfigurationRecord(domain + "neighbors/", "Neighbors");
record.addAction("Refresh", "Refresh");
records.add(record);
record = new OpenHABConfigurationRecord(domain + "status/", "Status");
records.add(record);
record = new OpenHABConfigurationRecord(domain + "info/", "Information");
records.add(record);
} else if (arg.equals("info/")) {
if (node.getManufacturer() != Integer.MAX_VALUE) {
if (database.FindManufacturer(node.getManufacturer()) == true) {
record = new OpenHABConfigurationRecord(domain, "Manufacturer", "Manufacturer", true);
record.value = database.getManufacturerName();
records.add(record);
}
if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) == true) {
record = new OpenHABConfigurationRecord(domain, "Product", "Product", true);
record.value = database.getProductName();
records.add(record);
}
}
record = new OpenHABConfigurationRecord(domain, "ManufacturerID", "Manufacturer ID", true);
if(node.getDeviceId() == Integer.MAX_VALUE) {
record.value = "UNKNOWN";
}
else {
record.value = Integer.toHexString(node.getManufacturer());
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "DeviceID", "Device ID", true);
if(node.getDeviceId() == Integer.MAX_VALUE) {
record.value = "UNKNOWN";
}
else {
record.value = Integer.toHexString(node.getDeviceId());
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "DeviceType", "Device Type", true);
if(node.getDeviceId() == Integer.MAX_VALUE) {
record.value = "UNKNOWN";
}
else {
record.value = Integer.toHexString(node.getDeviceType());
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Version", "Version", true);
record.value = Integer.toString(node.getVersion());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Listening", "Listening", true);
record.value = Boolean.toString(node.isListening());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Routing", "Routing", true);
record.value = Boolean.toString(node.isRouting());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Power", "Power", true);
ZWaveBatteryCommandClass batteryCommandClass = (ZWaveBatteryCommandClass) node
.getCommandClass(CommandClass.BATTERY);
if (batteryCommandClass != null) {
if(batteryCommandClass.getBatteryLevel() == null) {
record.value = "BATTERY " + "UNKNOWN";
}
else {
record.value = "BATTERY " + batteryCommandClass.getBatteryLevel() + "%";
}
} else {
record.value = "MAINS";
}
records.add(record);
ZWaveVersionCommandClass versionCommandClass = (ZWaveVersionCommandClass) node
.getCommandClass(CommandClass.VERSION);
if (versionCommandClass != null) {
record = new OpenHABConfigurationRecord(domain, "LibType", "Library Type", true);
if (versionCommandClass.getLibraryType() == null)
record.value = "Unknown";
else
record.value = versionCommandClass.getLibraryType().getLabel();
records.add(record);
record = new OpenHABConfigurationRecord(domain, "ProtocolVersion", "Protocol Version", true);
if (versionCommandClass.getProtocolVersion() == null)
record.value = "Unknown";
else
record.value = Double.toString(versionCommandClass.getProtocolVersion());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "AppVersion", "Application Version", true);
if (versionCommandClass.getApplicationVersion() == null)
record.value = "Unknown";
else
record.value = Double.toString(versionCommandClass.getApplicationVersion());
records.add(record);
}
ZWaveDeviceClass devClass = node.getDeviceClass();
if (devClass != null) {
record = new OpenHABConfigurationRecord(domain, "BasicClass", "Basic Device Class", true);
record.value = devClass.getBasicDeviceClass().toString();
records.add(record);
record = new OpenHABConfigurationRecord(domain, "GenericClass", "Generic Device Class", true);
record.value = devClass.getGenericDeviceClass().toString();
records.add(record);
record = new OpenHABConfigurationRecord(domain, "SpecificClass", "Specific Device Class", true);
record.value = devClass.getSpecificDeviceClass().toString();
records.add(record);
}
} else if (arg.equals("status/")) {
record = new OpenHABConfigurationRecord(domain, "LastSent", "Last Packet Sent", true);
if(node.getLastSent() == null) {
record.value = "NEVER";
}
else {
record.value = df.format(node.getLastSent());
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "LastReceived", "Last Packet Received", true);
if(node.getLastReceived() == null) {
record.value = "NEVER";
}
else {
record.value = df.format(node.getLastReceived());
}
records.add(record);
if(networkMonitor != null) {
record = new OpenHABConfigurationRecord(domain, "LastHeal", "Heal Status", true);
if (node.getHealState() == null)
record.value = networkMonitor.getNodeState(nodeId);
else
record.value = node.getHealState();
records.add(record);
}
record = new OpenHABConfigurationRecord(domain, "NodeStage", "Node Stage", true);
record.value = node.getNodeStage() + " @ " + df.format(node.getQueryStageTimeStamp());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Packets", "Packet Statistics", true);
record.value = node.getRetryCount() + " / " + node.getSendCount();
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Dead", "Dead", true);
if(node.getDeadCount() == 0) {
record.value = Boolean.toString(node.isDead());
}
else {
record.value = Boolean.toString(node.isDead()) + " [" + node.getDeadCount() + " previous - last @ " + df.format(node.getDeadTime()) + "]";
}
records.add(record);
} else if (arg.equals("parameters/")) {
if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) != false) {
List<ZWaveDbConfigurationParameter> configList = database.getProductConfigParameters();
if(configList == null)
return records;
// Get the configuration command class for this node
ZWaveConfigurationCommandClass configurationCommandClass = (ZWaveConfigurationCommandClass) node
.getCommandClass(CommandClass.CONFIGURATION);
if (configurationCommandClass == null) {
logger.error("NODE {}: Error getting configurationCommandClass", nodeId);
return null;
}
// Loop through the parameters and add to the records...
for (ZWaveDbConfigurationParameter parameter : configList) {
record = new OpenHABConfigurationRecord(domain, "configuration" + parameter.Index,
parameter.Index + ": " + database.getLabel(parameter.Label), false);
ConfigurationParameter configurationParameter = configurationCommandClass
.getParameter(parameter.Index);
// Only provide a value if it's stored in the node
// This is the only way we can be sure of its real value
if (configurationParameter != null)
record.value = Integer.toString(configurationParameter.getValue());
// If the value is in our PENDING list, then use that instead
Integer pendingValue = PendingCfg.Get(ZWaveCommandClass.CommandClass.CONFIGURATION.getKey(), nodeId, parameter.Index);
if(pendingValue != null) {
record.value = Integer.toString(pendingValue);
record.state = OpenHABConfigurationRecord.STATE.PENDING;
}
try {
record.type = OpenHABConfigurationRecord.TYPE.valueOf(parameter.Type.toUpperCase());
} catch(IllegalArgumentException e) {
record.type = OpenHABConfigurationRecord.TYPE.LONG;
}
if(parameter.Item != null) {
for (ZWaveDbConfigurationListItem item : parameter.Item)
record.addValue(Integer.toString(item.Value), database.getLabel(item.Label));
}
// Add any limits
record.minimum = parameter.Minimum;
record.maximum = parameter.Maximum;
// Add the description
record.description = database.getLabel(parameter.Help);
records.add(record);
}
}
} else if (arg.equals("associations/")) {
if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) != false) {
List<ZWaveDbAssociationGroup> groupList = database.getProductAssociationGroups();
if (groupList != null) {
// Loop through the associations and add all groups to the
// records...
for (ZWaveDbAssociationGroup group : groupList) {
// TODO: Controller reporting associations are set to read only
record = new OpenHABConfigurationRecord(domain, "association" + group.Index + "/",
database.getLabel(group.Label), true);
// Add the description
record.description = database.getLabel(group.Help);
// For the 'value', describe how many devices are set and the maximum allowed
ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) node
.getCommandClass(CommandClass.ASSOCIATION);
int memberCnt = 0;
List<Integer> members = associationCommandClass.getGroupMembers(group.Index);
if(members != null)
memberCnt = members.size();
record.value = memberCnt + " of " + group.Maximum + " group members";
// Add the action for refresh
record.addAction("Refresh", "Refresh");
records.add(record);
}
}
}
} else if (arg.startsWith("associations/association")) {
if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId()) != false) {
String groupString = arg.substring(24);
int nextDelimiter = groupString.indexOf('/');
// String arg = null;
if (nextDelimiter != -1) {
// arg = nodeNumber.substring(nextDelimiter + 1);
groupString = groupString.substring(0, nextDelimiter);
}
int groupId = Integer.parseInt(groupString);
// Get the requested group so we have access to the
// attributes
List<ZWaveDbAssociationGroup> groupList = database.getProductAssociationGroups();
if (groupList == null)
return null;
ZWaveDbAssociationGroup group = null;
for (int cnt = 0; cnt < groupList.size(); cnt++) {
if (groupList.get(cnt).Index == groupId) {
group = groupList.get(cnt);
break;
}
}
// Return if the group wasn't found
if (group == null)
return null;
// Get the group members
ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) node
.getCommandClass(CommandClass.ASSOCIATION);
List<Integer> members = associationCommandClass.getGroupMembers(groupId);
for(ZWaveNode nodeList : zController.getNodes()) {
// Don't allow an association with itself
if(nodeList.getNodeId() == node.getNodeId())
continue;
// Add the member
if (nodeList.getName() == null || nodeList.getName().isEmpty())
record = new OpenHABConfigurationRecord(domain, "node" + nodeList.getNodeId(), "Node " + nodeList.getNodeId(), false);
else
record = new OpenHABConfigurationRecord(domain, "node" + nodeList.getNodeId(), nodeList.getName(), false);
record.type = OpenHABConfigurationRecord.TYPE.LIST;
record.addValue("true", "Member");
record.addValue("false", "Non-Member");
if (members != null && members.contains(nodeList.getNodeId())) {
record.value = "true";
} else {
record.value = "false";
}
// If the value is in our PENDING list, then use that instead
Integer pendingValue = PendingCfg.Get(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey(), nodeId, groupId, nodeList.getNodeId());
if(pendingValue != null) {
if(pendingValue == 1)
record.value = "true";
else
record.value = "false";
record.state = OpenHABConfigurationRecord.STATE.PENDING;
}
records.add(record);
}
}
} else if (arg.equals("wakeup/")) {
ZWaveWakeUpCommandClass wakeupCommandClass = (ZWaveWakeUpCommandClass) node
.getCommandClass(CommandClass.WAKE_UP);
if(wakeupCommandClass == null) {
logger.error("NODE {}: Error getting wakeupCommandClass", nodeId);
return null;
}
// Display the wakeup parameters.
// Note that only the interval is writable.
record = new OpenHABConfigurationRecord(domain, "Interval", "Wakeup Interval", false);
record.minimum = wakeupCommandClass.getMinInterval();
record.maximum = wakeupCommandClass.getMaxInterval();
record.value = Integer.toString(wakeupCommandClass.getInterval());
// If the value is in our PENDING list, then use that instead
Integer pendingValue = PendingCfg.Get(ZWaveCommandClass.CommandClass.WAKE_UP.getKey(), nodeId);
if(pendingValue != null) {
record.value = Integer.toString(pendingValue);
record.state = OpenHABConfigurationRecord.STATE.PENDING;
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Minimum", "Minimum Interval", true);
record.value = Integer.toString(wakeupCommandClass.getMinInterval());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Maximum", "Maximum Interval", true);
record.value = Integer.toString(wakeupCommandClass.getMaxInterval());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Default", "Default Interval", true);
record.value = Integer.toString(wakeupCommandClass.getDefaultInterval());
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Step", "Interval Step", true);
record.value = Integer.toString(wakeupCommandClass.getIntervalStep());
records.add(record);
} else if (arg.equals("neighbors/")) {
// Check that we have the neighbor list for this node
if(node.getNeighbors() == null)
return null;
for (Integer neighbor : node.getNeighbors()) {
ZWaveNode nodeNeighbor = zController.getNode(neighbor);
String neighborName;
if (nodeNeighbor == null)
neighborName = "Node " + neighbor + " (UNKNOWN)";
else if (nodeNeighbor.getName() == null || nodeNeighbor.getName().isEmpty())
neighborName = "Node " + neighbor;
else
neighborName = nodeNeighbor.getName();
// Create the record
record = new OpenHABConfigurationRecord(domain, "node" + neighbor, neighborName, false);
record.readonly = true;