use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkDiscovererTest method setupTest.
@Before
public void setupTest() {
networkManager = Mockito.mock(ZigBeeNetworkManager.class);
nodeCapture = ArgumentCaptor.forClass(ZigBeeNode.class);
// commandCapture = ArgumentCaptor.forClass(ZigBeeCommand.class);
// matcherCapture = ArgumentCaptor.forClass(CommandResponseMatcher.class);
// Mockito.when(networkManager.unicast(commandCapture.capture(), matcherCapture.capture())).thenReturn(null);
Mockito.doAnswer(new Answer<Future<CommandResult>>() {
@Override
public Future<CommandResult> answer(InvocationOnMock invocation) {
ZigBeeCommand command = (ZigBeeCommand) invocation.getArguments()[0];
CommandResultFuture commandFuture = new CommandResultFuture(networkManager);
CommandResult result = new CommandResult(responses.get(command.getClusterId()));
commandFuture.set(result);
return commandFuture;
}
}).when(networkManager).unicast(org.mockito.Matchers.any(ZigBeeCommand.class), org.mockito.Matchers.any(ZigBeeTransactionMatcher.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
Runnable runnable = (Runnable) invocation.getArguments()[0];
new Thread(runnable).start();
return null;
}
}).when(networkManager).executeTask(org.mockito.Matchers.any(Runnable.class));
}
use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleReportingUnsubscribeCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
if (args.length != 6) {
throw new IllegalArgumentException("Invalid number of arguments");
}
final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
final int clusterId = parseCluster(args[3]);
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 int attributeId = parseAttribute(args[4]);
final ZclAttribute attribute = cluster.getAttribute(attributeId);
final CommandResult result = cluster.setReporting(attribute, 0, 0xFFFF, null).get();
if (result.isSuccess()) {
final ConfigureReportingResponse response = result.getResponse();
final ZclStatus statusCode = response.getRecords().get(0).getStatus();
if (statusCode == ZclStatus.SUCCESS) {
out.println("Attribute value configure reporting success.");
} else {
out.println("Attribute value configure reporting error: " + statusCode);
}
} else {
out.println("Error executing command: " + result);
}
}
use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleUnbindCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
if (args.length < 3) {
throw new IllegalArgumentException("Invalid number of arguments");
}
final int clusterId = parseCluster(args[1]);
final ZigBeeEndpoint source = getEndpoint(networkManager, args[2]);
ZclCluster cluster = source.getInputCluster(clusterId);
if (cluster == null) {
throw new IllegalArgumentException("Cluster '" + clusterId + "' not found.");
}
IeeeAddress destAddress;
int destEndpoint;
if (args.length >= 4) {
ZigBeeEndpoint destination = getEndpoint(networkManager, args[3]);
destAddress = destination.getIeeeAddress();
destEndpoint = destination.getEndpointId();
} else {
destAddress = networkManager.getNode(0).getIeeeAddress();
destEndpoint = 1;
}
final CommandResult response = cluster.unbind(destAddress, destEndpoint).get();
processDefaultResponse(response, out);
}
use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleAttributeReadCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
if (args.length != 4) {
throw new IllegalArgumentException("Invalid number of arguments");
}
final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
final Integer clusterId = parseCluster(args[2]);
ZclCluster cluster = endpoint.getInputCluster(clusterId);
if (cluster != null) {
out.println("Using input cluster");
} else {
cluster = endpoint.getOutputCluster(clusterId);
if (cluster != null) {
out.println("Using output cluster");
} else {
out.println("Cluster not found");
return;
}
}
final Integer attributeId = parseAttribute(args[3]);
String attributeName;
ZclAttribute attribute = cluster.getAttribute(attributeId);
if (attribute == null) {
attributeName = "Attribute " + attributeId;
} else {
attributeName = attribute.getName();
}
out.println("Reading " + cluster.getClusterName() + ", " + attributeName);
CommandResult result;
result = cluster.read(attributeId).get();
if (result.isSuccess()) {
final ReadAttributesResponse response = result.getResponse();
if (response.getRecords().size() == 0) {
out.println("No records returned");
return;
}
final ZclStatus statusCode = response.getRecords().get(0).getStatus();
if (statusCode == ZclStatus.SUCCESS) {
out.println("Cluster " + String.format("%04X", response.getClusterId()) + ", Attribute " + response.getRecords().get(0).getAttributeIdentifier() + ", type " + response.getRecords().get(0).getAttributeDataType() + ", value: " + response.getRecords().get(0).getAttributeValue());
} else {
out.println("Attribute value read error: " + statusCode);
}
return;
} else {
out.println("Error executing command: " + result);
return;
}
}
use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleBindCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
if (args.length < 3) {
throw new IllegalArgumentException("Invalid number of arguments");
}
final int clusterId = parseCluster(args[1]);
final ZigBeeEndpoint source = getEndpoint(networkManager, args[2]);
ZclCluster cluster = source.getInputCluster(clusterId);
if (cluster == null) {
throw new IllegalArgumentException("Cluster '" + clusterId + "' not found.");
}
IeeeAddress destAddress;
int destEndpoint;
if (args.length >= 4) {
ZigBeeEndpoint destination = getEndpoint(networkManager, args[3]);
destAddress = destination.getIeeeAddress();
destEndpoint = destination.getEndpointId();
} else {
destAddress = networkManager.getNode(0).getIeeeAddress();
destEndpoint = 1;
}
final CommandResult response = cluster.bind(destAddress, destEndpoint).get();
processDefaultResponse(response, out);
}
Aggregations