Search in sources :

Example 1 with WriteAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleAttributeWriteCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length != 5) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    final int clusterId = parseCluster(args[3]);
    final int attributeId = parseAttribute(args[4]);
    final ZclCluster cluster;
    final String direction = args[2].toUpperCase();
    if ("IN".equals(direction)) {
        cluster = endpoint.getInputCluster(clusterId);
    } else if ("OUT".equals(direction)) {
        cluster = endpoint.getOutputCluster(clusterId);
    } else {
        throw new IllegalArgumentException("Cluster direction must be IN or OUT");
    }
    final ZclAttribute attribute = cluster.getAttribute(attributeId);
    final Object value = parseValue(args[4], attribute.getDataType());
    final CommandResult result = cluster.write(attribute, value).get();
    if (result.isSuccess()) {
        final WriteAttributesResponse response = result.getResponse();
        final int statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == 0) {
            out.println("Attribute value write success.");
        } else {
            final ZclStatus status = ZclStatus.getStatus((byte) statusCode);
            out.println("Attribute value write error: " + status);
        }
    } else {
        out.println("Error executing command: " + result);
    }
}
Also used : ZclStatus(com.zsmartsystems.zigbee.zcl.ZclStatus) ZclAttribute(com.zsmartsystems.zigbee.zcl.ZclAttribute) WriteAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 2 with WriteAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclGeneralCluster method writeAttributesResponse.

/**
 * The Write Attributes Response
 * <p>
 * The write attributes response command is generated in response to a write
 * attributes command.
 *
 * @param records {@link List<WriteAttributeStatusRecord>} Records
 * @return the {@link Future<CommandResult>} command result future
 */
public Future<CommandResult> writeAttributesResponse(List<WriteAttributeStatusRecord> records) {
    WriteAttributesResponse command = new WriteAttributesResponse();
    // Set the fields
    command.setRecords(records);
    return send(command);
}
Also used : WriteAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse)

Aggregations

WriteAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse)2 CommandResult (com.zsmartsystems.zigbee.CommandResult)1 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)1 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)1 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)1