Skip to content

Commit

Permalink
test(cluster): add test for handling frames
Browse files Browse the repository at this point in the history
The tests ensure that:
1. A cluster specific response is sent even when disable default response is set.
2. A default response is not sent when disable default response is set.
3. A default response is not sent in response to receiving a default response.
4. A default response is not sent in response to a group addressed frame.
5. A default response (error status) is sent when the frame could not be handled by the resp. cluster.
  • Loading branch information
RobinBol committed Jan 7, 2025
1 parent 6ec65d1 commit 9ee11bc
Show file tree
Hide file tree
Showing 4 changed files with 469 additions and 24 deletions.
12 changes: 8 additions & 4 deletions lib/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ class Endpoint extends EventEmitter {
*/
async handleFrame(clusterId, frame, meta) {
const rawFrame = frame;

if (rawFrame[0] & 0x4) {
frame = ZCLMfgSpecificHeader.fromBuffer(rawFrame);
} else frame = ZCLStandardHeader.fromBuffer(rawFrame);
frame = Endpoint.parseFrame(frame);

// NOTE: we do not respond with a default response if:
// 1. The frame we received is a default response (frame.cmdId = 11)
Expand Down Expand Up @@ -194,6 +191,13 @@ class Endpoint extends EventEmitter {
return result;
}

static parseFrame(frame) {
if (frame[0] & 0x4) {
return ZCLMfgSpecificHeader.fromBuffer(frame);
}
return ZCLStandardHeader.fromBuffer(frame);
}

}

module.exports = Endpoint;
Loading

0 comments on commit 9ee11bc

Please sign in to comment.