Skip to content

Commit 0ca85d1

Browse files
committed
fix: ZStack: map all data confirm errors
1 parent 81617b3 commit 0ca85d1

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/adapter/z-stack/adapter/zStackAdapter.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ const Type = UnpiConstants.Type;
2929
const {ZnpCommandStatus, AddressMode} = Constants.COMMON;
3030

3131
const DataConfirmTimeout = 9999; // Not an actual code
32-
const DataConfirmErrorCodeLookup: {[k: number]: string} = {
33-
[DataConfirmTimeout]: "Timeout",
34-
26: "MAC no resources",
35-
183: "APS no ack",
36-
205: "No network route",
37-
225: "MAC channel access failure",
38-
233: "MAC no ack",
39-
240: "MAC transaction expired",
40-
};
4132

4233
interface WaitressMatcher {
4334
address?: number | string;
@@ -52,7 +43,8 @@ interface WaitressMatcher {
5243
class DataConfirmError extends Error {
5344
public code: number;
5445
constructor(code: number) {
55-
const message = `Data request failed with error: '${DataConfirmErrorCodeLookup[code]}' (${code})`;
46+
const error = code === DataConfirmTimeout ? "'TIMEOUT'" : `'${ZnpCommandStatus[code]}' (0x${code.toString(16)})`;
47+
const message = `Data request failed with error: ${error}`;
5648
super(message);
5749
this.code = code;
5850
}

test/adapter/z-stack/adapter.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ describe("zstack-adapter", () => {
23572357
} catch (e) {
23582358
error = e;
23592359
}
2360-
expect(error.message).toStrictEqual("Data request failed with error: 'undefined' (201)");
2360+
expect(error.message).toStrictEqual("Data request failed with error: 'NWK_UNSUPPORTED_ATTRIBUTE' (0xc9)");
23612361
});
23622362

23632363
it("Send zcl frame network address with default response", async () => {
@@ -2434,7 +2434,7 @@ describe("zstack-adapter", () => {
24342434
error = e;
24352435
}
24362436

2437-
expect(error.message).toStrictEqual("Data request failed with error: 'MAC transaction expired' (240)");
2437+
expect(error.message).toStrictEqual("Data request failed with error: 'MAC_TRANSACTION_EXPIRED' (0xf0)");
24382438
expect(mockZnpRequest).toHaveBeenCalledTimes(9);
24392439
expect(mockZnpRequestZdo).toHaveBeenCalledTimes(1);
24402440
expect(mockZnpRequest).toHaveBeenNthCalledWith(
@@ -2511,7 +2511,7 @@ describe("zstack-adapter", () => {
25112511
error = e;
25122512
}
25132513

2514-
expect(error.message).toStrictEqual("Data request failed with error: 'MAC transaction expired' (240)");
2514+
expect(error.message).toStrictEqual("Data request failed with error: 'MAC_TRANSACTION_EXPIRED' (0xf0)");
25152515
expect(mockZnpRequest).toHaveBeenCalledTimes(7);
25162516
expect(mockZnpRequestZdo).toHaveBeenCalledTimes(1);
25172517
expect(mockZnpRequest).toHaveBeenNthCalledWith(
@@ -2585,7 +2585,7 @@ describe("zstack-adapter", () => {
25852585
error = e;
25862586
}
25872587

2588-
expect(error.message).toStrictEqual("Data request failed with error: 'MAC no ack' (233)");
2588+
expect(error.message).toStrictEqual("Data request failed with error: 'MAC_NO_ACK' (0xe9)");
25892589
expect(mockZnpRequest).toHaveBeenCalledTimes(6);
25902590
expect(mockZnpRequestZdo).toHaveBeenCalledTimes(1);
25912591
expect(mockZnpRequest).toHaveBeenNthCalledWith(
@@ -2658,7 +2658,7 @@ describe("zstack-adapter", () => {
26582658
error = e;
26592659
}
26602660

2661-
expect(error.message).toStrictEqual("Data request failed with error: 'MAC no ack' (233)");
2661+
expect(error.message).toStrictEqual("Data request failed with error: 'MAC_NO_ACK' (0xe9)");
26622662
// expect(mockZnpRequest).toHaveBeenCalledTimes(7);
26632663
// expect(mockZnpRequestZdo).toHaveBeenCalledTimes(1);
26642664
expect(mockZnpRequest).toHaveBeenNthCalledWith(
@@ -2731,7 +2731,7 @@ describe("zstack-adapter", () => {
27312731
error = e;
27322732
}
27332733

2734-
expect(error.message).toStrictEqual("Data request failed with error: 'MAC no ack' (233)");
2734+
expect(error.message).toStrictEqual("Data request failed with error: 'MAC_NO_ACK' (0xe9)");
27352735
expect(mockZnpRequest).toHaveBeenCalledTimes(1);
27362736
});
27372737

@@ -2814,7 +2814,7 @@ describe("zstack-adapter", () => {
28142814
} catch (e) {
28152815
error = e;
28162816
}
2817-
expect(error.message).toStrictEqual("Data request failed with error: 'Timeout' (9999)");
2817+
expect(error.message).toStrictEqual("Data request failed with error: 'TIMEOUT'");
28182818
expect(mockZnpRequest).toHaveBeenCalledTimes(1);
28192819
expect(mockZnpRequest).toHaveBeenNthCalledWith(
28202820
1,
@@ -3059,7 +3059,7 @@ describe("zstack-adapter", () => {
30593059
},
30603060
99,
30613061
);
3062-
expect(error.message).toStrictEqual("Data request failed with error: 'undefined' (184)");
3062+
expect(error.message).toStrictEqual("Data request failed with error: 'APS_DUPLICATE_ENTRY' (0xb8)");
30633063
});
30643064

30653065
it("Send zcl frame network address and default response", async () => {
@@ -3227,7 +3227,7 @@ describe("zstack-adapter", () => {
32273227
} catch (e) {
32283228
error = e;
32293229
}
3230-
expect(error.message).toStrictEqual("Data request failed with error: 'undefined' (201)");
3230+
expect(error.message).toStrictEqual("Data request failed with error: 'NWK_UNSUPPORTED_ATTRIBUTE' (0xc9)");
32313231
});
32323232

32333233
it("Send zcl frame network address data confirm fails without default response", async () => {
@@ -3241,7 +3241,7 @@ describe("zstack-adapter", () => {
32413241
} catch (e) {
32423242
error = e;
32433243
}
3244-
expect(error.message).toStrictEqual("Data request failed with error: 'undefined' (201)");
3244+
expect(error.message).toStrictEqual("Data request failed with error: 'NWK_UNSUPPORTED_ATTRIBUTE' (0xc9)");
32453245
});
32463246

32473247
it("Send zcl frame network address timeout should discover route and retry", async () => {

0 commit comments

Comments
 (0)