From 55280947688890eed98c9eed05d89f97bb7564f1 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Wed, 20 Nov 2024 15:04:04 +1300 Subject: [PATCH] Improve command line interpretation of endpoint ID (#1448) * 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 64c4e5c9c6..1717103e53 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]); + int 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 5d7211735b..e092902c62 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); }