use of org.openremote.protocol.zwave.model.commandclasses.ZWParameterItem in project openremote by openremote.
the class ZWaveNetwork method discoverDevices.
public synchronized AssetTreeNode[] discoverDevices(ZWaveAgent agent) {
if (controller == null) {
return new AssetTreeNode[0];
}
// Filter nodes
List<ZWaveNode> nodes = controller.getNodes().stream().filter(node -> node.getState() == INITIALIZATION_FINISHED).filter(node -> {
// Do not add devices that have already been discovered
List<ZWCommandClass> cmdClasses = new ArrayList<>(node.getSupportedCommandClasses());
for (ZWEndPoint curEndpoint : node.getEndPoints()) {
cmdClasses.addAll(curEndpoint.getCmdClasses());
}
return cmdClasses.stream().map(ZWCommandClass::getChannels).flatMap(List<Channel>::stream).noneMatch(channel -> consumerLinkMap.values().stream().anyMatch(link -> link.getChannel() == channel));
}).collect(toList());
List<AssetTreeNode> assetNodes = nodes.stream().map(node -> {
// Root device
AssetTreeNode deviceNode = createDeviceNode(agent.getId(), node.getSupportedCommandClasses(), node.getGenericDeviceClassID().getDisplayName(node.getSpecificDeviceClassID()));
// Device Info
Asset<?> deviceInfoAsset = new ThingAsset("Info");
deviceInfoAsset.getAttributes().addAll(createNodeInfoAttributes(agent.getId(), node));
deviceNode.addChild(new AssetTreeNode(deviceInfoAsset));
for (ZWEndPoint curEndpoint : node.getEndPoints()) {
String subDeviceName = curEndpoint.getGenericDeviceClassID().getDisplayName(curEndpoint.getSpecificDeviceClassID()) + " - " + curEndpoint.getEndPointNumber();
AssetTreeNode subDeviceNode = createDeviceNode(agent.getId(), curEndpoint.getCmdClasses(), subDeviceName);
deviceNode.addChild(subDeviceNode);
}
// Parameters
List<ZWParameterItem> parameters = node.getParameters();
if (parameters.size() > 0) {
AssetTreeNode parameterListNode = new AssetTreeNode(new ThingAsset("Parameters"));
deviceNode.addChild(parameterListNode);
List<AssetTreeNode> parameterNodes = parameters.stream().filter(parameter -> parameter.getChannels().size() > 0).map(parameter -> {
int number = parameter.getNumber();
String parameterLabel = number + " : " + parameter.getDisplayName();
String description = parameter.getDescription();
Asset<?> parameterAsset = new ThingAsset(parameterLabel);
AssetTreeNode parameterNode = new AssetTreeNode(parameterAsset);
List<Attribute<?>> attributes = parameter.getChannels().stream().map(channel -> {
Attribute<?> attribute = TypeMapper.createAttribute(channel.getName(), channel.getChannelType());
addAttributeChannelMetaItems(agent.getId(), attribute, channel);
addValidRangeMeta(attribute, parameter);
return attribute;
}).collect(toList());
if (description != null && description.length() > 0) {
Attribute<String> descriptionAttribute = new Attribute<>("description", org.openremote.model.value.ValueType.TEXT, description);
descriptionAttribute.addMeta(new MetaItem<>(MetaItemType.LABEL, "Description"), new MetaItem<>(MetaItemType.READ_ONLY, true));
attributes.add(descriptionAttribute);
}
parameterAsset.getAttributes().addAll(attributes);
return parameterNode;
}).collect(toList());
parameterNodes.forEach(parameterListNode::addChild);
}
return deviceNode;
}).collect(toList());
// Z-Wave Controller
Asset<?> networkManagementAsset = new ThingAsset("Z-Wave Controller");
List<Attribute<?>> attributes = controller.getSystemCommandManager().getChannels().stream().filter(channel -> consumerLinkMap.values().stream().noneMatch(link -> link.getChannel() == channel)).map(channel -> {
Attribute<?> attribute = TypeMapper.createAttribute(channel.getName(), channel.getChannelType());
addAttributeChannelMetaItems(agent.getId(), attribute, channel);
return attribute;
}).collect(toList());
if (attributes.size() > 0) {
networkManagementAsset.getAttributes().addAll(attributes);
assetNodes.add(new AssetTreeNode(networkManagementAsset));
}
return assetNodes.toArray(new AssetTreeNode[0]);
}
Aggregations