Search in sources :

Example 1 with ZWaveDeviceType

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

the class ZWaveConfiguration method doSet.

@Override
public void doSet(String domain, String value) {
    logger.debug("doSet domain '{}' to '{}'", domain, value);
    String[] splitDomain = domain.split("/");
    // If the controller isn't ready, then ignore any requests
    if (zController.isConnected() == false) {
        logger.debug("Controller not ready - Ignoring request to '{}'", domain);
        return;
    }
    // There must be at least 2 components to the domain
    if (splitDomain.length < 2) {
        logger.error("Error malformed domain in doSet '{}'", domain);
        return;
    }
    if (splitDomain[0].equals("nodes")) {
        int nodeId = Integer.parseInt(splitDomain[1].substring(4));
        ZWaveNode node = zController.getNode(nodeId);
        if (node == null) {
            logger.error("Error finding node in doSet '{}'", domain);
            return;
        }
        // TODO: Should we check that the node is finished initialising
        ZWaveProductDatabase database = new ZWaveProductDatabase();
        if (database.FindProduct(node.getManufacturer(), node.getDeviceType(), node.getDeviceId(), node.getApplicationVersion()) == false) {
            logger.error("NODE {}: Error in doSet - no database found", nodeId);
            return;
        }
        if (splitDomain.length == 3) {
            if (splitDomain[2].equals("Name")) {
                node.setName(value);
            }
            if (splitDomain[2].equals("Location")) {
                node.setLocation(value);
            }
            if (splitDomain[2].equals("SwitchAll")) {
                ZWaveSwitchAllCommandClass switchAllCommandClass = (ZWaveSwitchAllCommandClass) node.getCommandClass(CommandClass.SWITCH_ALL);
                if (switchAllCommandClass == null) {
                    logger.error("NODE {}: Error getting switchAllCommandClass in doSet", nodeId);
                    return;
                }
                // Set the switch all mode
                int mode = Integer.parseInt(value);
                PendingCfg.Add(ZWaveSwitchAllCommandClass.CommandClass.SWITCH_ALL.getKey(), node.getNodeId(), 0, mode);
                SerialMessage msg = switchAllCommandClass.setValueMessage(mode);
                this.zController.sendData(msg);
                // And request a read-back
                this.zController.sendData(switchAllCommandClass.getValueMessage());
            }
            // Write the node to disk
            ZWaveNodeSerializer nodeSerializer = new ZWaveNodeSerializer();
            nodeSerializer.SerializeNode(node);
        } else if (splitDomain.length == 4) {
            if (splitDomain[2].equals("parameters")) {
                ZWaveConfigurationCommandClass configurationCommandClass = (ZWaveConfigurationCommandClass) node.getCommandClass(CommandClass.CONFIGURATION);
                if (configurationCommandClass == null) {
                    logger.error("NODE {}: Error getting configurationCommandClass in doSet", nodeId);
                    return;
                }
                int paramIndex = Integer.parseInt(splitDomain[3].substring(13));
                List<ZWaveDbConfigurationParameter> configList = database.getProductConfigParameters();
                // Get the size
                int size = 1;
                for (ZWaveDbConfigurationParameter parameter : configList) {
                    if (parameter.Index == paramIndex) {
                        size = parameter.Size;
                        break;
                    }
                }
                logger.debug("Set parameter index '{}' to '{}'", paramIndex, value);
                PendingCfg.Add(ZWaveCommandClass.CommandClass.CONFIGURATION.getKey(), nodeId, paramIndex, Integer.valueOf(value));
                ConfigurationParameter configurationParameter = new ConfigurationParameter(paramIndex, Integer.valueOf(value), size);
                // Set the parameter
                this.zController.sendData(configurationCommandClass.setConfigMessage(configurationParameter));
                // And request a read-back
                this.zController.sendData(configurationCommandClass.getConfigMessage(paramIndex));
            }
            if (splitDomain[2].equals("wakeup")) {
                ZWaveWakeUpCommandClass wakeupCommandClass = (ZWaveWakeUpCommandClass) node.getCommandClass(CommandClass.WAKE_UP);
                if (wakeupCommandClass == null) {
                    logger.error("NODE {}: Error getting wakeupCommandClass in doSet", nodeId);
                    return;
                }
                logger.debug("NODE {}: Set wakeup interval to '{}'", nodeId, value);
                // Add this as a pending transaction
                PendingCfg.Add(ZWaveCommandClass.CommandClass.WAKE_UP.getKey(), node.getNodeId(), Integer.parseInt(value));
                // Set the wake-up interval
                this.zController.sendData(wakeupCommandClass.setInterval(Integer.parseInt(value)));
                // And request a read-back
                this.zController.sendData(wakeupCommandClass.getIntervalMessage());
            }
            if (splitDomain[2].equals("controller")) {
                if (splitDomain[3].equals("Type")) {
                    ZWaveDeviceType type = ZWaveDeviceType.fromString(value);
                    logger.error("NODE {}: Setting controller type to {}", nodeId, type.toString());
                // ZW_EnableSUC and ZW_SetSUCNodeID
                }
            }
        } else if (splitDomain.length == 5) {
            if (splitDomain[2].equals("associations")) {
                ZWaveAssociationCommandClass associationCommandClass = (ZWaveAssociationCommandClass) node.getCommandClass(CommandClass.ASSOCIATION);
                if (associationCommandClass == null) {
                    logger.error("NODE {}: Error getting associationCommandClass in doSet", nodeId);
                    return;
                }
                int assocId = Integer.parseInt(splitDomain[3].substring(11));
                int assocArg = Integer.parseInt(splitDomain[4].substring(4));
                if (value.equalsIgnoreCase("true")) {
                    PendingCfg.Add(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey(), nodeId, assocId, assocArg, 1);
                    logger.debug("Add association index '{}' to '{}'", assocId, assocArg);
                    this.zController.sendData(associationCommandClass.setAssociationMessage(assocId, assocArg));
                } else {
                    PendingCfg.Add(ZWaveCommandClass.CommandClass.ASSOCIATION.getKey(), nodeId, assocId, assocArg, 0);
                    logger.debug("Remove association index '{}' to '{}'", assocId, assocArg);
                    this.zController.sendData(associationCommandClass.removeAssociationMessage(assocId, assocArg));
                }
                // Request an update to the group
                this.zController.sendData(associationCommandClass.getAssociationMessage(assocId));
                // So, let's start a network heal - just for this node right now
                if (networkMonitor != null) {
                    networkMonitor.startNodeHeal(nodeId);
                }
            }
        }
    }
}
Also used : ZWaveDeviceType(org.openhab.binding.zwave.internal.protocol.ZWaveDeviceType) ConfigurationParameter(org.openhab.binding.zwave.internal.protocol.ConfigurationParameter) ZWaveSwitchAllCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSwitchAllCommandClass) SerialMessage(org.openhab.binding.zwave.internal.protocol.SerialMessage) ZWaveWakeUpCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass) ZWaveAssociationCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass) ZWaveNodeSerializer(org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer) ZWaveNode(org.openhab.binding.zwave.internal.protocol.ZWaveNode) ZWaveConfigurationCommandClass(org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveConfigurationCommandClass) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConfigurationParameter (org.openhab.binding.zwave.internal.protocol.ConfigurationParameter)1 SerialMessage (org.openhab.binding.zwave.internal.protocol.SerialMessage)1 ZWaveDeviceType (org.openhab.binding.zwave.internal.protocol.ZWaveDeviceType)1 ZWaveNode (org.openhab.binding.zwave.internal.protocol.ZWaveNode)1 ZWaveAssociationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveAssociationCommandClass)1 ZWaveConfigurationCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveConfigurationCommandClass)1 ZWaveSwitchAllCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveSwitchAllCommandClass)1 ZWaveWakeUpCommandClass (org.openhab.binding.zwave.internal.protocol.commandclass.ZWaveWakeUpCommandClass)1 ZWaveNodeSerializer (org.openhab.binding.zwave.internal.protocol.initialization.ZWaveNodeSerializer)1