From 1378e86af7e4e651a4ccddcbb560dfcf3597dade Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 20 Nov 2024 14:48:29 +1300 Subject: [PATCH 1/2] Improve command line interpretation of endpoint ID Signed-off-by: Chris Jackson --- .../console/ZigBeeConsoleAbstractCommand.java | 22 +++++++++++++------ .../ZigBeeConsoleReportingConfigCommand.java | 10 +++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java b/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java index 64c4e5c9c..13a8ff4db 100644 --- a/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java +++ b/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java @@ -71,14 +71,22 @@ protected ZigBeeNode getNode(ZigBeeNetworkManager networkManager, final String n */ protected ZigBeeEndpoint getEndpoint(final ZigBeeNetworkManager networkManager, final String endpointId) throws IllegalArgumentException { - for (final ZigBeeNode node : networkManager.getNodes()) { - for (final ZigBeeEndpoint endpoint : node.getEndpoints()) { - if (endpointId.equals(node.getNetworkAddress() + "/" + endpoint.getEndpointId())) { - return endpoint; - } - } + String[] endpointParts = endpointId.split("/"); + if (endpointParts.length != 2) { + throw new IllegalArgumentException("Invalid endpoint format '" + endpointId + "'"); + } + ZigBeeNode node = getNode(networkManager, endpointParts[0]); + Integer endpointNumber; + try { + endpointNumber = Integer.parseInt(endpointParts[1]); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid endpoint number '" + endpointParts[1] + "'"); + } + ZigBeeEndpoint endpoint = node.getEndpoint(endpointNumber); + if (endpoint == null) { + throw new IllegalArgumentException("Endpoint '" + endpointId + "' is not found"); } - throw new IllegalArgumentException("Endpoint '" + endpointId + "' is not found"); + return endpoint; } /** diff --git a/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleReportingConfigCommand.java b/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleReportingConfigCommand.java index 5d7211735..e092902c6 100644 --- a/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleReportingConfigCommand.java +++ b/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleReportingConfigCommand.java @@ -70,15 +70,17 @@ public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStr if (result.isSuccess()) { final ReadReportingConfigurationResponse response = result.getResponse(); final AttributeReportingStatusRecord attributeReportingStatusRecord = response.getRecords().get(0); - + final ZclStatus statusCode = attributeReportingStatusRecord.getStatus(); if (statusCode == ZclStatus.SUCCESS) { out.println("Cluster " + response.getClusterId() + ", Attribute " + attributeReportingStatusRecord.getAttributeIdentifier() + ", type " + attributeReportingStatusRecord.getAttributeDataType() + ", minimum reporting interval: " - + attributeReportingStatusRecord.getMinimumReportingInterval() + ", maximum reporting interval: " - + attributeReportingStatusRecord.getMaximumReportingInterval() + ", timeout: " - + attributeReportingStatusRecord.getTimeoutPeriod()); + + attributeReportingStatusRecord.getMinimumReportingInterval() + + ", maximum reporting interval: " + + attributeReportingStatusRecord.getMaximumReportingInterval() + ", timeout: " + + (attributeReportingStatusRecord.getTimeoutPeriod() == 0 ? "N/A" + : attributeReportingStatusRecord.getTimeoutPeriod())); } else { out.println("Attribute value read error: " + statusCode); } From 7f1f8282f23736a228692a7a2c7c22a83db395a3 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 20 Nov 2024 14:57:21 +1300 Subject: [PATCH 2/2] Use primitive Signed-off-by: Chris Jackson --- .../zigbee/console/ZigBeeConsoleAbstractCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java b/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java index 13a8ff4db..1717103e5 100644 --- a/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java +++ b/com.zsmartsystems.zigbee.console/src/main/java/com/zsmartsystems/zigbee/console/ZigBeeConsoleAbstractCommand.java @@ -76,7 +76,7 @@ protected ZigBeeEndpoint getEndpoint(final ZigBeeNetworkManager networkManager, throw new IllegalArgumentException("Invalid endpoint format '" + endpointId + "'"); } ZigBeeNode node = getNode(networkManager, endpointParts[0]); - Integer endpointNumber; + int endpointNumber; try { endpointNumber = Integer.parseInt(endpointParts[1]); } catch (NumberFormatException e) {