Skip to content

Commit 5528094

Browse files
authored
Improve command line interpretation of endpoint ID (#1448)
* Improve command line interpretation of endpoint ID Signed-off-by: Chris Jackson <[email protected]>
1 parent fec6047 commit 5528094

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ protected ZigBeeNode getNode(ZigBeeNetworkManager networkManager, final String n
7171
*/
7272
protected ZigBeeEndpoint getEndpoint(final ZigBeeNetworkManager networkManager, final String endpointId)
7373
throws IllegalArgumentException {
74-
for (final ZigBeeNode node : networkManager.getNodes()) {
75-
for (final ZigBeeEndpoint endpoint : node.getEndpoints()) {
76-
if (endpointId.equals(node.getNetworkAddress() + "/" + endpoint.getEndpointId())) {
77-
return endpoint;
78-
}
79-
}
74+
String[] endpointParts = endpointId.split("/");
75+
if (endpointParts.length != 2) {
76+
throw new IllegalArgumentException("Invalid endpoint format '" + endpointId + "'");
77+
}
78+
ZigBeeNode node = getNode(networkManager, endpointParts[0]);
79+
int endpointNumber;
80+
try {
81+
endpointNumber = Integer.parseInt(endpointParts[1]);
82+
} catch (NumberFormatException e) {
83+
throw new IllegalArgumentException("Invalid endpoint number '" + endpointParts[1] + "'");
84+
}
85+
ZigBeeEndpoint endpoint = node.getEndpoint(endpointNumber);
86+
if (endpoint == null) {
87+
throw new IllegalArgumentException("Endpoint '" + endpointId + "' is not found");
8088
}
81-
throw new IllegalArgumentException("Endpoint '" + endpointId + "' is not found");
89+
return endpoint;
8290
}
8391

8492
/**

com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleReportingConfigCommand.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,17 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr
7070
if (result.isSuccess()) {
7171
final ReadReportingConfigurationResponse response = result.getResponse();
7272
final AttributeReportingStatusRecord attributeReportingStatusRecord = response.getRecords().get(0);
73-
73+
7474
final ZclStatus statusCode = attributeReportingStatusRecord.getStatus();
7575
if (statusCode == ZclStatus.SUCCESS) {
7676
out.println("Cluster " + response.getClusterId() + ", Attribute "
7777
+ attributeReportingStatusRecord.getAttributeIdentifier() + ", type "
7878
+ attributeReportingStatusRecord.getAttributeDataType() + ", minimum reporting interval: "
79-
+ attributeReportingStatusRecord.getMinimumReportingInterval() + ", maximum reporting interval: "
80-
+ attributeReportingStatusRecord.getMaximumReportingInterval() + ", timeout: "
81-
+ attributeReportingStatusRecord.getTimeoutPeriod());
79+
+ attributeReportingStatusRecord.getMinimumReportingInterval()
80+
+ ", maximum reporting interval: "
81+
+ attributeReportingStatusRecord.getMaximumReportingInterval() + ", timeout: "
82+
+ (attributeReportingStatusRecord.getTimeoutPeriod() == 0 ? "N/A"
83+
: attributeReportingStatusRecord.getTimeoutPeriod()));
8284
} else {
8385
out.println("Attribute value read error: " + statusCode);
8486
}

0 commit comments

Comments
 (0)