use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter 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);
}
}
}
}
}
use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter in project openhab1-addons by openhab.
the class ZWaveConfigurationCommandClass method processConfigurationReport.
/**
* Processes a CONFIGURATIONCMD_REPORT / CONFIGURATIONCMD_SET message.
*
* @param serialMessage
* the incoming message to process.
* @param offset
* the offset position from which to start message processing.
* @param endpoint
* the endpoint or instance number this message is meant for.
*/
protected void processConfigurationReport(SerialMessage serialMessage, int offset) {
// Extract the parameter index and value
int parameter = serialMessage.getMessagePayloadByte(offset + 1);
int size = serialMessage.getMessagePayloadByte(offset + 2);
// ZWave plus devices seem to return 0 if we request a parameter that doesn't exist
if (size == 0) {
logger.warn("NODE {}: Parameter {} response has 0 length", this.getNode().getNodeId(), parameter);
return;
}
// Recover the data
try {
int value = extractValue(serialMessage.getMessagePayload(), offset + 3, size);
logger.debug("NODE {}: Node configuration report, parameter={}, value={}, size={}", this.getNode().getNodeId(), parameter, value, size);
ConfigurationParameter configurationParameter;
// Check if the parameter exists in our list
configurationParameter = this.configParameters.get(parameter);
if (configurationParameter == null) {
configurationParameter = new ConfigurationParameter(parameter, value, size);
} else {
configurationParameter.setValue(value);
}
this.configParameters.put(parameter, configurationParameter);
ZWaveConfigurationParameterEvent zEvent = new ZWaveConfigurationParameterEvent(this.getNode().getNodeId(), configurationParameter);
this.getController().notifyEventListeners(zEvent);
} catch (NumberFormatException e) {
return;
}
}
use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter in project openhab1-addons by openhab.
the class ZWaveConfigurationCommandClass method setParameterReadOnly.
/**
* Sets a parameter as Read Only
* Some parameters in some devices can not be written to. Trying to write them results
* in a timeout and this should be avoided.
*
* @param index the parameter index
* @param readOnly true if the parameter can not be read
*/
public void setParameterReadOnly(Integer index, boolean readOnly) {
ConfigurationParameter configurationParameter;
// Check if the parameter exists in our list
configurationParameter = this.configParameters.get(index);
if (configurationParameter == null) {
configurationParameter = new ConfigurationParameter(index, 0, 1);
configParameters.put(index, configurationParameter);
}
configurationParameter.setReadOnly(readOnly);
}
use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter in project openhab1-addons by openhab.
the class ZWaveConfigurationCommandClass method getConfigMessage.
/**
* Gets a SerialMessage with the CONFIGURATIONCMD_GET command
*
* @return the serial message
*/
public SerialMessage getConfigMessage(int parameter) {
// Check if the parameter exists in our list
ConfigurationParameter configurationParameter = this.configParameters.get(parameter);
if (configurationParameter != null && configurationParameter.getWriteOnly() == true) {
logger.debug("NODE {}: CONFIGURATIONCMD_GET ignored for parameter {} - parameter is write only", this.getNode().getNodeId(), parameter);
return null;
}
logger.debug("NODE {}: Creating new message for application command CONFIGURATIONCMD_GET", this.getNode().getNodeId());
SerialMessage result = new SerialMessage(this.getNode().getNodeId(), SerialMessageClass.SendData, SerialMessageType.Request, SerialMessageClass.ApplicationCommandHandler, SerialMessagePriority.Config);
byte[] newPayload = { (byte) this.getNode().getNodeId(), 3, (byte) getCommandClass().getKey(), (byte) CONFIGURATIONCMD_GET, (byte) (parameter & 0xff) };
result.setMessagePayload(newPayload);
return result;
}
use of org.openhab.binding.zwave.internal.protocol.ConfigurationParameter in project openhab1-addons by openhab.
the class ZWaveConfigurationCommandClass method setParameterWriteOnly.
/**
* Sets a parameter as Write Only
* Some parameters in some devices can not be read. Trying to read them results
* in a timeout and this should be avoided.
*
* @param index the parameter index
* @param writeOnly true if the parameter can not be read
*/
public void setParameterWriteOnly(Integer index, Integer size, boolean writeOnly) {
ConfigurationParameter configurationParameter;
// Check if the parameter exists in our list
configurationParameter = this.configParameters.get(index);
if (configurationParameter == null) {
configurationParameter = new ConfigurationParameter(index, 0, size);
configParameters.put(index, configurationParameter);
}
configurationParameter.setWriteOnly(writeOnly);
}
Aggregations