use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleDescribeEndpointCommand method printClusters.
private void printClusters(final ZigBeeEndpoint endpoint, final boolean input, final PrintStream out) {
Collection<Integer> clusters;
if (input) {
clusters = endpoint.getInputClusterIds();
} else {
clusters = endpoint.getOutputClusterIds();
}
Map<Integer, ZclCluster> clusterTree = new TreeMap<Integer, ZclCluster>();
for (Integer clusterId : clusters) {
ZclCluster cluster;
if (input) {
cluster = endpoint.getInputCluster(clusterId);
} else {
cluster = endpoint.getOutputCluster(clusterId);
}
clusterTree.put(cluster.getClusterId(), cluster);
}
for (ZclCluster cluster : clusterTree.values()) {
out.println(printClusterId(cluster.getClusterId()) + " " + cluster.getClusterName());
printAttributes(cluster, out);
}
}
use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeEndpoint method getDao.
/**
* Gets a {@link ZigBeeEndpointDao} used for serialisation of the {@link ZigBeeEndpoint}
*
* @return the {@link ZigBeeEndpointDao}
*/
public ZigBeeEndpointDao getDao() {
ZigBeeEndpointDao dao = new ZigBeeEndpointDao();
dao.setEndpointId(endpointId);
dao.setProfileId(profileId);
List<ZclClusterDao> clusters;
clusters = new ArrayList<ZclClusterDao>();
for (ZclCluster cluster : inputClusters.values()) {
clusters.add(cluster.getDao());
}
dao.setInputClusters(clusters);
clusters = new ArrayList<ZclClusterDao>();
for (ZclCluster cluster : outputClusters.values()) {
clusters.add(cluster.getDao());
}
dao.setOutputClusters(clusters);
return dao;
}
use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeEndpoint method getClusterClass.
private ZclCluster getClusterClass(int clusterId) {
ZclClusterType clusterType = ZclClusterType.getValueById(clusterId);
if (clusterType == null) {
// Unsupported cluster
logger.debug("{}: Unsupported cluster {}", getEndpointAddress(), clusterId);
return null;
}
// Create a cluster class
ZclCluster cluster = null;
Constructor<? extends ZclCluster> constructor;
// try {
try {
constructor = clusterType.getClusterClass().getConstructor(ZigBeeNetworkManager.class, ZigBeeEndpoint.class);
cluster = constructor.newInstance(networkManager, this);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
logger.debug("{}: Error instantiating cluster {}", getEndpointAddress(), clusterType);
return null;
}
return cluster;
}
use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeEndpoint method updateClusters.
private void updateClusters(Map<Integer, ZclCluster> clusters, List<Integer> newList, boolean isInput) {
// Get a list any clusters that are no longer in the list
List<Integer> removeIds = new ArrayList<Integer>();
for (ZclCluster cluster : clusters.values()) {
if (newList.contains(cluster.getClusterId())) {
// The existing cluster is in the new list, so no need to remove it
continue;
}
removeIds.add(cluster.getClusterId());
}
// Remove clusters no longer in use
for (int id : removeIds) {
logger.debug("{}: Removing cluster {}", getEndpointAddress(), id);
clusters.remove(id);
}
// Add any missing clusters into the list
for (int id : newList) {
if (!clusters.containsKey(id)) {
// Get the cluster type
ZclCluster clusterClass = getClusterClass(id);
if (clusterClass == null) {
continue;
}
if (isInput) {
logger.debug("{}: Setting cluster {} as server", getEndpointAddress(), ZclClusterType.getValueById(id));
clusterClass.setServer();
} else {
logger.debug("{}: Setting cluster {} as client", getEndpointAddress(), ZclClusterType.getValueById(id));
clusterClass.setClient();
}
// Add to our list of clusters
clusters.put(id, clusterClass);
}
}
}
use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeEndpoint method addApplication.
/**
* Adds an application and makes it available to this endpoint.
* The cluster used by the server must be in the output clusters list and this will be passed to the
* {@link ZclApplication#serverStartup()) method to start the application.
*
* @param application the new {@link ZigBeeApplication}
*/
public void addApplication(ZigBeeApplication application) {
applications.put(application.getClusterId(), application);
ZclCluster cluster = outputClusters.get(application.getClusterId());
if (cluster == null) {
cluster = inputClusters.get(application.getClusterId());
}
application.appStartup(cluster);
}
Aggregations