Skip to content

Commit

Permalink
fix: Fix Received undefined command from '0' Koenkk/zigbee2mqtt#22140
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed May 6, 2024
1 parent 0d5ef04 commit 2a7ce14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/controller/greenPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class GreenPower extends events.EventEmitter {

public async onZclGreenPowerData(dataPayload: AdapterEvents.ZclPayload, frame: Zcl.ZclFrame): Promise<void> {
try {
switch(frame.payload.commandID) {
const commandID = frame.payload.commandID ?? frame.header.commandIdentifier;
switch(commandID) {
/* istanbul ignore next */
case undefined:
logger.error(`Received undefined command from '${dataPayload.address}'`, NS);
Expand Down Expand Up @@ -207,7 +208,7 @@ class GreenPower extends events.EventEmitter {
break;
default:
// NOTE: this is spammy because it logs everything that is handed back to Controller without special processing here
logger.debug(`Received unhandled command '0x${frame.payload.commandID.toString(16)}' from '${dataPayload.address}'`, NS);
logger.debug(`Received unhandled command '0x${commandID.toString(16)}' from '${dataPayload.address}'`, NS);
}
} catch (error) {
/* istanbul ignore next */
Expand Down
19 changes: 19 additions & 0 deletions test/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4411,6 +4411,25 @@ describe('Controller', () => {
await mockAdapterEvents['']
});

it('Should handle comissioning frame gracefully', async () => {
await controller.start();
const buffer = Buffer.from([25,10,2,11,254,0]);
const frame = Zcl.ZclFrame.fromBuffer(Zcl.Clusters.greenPower.ID, Zcl.ZclHeader.fromBuffer(buffer)!, buffer, {});
await mockAdapterEvents['zclPayload']({
wasBroadcast: true,
address: 0x46f4fe,
clusterID: frame.cluster.ID,
data: buffer,
header: frame.header,
endpoint: 242,
linkquality: 50,
groupID: 1,
});

expect(mockLogger.error).toHaveBeenCalledTimes(0);
expect(mockLogger.debug).toHaveBeenCalledWith(`Received unhandled command '0x2' from '4650238'`, `zh:controller:greenpower`);
});

it('Should ignore invalid green power frame', async () => {
await controller.start();
await mockAdapterEvents['deviceJoined']({networkAddress: 129, ieeeAddr: '0x129'});
Expand Down

0 comments on commit 2a7ce14

Please sign in to comment.