Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/adapter/z-stack/adapter/zStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ const Type = UnpiConstants.Type;
const {ZnpCommandStatus, AddressMode} = Constants.COMMON;

const DataConfirmTimeout = 9999; // Not an actual code
const DataConfirmErrorCodeLookup: {[k: number]: string} = {
[DataConfirmTimeout]: "Timeout",
26: "MAC no resources",
183: "APS no ack",
205: "No network route",
225: "MAC channel access failure",
233: "MAC no ack",
240: "MAC transaction expired",
};

interface WaitressMatcher {
address?: number | string;
Expand All @@ -52,7 +43,8 @@ interface WaitressMatcher {
class DataConfirmError extends Error {
public code: number;
constructor(code: number) {
const message = `Data request failed with error: '${DataConfirmErrorCodeLookup[code]}' (${code})`;
const error = code === DataConfirmTimeout ? "'TIMEOUT'" : `'${ZnpCommandStatus[code]}' (0x${code.toString(16)})`;
const message = `Data request failed with error: ${error}`;
super(message);
this.code = code;
}
Expand Down
20 changes: 10 additions & 10 deletions test/adapter/z-stack/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,7 @@ describe("zstack-adapter", () => {
} catch (e) {
error = e;
}
expect(error.message).toStrictEqual("Data request failed with error: 'undefined' (201)");
expect(error.message).toStrictEqual("Data request failed with error: 'NWK_UNSUPPORTED_ATTRIBUTE' (0xc9)");
});

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

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

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

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

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

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

Expand Down Expand Up @@ -2814,7 +2814,7 @@ describe("zstack-adapter", () => {
} catch (e) {
error = e;
}
expect(error.message).toStrictEqual("Data request failed with error: 'Timeout' (9999)");
expect(error.message).toStrictEqual("Data request failed with error: 'TIMEOUT'");
expect(mockZnpRequest).toHaveBeenCalledTimes(1);
expect(mockZnpRequest).toHaveBeenNthCalledWith(
1,
Expand Down Expand Up @@ -3059,7 +3059,7 @@ describe("zstack-adapter", () => {
},
99,
);
expect(error.message).toStrictEqual("Data request failed with error: 'undefined' (184)");
expect(error.message).toStrictEqual("Data request failed with error: 'APS_DUPLICATE_ENTRY' (0xb8)");
});

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

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

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