Search in sources :

Example 6 with ZWaveWakeUpCommandClass

use of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass in project openhab1-addons by openhab.

the class SendDataMessageClass method handleFailedSendDataRequest.

public boolean handleFailedSendDataRequest(ZWaveController zController, SerialMessage originalMessage) {
    ZWaveNode node = zController.getNode(originalMessage.getMessageNode());
    logger.trace("NODE {}: Handling failed message.", node.getNodeId());
    // Increment the resend count.
    // This will set the node to DEAD if we've exceeded the retries.
    node.incrementResendCount();
    // No retries if the node is DEAD or FAILED
    if (node.isDead()) {
        logger.error("NODE {}: Node is DEAD. Dropping message.", node.getNodeId());
        return false;
    }
    // If this device isn't listening, queue the message in the wakeup class
    if (!node.isListening() && !node.isFrequentlyListening()) {
        ZWaveWakeUpCommandClass wakeUpCommandClass = (ZWaveWakeUpCommandClass) node.getCommandClass(CommandClass.WAKE_UP);
        if (wakeUpCommandClass != null) {
            // It's a battery operated device, place in wake-up queue.
            wakeUpCommandClass.setAwake(false);
            wakeUpCommandClass.processOutgoingWakeupMessage(originalMessage);
            return false;
        }
    }
    logger.error("NODE {}: Got an error while sending data. Resending message.", node.getNodeId());
    // Set priority to Immediate since this is a retry
    originalMessage.setPriority(SerialMessagePriority.Immediate);
    zController.enqueue(originalMessage);
    return true;
}
Also used : ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)

Example 7 with ZWaveWakeUpCommandClass

use of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass 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;
}
Also used : ZWaveVersionCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveVersionCommandClass) ArrayList(java.util.ArrayList) ConfigurationParameter(org.openhab.binding.zwave.internal.protocol.ConfigurationParameter) ZWaveSwitchAllCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSwitchAllCommandClass) ZWaveDeviceClass(org.openhab.binding.zwave.internal.protocol.ZWaveDeviceClass) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass) ZWaveAssociationCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass) ZWaveConfigurationCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveConfigurationCommandClass) ArrayList(java.util.ArrayList) List(java.util.List) ZWaveBatteryCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveBatteryCommandClass) Date(java.util.Date) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode)

Example 8 with ZWaveWakeUpCommandClass

use of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass in project openhab1-addons by openhab.

the class ZWaveController method enqueue.

/**
     * Enqueues a message for sending on the send queue.
     *
     * @param serialMessage the serial message to enqueue.
     */
public void enqueue(SerialMessage serialMessage) {
    // Sanity check!
    if (serialMessage == null) {
        return;
    }
    // First try and get the node
    // If we're sending to a node, then this obviously isn't to the controller, and we should
    // queue anything to a battery node (ie a node supporting the WAKEUP class)!
    ZWaveNode node = this.getNode(serialMessage.getMessageNode());
    if (node != null) {
        // Does this message need to be security encapsulated?
        if (node.doesMessageRequireSecurityEncapsulation(serialMessage)) {
            ZWaveSecurityCommandClass securityCommandClass = (ZWaveSecurityCommandClass) node.getCommandClass(CommandClass.SECURITY);
            securityCommandClass.queueMessageForEncapsulationAndTransmission(serialMessage);
            // so we discard this one without putting it on the queue
            return;
        }
        // Keep track of the number of packets sent to this device
        node.incrementSendCount();
        // If the device isn't listening, queue the message if it supports the wakeup class
        if (!node.isListening() && !node.isFrequentlyListening()) {
            ZWaveWakeUpCommandClass wakeUpCommandClass = (ZWaveWakeUpCommandClass) node.getCommandClass(CommandClass.WAKE_UP);
            // If it's a battery operated device, check if it's awake or place in wake-up queue.
            if (wakeUpCommandClass != null && !wakeUpCommandClass.processOutgoingWakeupMessage(serialMessage)) {
                return;
            }
        }
    }
    // Add the message to the queue
    this.sendQueue.add(serialMessage);
    if (logger.isTraceEnabled()) {
        logger.debug("Enqueueing message. Queue length = {}, Queue = {}", this.sendQueue.size(), this.sendQueue);
    } else {
        logger.debug("Enqueueing message. Queue length = {}", this.sendQueue.size());
    }
}
Also used : ZWaveSecurityCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSecurityCommandClass) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)

