From 667638f5cc837ec62a21e58320e4b74bd98eb227 Mon Sep 17 00:00:00 2001 From: Robin Bolscher Date: Fri, 23 Oct 2026 13:06:25 +0200 Subject: [PATCH 1/2] fix: Ignore a response that has no pending request Some devices send the same response twice. The second copy found no pending request and no handler, so it was logged as an unknown command and answered with an error Default Response, although the device sent a valid response. Ignore responses without a pending request with a debug log instead. Fixes #209 --- lib/Cluster.js | 7 ++++++ test/testClusterResponseTimeout.js | 40 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/Cluster.js b/lib/Cluster.js index 371c65d..d59953f 100644 --- a/lib/Cluster.js +++ b/lib/Cluster.js @@ -893,6 +893,13 @@ class Cluster extends EventEmitter { } } + // A response without a pending request, e.g. a device sending the same response twice, is + // not an error: answering it with an error Default Response would be wrong. + if (command && (command.isResponse || command.name === 'defaultResponse')) { + debug(this.logId, 'ignoring response without pending request:', command.name, frame); + return; + } + debug(this.logId, 'unknown command received:', frame, meta); // ZCL R8 2.5.12.2: UNSUP_COMMAND (0x81, UNSUP_CLUSTER_COMMAND here) diff --git a/test/testClusterResponseTimeout.js b/test/testClusterResponseTimeout.js index add1098..5d3ccd3 100644 --- a/test/testClusterResponseTimeout.js +++ b/test/testClusterResponseTimeout.js @@ -8,6 +8,7 @@ const Node = require('../lib/Node'); const { ZCLDataTypes } = require('../lib/zclTypes'); const BoundCluster = require('../lib/BoundCluster'); const OnOffCluster = require('../lib/clusters/onOff'); +const BasicCluster = require('../lib/clusters/basic'); const AlarmsCluster = require('../lib/clusters/alarms'); const IasZoneCluster = require('../lib/clusters/iasZone'); @@ -371,4 +372,43 @@ describe('Cluster Response Timeout', function () { await assert.rejects(sendingNode.endpoints[1].clusters.onOff.toggle(), /device not responding/); }); + + it('should ignore a duplicate response without sending an error back', async function () { + const sentFrames = []; + const node = new Node({ + sendFrame: async (endpointId, clusterId, frame) => { + sentFrames.push(frame); + if (sentFrames.length > 1) return; + // The device answers with a Read Attributes Response (attribute 0x0004, SUCCESS, "_TZ3000") + // and sends that same response a second time, as some devices do + const response = Buffer.from([ + 0x18, + frame[1], + 0x01, + 0x04, + 0x00, + 0x00, + 0x42, + 0x07, + ...Buffer.from('_TZ3000'), + ]); + setImmediate(async () => { + await node.handleFrame(endpointId, clusterId, response, { dstEndpoint: 1 }); + await node.handleFrame(endpointId, clusterId, response, { dstEndpoint: 1 }); + }); + }, + endpointDescriptors: [{ endpointId: 1, inputClusters: [BasicCluster.ID] }], + }); + + const { basic } = node.endpoints[1].clusters; + const response = await basic.readAttributesStructured( + { attributes: [{ attributeId: 4, indexPath: [] }] }, + { timeout: 1000 }, + ); + await new Promise(setImmediate); + + assert.strictEqual(response.attributes.subarray(5).toString(), '_TZ3000'); + // Only the request went out, no error Default Response for the second copy + assert.strictEqual(sentFrames.length, 1); + }); }); From 84b27e846d2beb51c6beeaab33c0bdd0be0ffd30 Mon Sep 17 00:00:00 2001 From: Robin Bolscher Date: Fri, 23 Oct 2026 13:24:12 +0200 Subject: [PATCH 2/2] test: Keep UNSUP_COMMAND for a known request without a handler Only responses without a pending request are ignored; a server-to-client request the cluster has no handler for must still be answered with UNSUP_COMMAND. --- test/testZCLError.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/testZCLError.js b/test/testZCLError.js index 42a36a1..108aea2 100644 --- a/test/testZCLError.js +++ b/test/testZCLError.js @@ -6,6 +6,7 @@ const BoundCluster = require('../lib/BoundCluster'); const Node = require('../lib/Node'); const OnOffCluster = require('../lib/clusters/onOff'); const LevelControlCluster = require('../lib/clusters/levelControl'); +const IasZoneCluster = require('../lib/clusters/iasZone'); const { ZCLStandardHeader } = require('../lib/zclFrames'); const { ZCLError } = require('../lib/util'); const { createMockNode } = require('./util'); @@ -236,6 +237,31 @@ describe('ZCLError handling', function () { assert.strictEqual(ZCLStandardHeader.fromBuffer(capturedFrames[0].data).data[1], 0x81); }); + // A known request without a handler is still unsupported; only responses without a pending + // request are ignored + it('should send UNSUP_COMMAND (0x81) for a server-to-client request without a handler', async function () { + const capturedFrames = []; + const node = new Node({ + sendFrame: async (endpointId, clusterId, data) => { + capturedFrames.push(data); + }, + endpointDescriptors: [{ endpointId: 1, inputClusters: [IasZoneCluster.ID] }], + }); + const header = new ZCLStandardHeader(); + header.frameControl.clusterSpecific = true; + header.frameControl.directionToClient = true; + header.trxSequenceNumber = 1; + header.cmdId = 0x00; // zoneStatusChangeNotification + header.data = Buffer.from([0x01, 0x00, 0x00, 0x01, 0x00, 0x00]); + + await node.handleFrame(1, IasZoneCluster.ID, header.toBuffer(), {}); + await new Promise(setImmediate); + + const defaultResponse = ZCLStandardHeader.fromBuffer(capturedFrames[0]); + assert.strictEqual(defaultResponse.cmdId, 0x0b); + assert.strictEqual(defaultResponse.data[1], 0x81); + }); + it('should send UNSUPPORTED_CLUSTER (0xc3) for a server-to-client frame on a cluster the endpoint lacks', async function () { const { deviceNode, capturedFrames } = createSpyNodePair(); await deviceNode.handleFrame(1, LevelControlCluster.ID, makeToClientFrame(0x00), {});