use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter in project openhab1-addons by openhab.
the class ZWaveConfiguration method getConfiguration.
@Override
public List<OpenHABConfigurationRecord> getConfiguration(String domain) {
// We only deal with top level domains here!
if (domain.endsWith("/") == false) {
logger.error("Malformed domain request in getConfiguration '{}'", domain);
return null;
}
List<OpenHABConfigurationRecord> records = new ArrayList<OpenHABConfigurationRecord>();
OpenHABConfigurationRecord record;
if (domain.equals("status/")) {
return null;
}
if (domain.startsWith("products/")) {
ZWaveProductDatabase database = new ZWaveProductDatabase();
String[] splitDomain = domain.split("/");
switch(splitDomain.length) {
case 1:
// Just list the manufacturers
for (ZWaveDbManufacturer manufacturer : database.GetManufacturers()) {
record = new OpenHABConfigurationRecord(domain + manufacturer.Id.toString() + "/", manufacturer.Name);
records.add(record);
}
break;
case 2:
// Get products list
if (database.FindManufacturer(Integer.parseInt(splitDomain[1])) == false) {
break;
}
record = new OpenHABConfigurationRecord(domain, "ManufacturerID", "Manufacturer ID", true);
record.value = Integer.toHexString(database.getManufacturerId());
records.add(record);
for (ZWaveDbProduct product : database.GetProducts()) {
record = new OpenHABConfigurationRecord(domain + product.Reference.get(0).Type + "/" + product.Reference.get(0).Id + "/", product.Model);
record.value = database.getLabel(product.Label);
records.add(record);
}
break;
case 4:
// Get product
if (database.FindProduct(Integer.parseInt(splitDomain[1]), Integer.parseInt(splitDomain[2]), Integer.parseInt(splitDomain[3]), MAX_VERSION) == false) {
break;
}
if (database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.CONFIGURATION.getKey()) == true) {
record = new OpenHABConfigurationRecord(domain + "parameters/", "Configuration Parameters");
records.add(record);
}
if (database.doesProductImplementCommandClass(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey()) == true) {
record = new OpenHABConfigurationRecord(domain + "associations/", "Association Groups");
records.add(record);
}
record = new OpenHABConfigurationRecord(domain + "classes/", "Command Classes");
records.add(record);
break;
case 5:
// Get product
if (database.FindProduct(Integer.parseInt(splitDomain[1]), Integer.parseInt(splitDomain[2]), Integer.parseInt(splitDomain[3]), MAX_VERSION) == false) {
break;
}
if (splitDomain[4].equals("parameters")) {
List<ZWaveDbConfigurationParameter> configList = database.getProductConfigParameters();
// Loop through the parameters and add to the records...
for (ZWaveDbConfigurationParameter parameter : configList) {
record = new OpenHABConfigurationRecord(domain, "configuration" + parameter.Index, database.getLabel(parameter.Label), true);
if (parameter != null) {
record.value = parameter.Default;
}
// Add the data type
try {
record.type = OpenHABConfigurationRecord.TYPE.valueOf(parameter.Type.toUpperCase());
} catch (IllegalArgumentException e) {
logger.error("Error with parameter type for {} - Set {} - assuming LONG", parameter.Label.toString(), parameter.Type);
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 the description
record.description = database.getLabel(parameter.Help);
records.add(record);
}
}
if (splitDomain[4].equals("associations")) {
List<ZWaveDbAssociationGroup> groupList = database.getProductAssociationGroups();
if (groupList != null) {
// records...
for (ZWaveDbAssociationGroup group : groupList) {
record = new OpenHABConfigurationRecord(domain, "association" + group.Index, database.getLabel(group.Label), true);
// Add the description
record.description = database.getLabel(group.Help);
records.add(record);
}
}
}
if (splitDomain[4].equals("classes")) {
List<ZWaveDbCommandClass> classList = database.getProductCommandClasses();
if (classList != null) {
// records...
for (ZWaveDbCommandClass iClass : classList) {
// Make sure the command class exists!
if (ZWaveCommandClass.CommandClass.getCommandClass(iClass.Id) == null) {
continue;
}
record = new OpenHABConfigurationRecord(domain, "class" + iClass.Id, ZWaveCommandClass.CommandClass.getCommandClass(iClass.Id).getLabel(), true);
if (ZWaveCommandClass.CommandClass.getCommandClass(iClass.Id).getCommandClassClass() == null) {
record.state = OpenHABConfigurationRecord.STATE.WARNING;
}
records.add(record);
}
}
}
break;
}
return records;
}
// All domains after here must have an initialised ZWave network
if (zController == null) {
logger.error("Controller not initialised in call to getConfiguration");
return null;
}
if (domain.equals("nodes/")) {
ZWaveProductDatabase database = new ZWaveProductDatabase();
// Return the list of nodes
for (ZWaveNode node : zController.getNodes()) {
if (node.getName() == null || node.getName().isEmpty()) {
record = new OpenHABConfigurationRecord("nodes/" + "node" + node.getNodeId() + "/", "Node " + node.getNodeId());
} else {
record = new OpenHABConfigurationRecord("nodes/" + "node" + node.getNodeId() + "/", node.getNodeId() + ": " + node.getName());
}
// If we can't find the product, then try and find just the manufacturer
if (node.getManufacturer() == Integer.MAX_VALUE) {
// The device isn't know, print nothing!
} else if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId(), node.getApplicationVersion()) == false) {
if (database.FindManufacturer(node.getManufacturer()) == false) {
record.value = "Manufacturer:" + node.getManufacturer() + " [ID:" + Integer.toHexString(node.getDeviceId()) + ",Type:" + Integer.toHexString(node.getDeviceType()) + "]";
} else {
record.value = database.getManufacturerName() + " [ID:" + Integer.toHexString(node.getDeviceId()) + ",Type:" + Integer.toHexString(node.getDeviceType()) + "]";
}
logger.debug("NODE {}: No database entry: {}", node.getNodeId(), record.value);
} else {
if (node.getLocation() == null || node.getLocation().isEmpty()) {
record.value = database.getProductName();
} else {
record.value = database.getProductName() + ": " + node.getLocation();
}
}
// Set the state
boolean canDelete = false;
switch(node.getNodeState()) {
case DEAD:
record.state = OpenHABConfigurationRecord.STATE.ERROR;
break;
case FAILED:
record.state = OpenHABConfigurationRecord.STATE.ERROR;
canDelete = true;
break;
case ALIVE:
Date lastDead = node.getDeadTime();
Long timeSinceLastDead = Long.MAX_VALUE;
if (lastDead != null) {
timeSinceLastDead = System.currentTimeMillis() - lastDead.getTime();
}
if (node.getNodeInitializationStage() != ZWaveNodeInitStage.DONE) {
record.state = OpenHABConfigurationRecord.STATE.INITIALIZING;
} else if (node.getDeadCount() > 0 && timeSinceLastDead < 86400000) {
record.state = OpenHABConfigurationRecord.STATE.WARNING;
} else if (node.getSendCount() > 20 && (node.getRetryCount() * 100 / node.getSendCount()) > 5) {
record.state = OpenHABConfigurationRecord.STATE.WARNING;
} else {
record.state = OpenHABConfigurationRecord.STATE.OK;
}
break;
}
// Add the action buttons
record.addAction("Heal", "Heal Node");
record.addAction("Initialise", "Reinitialise Node");
// Add the delete button if the node is not "operational"
if (canDelete) {
record.addAction("Delete", "Delete Node");
}
records.add(record);
}
return records;
}
if (domain.startsWith("nodes/node")) {
String nodeNumber = domain.substring(10);
int next = nodeNumber.indexOf('/');
String arg = null;
if (next != -1) {
arg = nodeNumber.substring(next + 1);
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);
ZWaveSwitchAllCommandClass switchAllCommandClass = (ZWaveSwitchAllCommandClass) node.getCommandClass(ZWaveCommandClass.CommandClass.SWITCH_ALL);
if (node.getCommandClass(CommandClass.SWITCH_ALL) != null) {
record = new OpenHABConfigurationRecord(domain, "SwitchAll", "Switch All", false);
record.type = OpenHABConfigurationRecord.TYPE.LIST;
record.addValue("0", "Exclude from All On and All Off groups");
record.addValue("1", "Include in All On group");
record.addValue("2", "Include in All Off group");
record.addValue("255", "Include in All On and All Off groups");
record.value = String.valueOf(switchAllCommandClass.getMode());
records.add(record);
}
// Get the configuration command class for this node if it's supported
if (node.getCommandClass(CommandClass.CONFIGURATION) != null) {
record = new OpenHABConfigurationRecord(domain + "parameters/", "Configuration Parameters");
record.addAction("Refresh", "Refresh");
records.add(record);
}
if (node.getCommandClass(CommandClass.ASSOCIATION) != null) {
record = new OpenHABConfigurationRecord(domain + "associations/", "Association Groups");
record.addAction("Refresh", "Refresh");
records.add(record);
}
if (node.getCommandClass(CommandClass.WAKE_UP) != null) {
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("switch_all/")) {
/*
* ZWaveSwitchAllCommandClass switchAllCommandClass =
* (ZWaveSwitchAllCommandClass)node.getCommandClass(ZWaveCommandClass.CommandClass.SWITCH_ALL);
* if (switchAllCommandClass != null) {
* logger.debug("NODE {}: Supports Switch All Command Class Adding Switch All Configuration ",
* (Object)nodeId);
* record = new OpenHABConfigurationRecord(domain, "Mode", "Mode", true);
* record.type = OpenHABConfigurationRecord.TYPE.LIST;
* record.addValue("0x00", "Exclude from All On and All Off groups");
* record.addValue("0x01", "Include in All On group");
* record.addValue("0x02", "Include in All Off group");
* record.addValue("0xFF", "Include in All On and All Off groups");
* records.add(record);
* }
*/
} else if (arg.equals("info/")) {
record = new OpenHABConfigurationRecord(domain, "NodeID", "Node ID", true);
record.value = Integer.toString(node.getNodeId());
records.add(record);
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(), node.getApplicationVersion()) == 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() + "%";
}
// If the node is reporting low battery, mark it up...
if (batteryCommandClass.getBatteryLow() == true) {
record.value += " LOW";
}
} else if (node.getNodeInitializationStage().getStage() <= ZWaveNodeInitStage.DETAILS.getStage()) {
// If we haven't passed the DETAILS stage, then we don't know the source
record.value = "UNKNOWN";
} 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 = versionCommandClass.getProtocolVersion();
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "AppVersion", "Application Version", true);
if (versionCommandClass.getApplicationVersion() == null) {
record.value = "Unknown";
} else {
record.value = 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.getNodeState() + " " + node.getNodeInitializationStage() + " " + 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(), node.getApplicationVersion()) != false) {
List<ZWaveDbConfigurationParameter> configList = database.getProductConfigParameters();
if (configList == null) {
return records;
}
// Get the configuration command class for this node if it's supported
ZWaveConfigurationCommandClass configurationCommandClass = (ZWaveConfigurationCommandClass) node.getCommandClass(CommandClass.CONFIGURATION);
if (configurationCommandClass == null) {
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);
// This is the only way we can be sure of its real value
if (configurationParameter != null && configurationParameter.getWriteOnly() == false) {
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(), node.getApplicationVersion()) != false) {
List<ZWaveDbAssociationGroup> groupList = database.getProductAssociationGroups();
if (groupList == null) {
return records;
}
// Get the association command class for this node if it's supported
ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) node.getCommandClass(CommandClass.ASSOCIATION);
if (associationCommandClass == null) {
return null;
}
// records...
for (ZWaveDbAssociationGroup group : groupList) {
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
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(), node.getApplicationVersion()) != 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);
// First we build a list of all nodes, starting with the group members
// This ensures that old nodes included in a group, but not now part
// of the network will still be listed, and can be removed.
List<Integer> nodes = new ArrayList<Integer>();
nodes.addAll(associationCommandClass.getGroupMembers(groupId));
for (ZWaveNode nodeList : zController.getNodes()) {
// Don't allow an association with itself
if (nodeList.getNodeId() == node.getNodeId()) {
continue;
}
if (!nodes.contains(nodeList.getNodeId())) {
nodes.add(nodeList.getNodeId());
}
}
// Let's sort them!
Collections.sort(nodes);
// Now we loop through the node list and create an entry for each node.
List<Integer> members = associationCommandClass.getGroupMembers(groupId);
for (int i = 0; i < nodes.size(); i++) {
int nodeNum = nodes.get(i);
ZWaveNode nodeList = zController.getNode(nodeNum);
// Add the member
if (nodeList == null || nodeList.getName() == null || nodeList.getName().isEmpty()) {
record = new OpenHABConfigurationRecord(domain, "node" + nodeNum, "Node " + nodeNum, false);
} else {
record = new OpenHABConfigurationRecord(domain, "node" + nodeNum, nodeList.getName(), false);
}
record.type = OpenHABConfigurationRecord.TYPE.LIST;
record.addValue("true", "Member");
record.addValue("false", "Non-Member");
if (members != null && members.contains(nodeNum)) {
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, nodeNum);
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.debug("NODE {}: wakeupCommandClass not supported", 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, "LastWake", "Last Wakeup", true);
if (wakeupCommandClass.getLastWakeup() == null) {
record.value = "NEVER";
} else {
record.value = df.format(wakeupCommandClass.getLastWakeup());
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "Target", "Target Node", true);
record.value = Integer.toString(wakeupCommandClass.getTargetNodeId());
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;
// If this node isn't known, mark it as an error
if (nodeNeighbor == null) {
record.state = OpenHABConfigurationRecord.STATE.ERROR;
}
records.add(record);
}
} else if (arg.equals("controller/")) {
// Create the record
record = new OpenHABConfigurationRecord(domain, "Type", "Controller Type", true);
record.type = OpenHABConfigurationRecord.TYPE.LIST;
record.value = zController.getControllerType().getLabel();
record.addValue(ZWaveDeviceType.PRIMARY.toString(), ZWaveDeviceType.PRIMARY.getLabel());
record.addValue(ZWaveDeviceType.SECONDARY.toString(), ZWaveDeviceType.SECONDARY.getLabel());
record.addValue(ZWaveDeviceType.SUC.toString(), ZWaveDeviceType.SUC.getLabel());
// Set the read-only if this isn't a controller!
switch(zController.getControllerType()) {
case SUC:
case PRIMARY:
case SECONDARY:
record.readonly = true;
break;
default:
record.readonly = true;
break;
}
records.add(record);
record = new OpenHABConfigurationRecord(domain, "APIVersion", "API Version", true);
record.value = zController.getSerialAPIVersion();
records.add(record);
record = new OpenHABConfigurationRecord(domain, "ZWaveVersion", "ZWave Version", true);
record.value = zController.getZWaveVersion();
records.add(record);
}
return records;
}
return null;
}
use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter in project openhab1-addons by openhab.
the class ZWaveConfigurationConverter method receiveCommand.
/**
* {@inheritDoc}
*/
@Override
public void receiveCommand(Item item, Command command, ZWaveNode node, ZWaveConfigurationCommandClass commandClass, int endpointId, Map<String, String> arguments) {
ZWaveCommandConverter<?, ?> converter = this.getCommandConverter(command.getClass());
if (converter == null) {
logger.warn("NODE {}: No converter found for item={}, type={}, endpoint={}, ignoring command.", node.getNodeId(), item.getName(), command.getClass().getSimpleName(), endpointId);
return;
}
String parmNumber = arguments.get("parameter");
if (parmNumber == null) {
logger.error("NODE {}: 'parameter' option must be specified.", node.getNodeId());
return;
}
int paramIndex = Integer.parseInt(parmNumber);
if (paramIndex < 0 || paramIndex > 255) {
logger.error("NODE {}: 'parameter' option must be between 0 and 255.", node.getNodeId());
return;
}
ZWaveProductDatabase database = new ZWaveProductDatabase();
if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId(), node.getApplicationVersion()) == false) {
logger.error("NODE {}: database can't find product.", node.getNodeId());
return;
}
List<ZWaveDbConfigurationParameter> configList = database.getProductConfigParameters();
if (configList == null) {
logger.error("NODE {}: Device has no configuration.", node.getNodeId());
return;
}
ZWaveDbConfigurationParameter dbParameter = null;
for (ZWaveDbConfigurationParameter parameter : configList) {
if (parameter.Index == paramIndex) {
dbParameter = parameter;
break;
}
}
if (dbParameter == null) {
logger.error("NODE {}: Device has no parameter {}.", node.getNodeId(), paramIndex);
return;
}
ConfigurationParameter configurationParameter = new ConfigurationParameter(paramIndex, (Integer) converter.convertFromCommandToValue(item, command), dbParameter.Size);
// Set the parameter
SerialMessage serialMessage = commandClass.setConfigMessage(configurationParameter);
if (serialMessage == null) {
logger.warn("NODE {}: Generating message failed for command class = {}, endpoint = {}", node.getNodeId(), commandClass.getCommandClass().getLabel(), endpointId);
return;
}
this.getController().sendData(serialMessage);
// And request a read-back
serialMessage = commandClass.getConfigMessage(paramIndex);
this.getController().sendData(serialMessage);
if (command instanceof State) {
this.getEventPublisher().postUpdate(item.getName(), (State) command);
}
}
Aggregations