Example 9 with ZWaveWakeUpCommandClass

use of org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass in project openhab1-addons by openhab.

the class ZWaveNode method getRoutingList.

/**
     * Updates a nodes routing information
     * Generation of routes uses associations
     *
     * @param nodeId
     */
public ArrayList<Integer> getRoutingList() {
    logger.debug("NODE {}: Update return routes", nodeId);
    // Create a list of nodes this device is configured to talk to
    ArrayList<Integer> routedNodes = new ArrayList<Integer>();
    // Only update routes if this is a routing node
    if (isRouting() == false) {
        logger.debug("NODE {}: Node is not a routing node. No routes can be set.", nodeId);
        return null;
    }
    // Get the number of association groups reported by this node
    ZWaveAssociationCommandClass associationCmdClass = (ZWaveAssociationCommandClass) getCommandClass(CommandClass.ASSOCIATION);
    if (associationCmdClass == null) {
        logger.debug("NODE {}: Node has no association class. No routes can be set.", nodeId);
        return null;
    }
    int groups = associationCmdClass.getGroupCount();
    if (groups != 0) {
        // Loop through each association group and add the node ID to the list
        for (int group = 1; group <= groups; group++) {
            for (Integer associationNodeId : associationCmdClass.getGroupMembers(group)) {
                routedNodes.add(associationNodeId);
            }
        }
    }
    // Add the wakeup destination node to the list for battery devices
    ZWaveWakeUpCommandClass wakeupCmdClass = (ZWaveWakeUpCommandClass) getCommandClass(CommandClass.WAKE_UP);
    if (wakeupCmdClass != null) {
        Integer wakeupNodeId = wakeupCmdClass.getTargetNodeId();
        routedNodes.add(wakeupNodeId);
    }
    // Are there any nodes to which we need to set routes?
    if (routedNodes.size() == 0) {
        logger.debug("NODE {}: No return routes required.", nodeId);
        return null;
    }
    return routedNodes;
}
Also used : ZWaveAssociationCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass) ArrayList(java.util.ArrayList) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)

Aggregations

ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)9 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)6 ZWaveAssociationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass)6 ArrayList (java.util.ArrayList)4 ZWaveConfigurationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveConfigurationCommandClass)4 ZWaveNodeSerializer (org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer)3 List (java.util.List)2 ConfigurationParameter (org.openhab.binding.zwave.internal.protocol.ConfigurationParameter)2 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)2 ZWaveCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveCommandClass)2 ZWaveNoOperationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveNoOperationCommandClass)2 ZWaveSwitchAllCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSwitchAllCommandClass)2 ZWaveVersionCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveVersionCommandClass)2 Date (java.util.Date)1 ZWaveDbAssociationGroup (org.openhab.binding.zwave.internal.config.ZWaveDbAssociationGroup)1 ZWaveDbCommandClass (org.openhab.binding.zwave.internal.config.ZWaveDbCommandClass)1 ZWaveDbConfigurationParameter (org.openhab.binding.zwave.internal.config.ZWaveDbConfigurationParameter)1 ZWaveProductDatabase (org.openhab.binding.zwave.internal.config.ZWaveProductDatabase)1 ZWaveDeviceClass (org.openhab.binding.zwave.internal.protocol.ZWaveDeviceClass)1 ZWaveDeviceType (org.openhab.binding.zwave.internal.protocol.ZWaveDeviceType)1