use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeApi method on.
/**
* Switches destination on.
*
* @param destination the {@link ZigBeeAddress}
* @return the command result future.
*/
public Future<CommandResult> on(final ZigBeeAddress destination) {
if (!(destination instanceof ZigBeeEndpointAddress)) {
return null;
}
ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) destination;
ZigBeeEndpoint endpoint = networkManager.getNode(endpointAddress.getAddress()).getEndpoint(endpointAddress.getEndpoint());
if (endpoint == null) {
return null;
}
ZclOnOffCluster cluster = (ZclOnOffCluster) endpoint.getInputCluster(ZclOnOffCluster.CLUSTER_ID);
return cluster.onCommand();
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleNodeListCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
final Set<ZigBeeNode> nodes = networkManager.getNodes();
final List<Integer> nodeIds = new ArrayList<Integer>();
for (ZigBeeNode node : nodes) {
nodeIds.add(node.getNetworkAddress());
}
Collections.sort(nodeIds);
out.println("Network Addr IEEE Address Device Type EP Profile");
for (Integer nodeId : nodeIds) {
ZigBeeNode node = networkManager.getNode(nodeId);
out.print(String.format("%-6d %04X %s %-11s", node.getNetworkAddress(), node.getNetworkAddress(), node.getIeeeAddress(), node.getLogicalType()));
List<Integer> endpointIds = new ArrayList<Integer>();
for (final ZigBeeEndpoint endpoint : node.getEndpoints()) {
endpointIds.add(endpoint.getEndpointId());
}
Collections.sort(endpointIds);
boolean first = true;
for (Integer endpointId : endpointIds) {
if (!first) {
out.print(" ");
}
first = false;
ZigBeeEndpoint endpoint = node.getEndpoint(endpointId);
out.println(String.format("%-3d %s", endpoint.getEndpointId(), ZigBeeProfileType.getProfileType(endpoint.getProfileId())));
}
if (first) {
out.println();
}
}
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleReportingConfigCommand 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 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.getReporting(attribute).get();
if (result.isSuccess()) {
final ReadAttributesResponse response = result.getResponse();
final ZclStatus statusCode = response.getRecords().get(0).getStatus();
if (statusCode == ZclStatus.SUCCESS) {
out.println("Cluster " + 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);
}
} else {
out.println("Error executing command: " + result);
}
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleReportingSubscribeCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
if (args.length < 7) {
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 minInterval;
try {
minInterval = Integer.parseInt(args[5]);
} catch (final NumberFormatException e) {
throw new IllegalArgumentException("Min Interval has invalid format");
}
final int maxInterval;
try {
maxInterval = Integer.parseInt(args[6]);
} catch (final NumberFormatException e) {
throw new IllegalArgumentException("Max Interval has invalid format");
}
final int attributeId = parseAttribute(args[4]);
final ZclAttribute attribute = cluster.getAttribute(attributeId);
final Object reportableChange;
if (args.length > 6) {
reportableChange = parseValue(args[7], attribute.getDataType());
} else {
reportableChange = null;
}
final CommandResult result = cluster.setReporting(attribute, minInterval, maxInterval, reportableChange).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.ZigBeeEndpoint 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);
}
}
Aggregations