zigbee-herdsman 6.0.2 → 6.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +9 -3
  3. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  4. package/.github/dependabot.yml +0 -22
  5. package/.github/workflows/ci.yml +0 -69
  6. package/.github/workflows/release-please.yml +0 -18
  7. package/.github/workflows/stale.yml +0 -20
  8. package/.github/workflows/typedoc.yaml +0 -47
  9. package/.release-please-manifest.json +0 -3
  10. package/.vscode/extensions.json +0 -3
  11. package/.vscode/settings.json +0 -11
  12. package/biome.json +0 -98
  13. package/examples/join-and-log.js +0 -24
  14. package/release-please-config.json +0 -9
  15. package/src/adapter/adapter.ts +0 -189
  16. package/src/adapter/adapterDiscovery.ts +0 -666
  17. package/src/adapter/const.ts +0 -12
  18. package/src/adapter/deconz/adapter/deconzAdapter.ts +0 -877
  19. package/src/adapter/deconz/driver/constants.ts +0 -246
  20. package/src/adapter/deconz/driver/driver.ts +0 -1540
  21. package/src/adapter/deconz/driver/frame.ts +0 -11
  22. package/src/adapter/deconz/driver/frameParser.ts +0 -753
  23. package/src/adapter/deconz/driver/parser.ts +0 -45
  24. package/src/adapter/deconz/driver/writer.ts +0 -22
  25. package/src/adapter/deconz/types.d.ts +0 -13
  26. package/src/adapter/ember/adapter/emberAdapter.ts +0 -2265
  27. package/src/adapter/ember/adapter/endpoints.ts +0 -86
  28. package/src/adapter/ember/adapter/oneWaitress.ts +0 -324
  29. package/src/adapter/ember/adapter/tokensManager.ts +0 -782
  30. package/src/adapter/ember/consts.ts +0 -178
  31. package/src/adapter/ember/enums.ts +0 -1746
  32. package/src/adapter/ember/ezsp/buffalo.ts +0 -1392
  33. package/src/adapter/ember/ezsp/consts.ts +0 -148
  34. package/src/adapter/ember/ezsp/enums.ts +0 -1114
  35. package/src/adapter/ember/ezsp/ezsp.ts +0 -9061
  36. package/src/adapter/ember/ezspError.ts +0 -10
  37. package/src/adapter/ember/types.ts +0 -866
  38. package/src/adapter/ember/uart/ash.ts +0 -1960
  39. package/src/adapter/ember/uart/consts.ts +0 -109
  40. package/src/adapter/ember/uart/enums.ts +0 -192
  41. package/src/adapter/ember/uart/parser.ts +0 -48
  42. package/src/adapter/ember/uart/queues.ts +0 -247
  43. package/src/adapter/ember/uart/writer.ts +0 -53
  44. package/src/adapter/ember/utils/initters.ts +0 -58
  45. package/src/adapter/ember/utils/math.ts +0 -73
  46. package/src/adapter/events.ts +0 -21
  47. package/src/adapter/ezsp/adapter/backup.ts +0 -109
  48. package/src/adapter/ezsp/adapter/ezspAdapter.ts +0 -614
  49. package/src/adapter/ezsp/driver/commands.ts +0 -2497
  50. package/src/adapter/ezsp/driver/consts.ts +0 -11
  51. package/src/adapter/ezsp/driver/driver.ts +0 -1002
  52. package/src/adapter/ezsp/driver/ezsp.ts +0 -802
  53. package/src/adapter/ezsp/driver/frame.ts +0 -101
  54. package/src/adapter/ezsp/driver/index.ts +0 -4
  55. package/src/adapter/ezsp/driver/multicast.ts +0 -78
  56. package/src/adapter/ezsp/driver/parser.ts +0 -81
  57. package/src/adapter/ezsp/driver/types/basic.ts +0 -201
  58. package/src/adapter/ezsp/driver/types/index.ts +0 -239
  59. package/src/adapter/ezsp/driver/types/named.ts +0 -2330
  60. package/src/adapter/ezsp/driver/types/struct.ts +0 -844
  61. package/src/adapter/ezsp/driver/uart.ts +0 -460
  62. package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +0 -44
  63. package/src/adapter/ezsp/driver/utils/index.ts +0 -32
  64. package/src/adapter/ezsp/driver/writer.ts +0 -64
  65. package/src/adapter/index.ts +0 -3
  66. package/src/adapter/serialPort.ts +0 -58
  67. package/src/adapter/socketPortUtils.ts +0 -16
  68. package/src/adapter/tstype.ts +0 -78
  69. package/src/adapter/z-stack/adapter/adapter-backup.ts +0 -519
  70. package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +0 -457
  71. package/src/adapter/z-stack/adapter/endpoints.ts +0 -57
  72. package/src/adapter/z-stack/adapter/manager.ts +0 -543
  73. package/src/adapter/z-stack/adapter/tstype.ts +0 -6
  74. package/src/adapter/z-stack/adapter/zStackAdapter.ts +0 -1190
  75. package/src/adapter/z-stack/constants/af.ts +0 -27
  76. package/src/adapter/z-stack/constants/common.ts +0 -285
  77. package/src/adapter/z-stack/constants/dbg.ts +0 -23
  78. package/src/adapter/z-stack/constants/index.ts +0 -11
  79. package/src/adapter/z-stack/constants/mac.ts +0 -128
  80. package/src/adapter/z-stack/constants/sapi.ts +0 -25
  81. package/src/adapter/z-stack/constants/sys.ts +0 -72
  82. package/src/adapter/z-stack/constants/util.ts +0 -82
  83. package/src/adapter/z-stack/constants/utils.ts +0 -14
  84. package/src/adapter/z-stack/constants/zdo.ts +0 -103
  85. package/src/adapter/z-stack/models/startup-options.ts +0 -13
  86. package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +0 -44
  87. package/src/adapter/z-stack/structs/entries/address-manager-table.ts +0 -19
  88. package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +0 -12
  89. package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +0 -21
  90. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +0 -19
  91. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +0 -21
  92. package/src/adapter/z-stack/structs/entries/channel-list.ts +0 -8
  93. package/src/adapter/z-stack/structs/entries/has-configured.ts +0 -16
  94. package/src/adapter/z-stack/structs/entries/index.ts +0 -16
  95. package/src/adapter/z-stack/structs/entries/nib.ts +0 -66
  96. package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +0 -15
  97. package/src/adapter/z-stack/structs/entries/nwk-key.ts +0 -13
  98. package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +0 -8
  99. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +0 -20
  100. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +0 -19
  101. package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +0 -33
  102. package/src/adapter/z-stack/structs/entries/security-manager-table.ts +0 -22
  103. package/src/adapter/z-stack/structs/index.ts +0 -4
  104. package/src/adapter/z-stack/structs/serializable-memory-object.ts +0 -14
  105. package/src/adapter/z-stack/structs/struct.ts +0 -367
  106. package/src/adapter/z-stack/structs/table.ts +0 -198
  107. package/src/adapter/z-stack/unpi/constants.ts +0 -33
  108. package/src/adapter/z-stack/unpi/frame.ts +0 -62
  109. package/src/adapter/z-stack/unpi/index.ts +0 -4
  110. package/src/adapter/z-stack/unpi/parser.ts +0 -56
  111. package/src/adapter/z-stack/unpi/writer.ts +0 -21
  112. package/src/adapter/z-stack/utils/channel-list.ts +0 -40
  113. package/src/adapter/z-stack/utils/index.ts +0 -2
  114. package/src/adapter/z-stack/utils/network-options.ts +0 -26
  115. package/src/adapter/z-stack/znp/buffaloZnp.ts +0 -175
  116. package/src/adapter/z-stack/znp/definition.ts +0 -2713
  117. package/src/adapter/z-stack/znp/index.ts +0 -2
  118. package/src/adapter/z-stack/znp/parameterType.ts +0 -22
  119. package/src/adapter/z-stack/znp/tstype.ts +0 -44
  120. package/src/adapter/z-stack/znp/utils.ts +0 -10
  121. package/src/adapter/z-stack/znp/znp.ts +0 -342
  122. package/src/adapter/z-stack/znp/zpiObject.ts +0 -148
  123. package/src/adapter/zboss/adapter/zbossAdapter.ts +0 -526
  124. package/src/adapter/zboss/commands.ts +0 -1184
  125. package/src/adapter/zboss/consts.ts +0 -9
  126. package/src/adapter/zboss/driver.ts +0 -422
  127. package/src/adapter/zboss/enums.ts +0 -360
  128. package/src/adapter/zboss/frame.ts +0 -227
  129. package/src/adapter/zboss/reader.ts +0 -65
  130. package/src/adapter/zboss/types.ts +0 -0
  131. package/src/adapter/zboss/uart.ts +0 -428
  132. package/src/adapter/zboss/utils.ts +0 -58
  133. package/src/adapter/zboss/writer.ts +0 -49
  134. package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +0 -27
  135. package/src/adapter/zigate/adapter/zigateAdapter.ts +0 -618
  136. package/src/adapter/zigate/driver/LICENSE +0 -17
  137. package/src/adapter/zigate/driver/buffaloZiGate.ts +0 -212
  138. package/src/adapter/zigate/driver/commandType.ts +0 -418
  139. package/src/adapter/zigate/driver/constants.ts +0 -150
  140. package/src/adapter/zigate/driver/frame.ts +0 -197
  141. package/src/adapter/zigate/driver/messageType.ts +0 -287
  142. package/src/adapter/zigate/driver/parameterType.ts +0 -32
  143. package/src/adapter/zigate/driver/ziGateObject.ts +0 -146
  144. package/src/adapter/zigate/driver/zigate.ts +0 -423
  145. package/src/adapter/zoh/adapter/utils.ts +0 -27
  146. package/src/adapter/zoh/adapter/zohAdapter.ts +0 -838
  147. package/src/buffalo/buffalo.ts +0 -342
  148. package/src/buffalo/index.ts +0 -1
  149. package/src/controller/controller.ts +0 -1022
  150. package/src/controller/database.ts +0 -124
  151. package/src/controller/events.ts +0 -52
  152. package/src/controller/greenPower.ts +0 -603
  153. package/src/controller/helpers/index.ts +0 -1
  154. package/src/controller/helpers/installCodes.ts +0 -107
  155. package/src/controller/helpers/request.ts +0 -96
  156. package/src/controller/helpers/requestQueue.ts +0 -125
  157. package/src/controller/helpers/zclFrameConverter.ts +0 -47
  158. package/src/controller/helpers/zclTransactionSequenceNumber.ts +0 -19
  159. package/src/controller/index.ts +0 -6
  160. package/src/controller/model/device.ts +0 -1249
  161. package/src/controller/model/endpoint.ts +0 -1105
  162. package/src/controller/model/entity.ts +0 -23
  163. package/src/controller/model/group.ts +0 -424
  164. package/src/controller/model/index.ts +0 -5
  165. package/src/controller/model/zigbeeEntity.ts +0 -30
  166. package/src/controller/touchlink.ts +0 -189
  167. package/src/controller/tstype.ts +0 -274
  168. package/src/index.ts +0 -12
  169. package/src/models/backup-storage-legacy.ts +0 -48
  170. package/src/models/backup-storage-unified.ts +0 -47
  171. package/src/models/backup.ts +0 -37
  172. package/src/models/index.ts +0 -5
  173. package/src/models/network-options.ts +0 -11
  174. package/src/utils/backup.ts +0 -152
  175. package/src/utils/index.ts +0 -5
  176. package/src/utils/logger.ts +0 -20
  177. package/src/utils/patchBigIntSerialization.ts +0 -8
  178. package/src/utils/queue.ts +0 -76
  179. package/src/utils/types.d.ts +0 -3
  180. package/src/utils/utils.ts +0 -19
  181. package/src/utils/wait.ts +0 -5
  182. package/src/utils/waitress.ts +0 -96
  183. package/src/zspec/consts.ts +0 -84
  184. package/src/zspec/enums.ts +0 -22
  185. package/src/zspec/index.ts +0 -3
  186. package/src/zspec/tstypes.ts +0 -18
  187. package/src/zspec/utils.ts +0 -247
  188. package/src/zspec/zcl/buffaloZcl.ts +0 -1220
  189. package/src/zspec/zcl/definition/cluster.ts +0 -5915
  190. package/src/zspec/zcl/definition/clusters-typegen.ts +0 -588
  191. package/src/zspec/zcl/definition/clusters-types.ts +0 -7331
  192. package/src/zspec/zcl/definition/consts.ts +0 -24
  193. package/src/zspec/zcl/definition/enums.ts +0 -203
  194. package/src/zspec/zcl/definition/foundation.ts +0 -329
  195. package/src/zspec/zcl/definition/manufacturerCode.ts +0 -729
  196. package/src/zspec/zcl/definition/status.ts +0 -69
  197. package/src/zspec/zcl/definition/tstype.ts +0 -377
  198. package/src/zspec/zcl/index.ts +0 -11
  199. package/src/zspec/zcl/utils.ts +0 -321
  200. package/src/zspec/zcl/zclFrame.ts +0 -356
  201. package/src/zspec/zcl/zclHeader.ts +0 -102
  202. package/src/zspec/zcl/zclStatusError.ts +0 -10
  203. package/src/zspec/zdo/buffaloZdo.ts +0 -2336
  204. package/src/zspec/zdo/definition/clusters.ts +0 -722
  205. package/src/zspec/zdo/definition/consts.ts +0 -16
  206. package/src/zspec/zdo/definition/enums.ts +0 -99
  207. package/src/zspec/zdo/definition/status.ts +0 -105
  208. package/src/zspec/zdo/definition/tstypes.ts +0 -1062
  209. package/src/zspec/zdo/index.ts +0 -7
  210. package/src/zspec/zdo/utils.ts +0 -76
  211. package/src/zspec/zdo/zdoStatusError.ts +0 -10
  212. package/test/adapter/adapter.test.ts +0 -1062
  213. package/test/adapter/ember/ash.test.ts +0 -337
  214. package/test/adapter/ember/consts.ts +0 -131
  215. package/test/adapter/ember/emberAdapter.test.ts +0 -3449
  216. package/test/adapter/ember/ezsp.test.ts +0 -385
  217. package/test/adapter/ember/ezspBuffalo.test.ts +0 -93
  218. package/test/adapter/ember/ezspError.test.ts +0 -12
  219. package/test/adapter/ember/math.test.ts +0 -206
  220. package/test/adapter/ezsp/frame.test.ts +0 -30
  221. package/test/adapter/ezsp/uart.test.ts +0 -181
  222. package/test/adapter/z-stack/adapter.test.ts +0 -3984
  223. package/test/adapter/z-stack/constants.test.ts +0 -33
  224. package/test/adapter/z-stack/structs.test.ts +0 -115
  225. package/test/adapter/z-stack/unpi.test.ts +0 -213
  226. package/test/adapter/z-stack/znp.test.ts +0 -1284
  227. package/test/adapter/zboss/fixZdoResponse.test.ts +0 -179
  228. package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +0 -81
  229. package/test/adapter/zigate/zdo.test.ts +0 -187
  230. package/test/adapter/zoh/utils.test.ts +0 -36
  231. package/test/adapter/zoh/zohAdapter.test.ts +0 -1307
  232. package/test/benchOptions.ts +0 -14
  233. package/test/buffalo.test.ts +0 -431
  234. package/test/controller.bench.ts +0 -214
  235. package/test/controller.test.ts +0 -8702
  236. package/test/greenpower.test.ts +0 -1408
  237. package/test/mockAdapters.ts +0 -65
  238. package/test/mockDevices.ts +0 -598
  239. package/test/requests.bench.ts +0 -229
  240. package/test/testUtils.ts +0 -20
  241. package/test/tsconfig.json +0 -9
  242. package/test/utils/math.ts +0 -19
  243. package/test/utils.test.ts +0 -279
  244. package/test/vitest.config.mts +0 -26
  245. package/test/zcl.test.ts +0 -2831
  246. package/test/zspec/utils.test.ts +0 -68
  247. package/test/zspec/zcl/buffalo.test.ts +0 -1374
  248. package/test/zspec/zcl/frame.test.ts +0 -960
  249. package/test/zspec/zcl/utils.test.ts +0 -273
  250. package/test/zspec/zdo/buffalo.test.ts +0 -1850
  251. package/test/zspec/zdo/utils.test.ts +0 -241
  252. package/tsconfig.json +0 -24
@@ -1,14 +0,0 @@
1
- import {hrtime} from "node:process";
2
- import type {bench} from "vitest";
3
-
4
- export const BENCH_OPTIONS: NonNullable<Parameters<typeof bench>[2]> = {
5
- throws: true,
6
- warmupTime: 1000,
7
- now: () => Number(hrtime.bigint()) / 1e6,
8
- setup: (_task, mode) => {
9
- // Run the garbage collector before warmup at each cycle
10
- if (mode === "warmup" && typeof globalThis.gc === "function") {
11
- globalThis.gc();
12
- }
13
- },
14
- };
@@ -1,431 +0,0 @@
1
- import {describe, expect, it} from "vitest";
2
- import {Buffalo} from "../src/buffalo";
3
- import {ieeeaAddr1, ieeeaAddr2} from "./testUtils";
4
-
5
- describe("Buffalo", () => {
6
- it("is more", () => {
7
- const buffalo = new Buffalo(Buffer.from([0, 1, 2]), 1);
8
- expect(buffalo.getPosition()).toEqual(1);
9
- expect(buffalo.isMore()).toStrictEqual(true);
10
- buffalo.readUInt16();
11
- expect(buffalo.isMore()).toStrictEqual(false);
12
- });
13
-
14
- it("gets written", () => {
15
- const buffalo = new Buffalo(Buffer.alloc(3), 1);
16
- buffalo.writeUInt8(240);
17
- expect(buffalo.getWritten()).toStrictEqual(Buffer.from([0, 240]));
18
- });
19
-
20
- it("UINT8 write", () => {
21
- const buffalo = new Buffalo(Buffer.alloc(3), 1);
22
- buffalo.writeUInt8(240);
23
- expect(buffalo.getPosition()).toEqual(2);
24
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0xf0, 0x00]));
25
- });
26
-
27
- it("UINT8 read", () => {
28
- const buffalo = new Buffalo(Buffer.from([0x00, 0x03, 0x00, 0x00]), 1);
29
- const value = buffalo.readUInt8();
30
- expect(buffalo.getPosition()).toEqual(2);
31
- expect(value).toStrictEqual(3);
32
- });
33
-
34
- it("INT8 write", () => {
35
- const buffalo = new Buffalo(Buffer.alloc(3), 1);
36
- buffalo.writeInt8(127);
37
- expect(buffalo.getPosition()).toEqual(2);
38
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x7f, 0x00]));
39
- });
40
-
41
- it("INT8 read", () => {
42
- const buffalo = new Buffalo(Buffer.from([0x00, 0xf0, 0x00, 0x00]), 1);
43
- const value = buffalo.readInt8();
44
- expect(buffalo.getPosition()).toEqual(2);
45
- expect(value).toStrictEqual(-16);
46
- });
47
-
48
- it("INT16 write", () => {
49
- const buffalo = new Buffalo(Buffer.alloc(3), 1);
50
- buffalo.writeInt16(256);
51
- expect(buffalo.getPosition()).toEqual(3);
52
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00, 0x01]));
53
- });
54
-
55
- it("INT16 read", () => {
56
- const buffalo = new Buffalo(Buffer.from([0x00, 0xff, 0xff, 0x00]), 1);
57
- const value = buffalo.readInt16();
58
- expect(buffalo.getPosition()).toEqual(3);
59
- expect(value).toStrictEqual(-1);
60
- });
61
-
62
- it("UINT16 write", () => {
63
- const buffalo = new Buffalo(Buffer.alloc(3), 1);
64
- buffalo.writeUInt16(1020);
65
- expect(buffalo.getPosition()).toEqual(3);
66
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0xfc, 0x03]));
67
- });
68
-
69
- it("UINT16 read", () => {
70
- const buffalo = new Buffalo(Buffer.from([0x00, 0x03, 0xff, 0x00]), 1);
71
- const value = buffalo.readUInt16();
72
- expect(buffalo.getPosition()).toEqual(3);
73
- expect(value).toStrictEqual(65283);
74
- });
75
-
76
- it("INT32 write", () => {
77
- const buffalo = new Buffalo(Buffer.alloc(6), 2);
78
- buffalo.writeInt32(1065283);
79
- expect(buffalo.getPosition()).toEqual(6);
80
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00, 0x43, 0x41, 0x10, 0x00]));
81
- });
82
-
83
- it("INT32 read", () => {
84
- const buffalo = new Buffalo(Buffer.from([0x01, 0x03, 0xff, 0xff]));
85
- const value = buffalo.readInt32();
86
- expect(buffalo.getPosition()).toEqual(4);
87
- expect(value).toStrictEqual(-64767);
88
- });
89
-
90
- it("UINT32 write", () => {
91
- const buffalo = new Buffalo(Buffer.alloc(6), 2);
92
- buffalo.writeUInt32(1065283);
93
- expect(buffalo.getPosition()).toEqual(6);
94
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00, 0x43, 0x41, 0x10, 0x00]));
95
- });
96
-
97
- it("UINT32 read", () => {
98
- const buffalo = new Buffalo(Buffer.from([0x01, 0x03, 0xff, 0xff]));
99
- const value = buffalo.readUInt32();
100
- expect(buffalo.getPosition()).toEqual(4);
101
- expect(value).toStrictEqual(4294902529);
102
- });
103
-
104
- it("INT40 write", () => {
105
- const buffalo = new Buffalo(Buffer.alloc(7), 2);
106
- buffalo.writeInt40(21542142465);
107
- expect(buffalo.getPosition()).toEqual(7);
108
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 1, 2, 3, 4, 5]));
109
- });
110
-
111
- it("INT40 read", () => {
112
- const buffalo = new Buffalo(Buffer.from([1, 2, 3, 4, 5]));
113
- const value = buffalo.readInt40();
114
- expect(buffalo.getPosition()).toEqual(5);
115
- expect(value).toStrictEqual(21542142465);
116
- });
117
-
118
- it("UINT40 write", () => {
119
- const buffalo = new Buffalo(Buffer.alloc(7), 2);
120
- buffalo.writeUInt40(21542142465);
121
- expect(buffalo.getPosition()).toEqual(7);
122
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 1, 2, 3, 4, 5]));
123
- });
124
-
125
- it("UINT40 read", () => {
126
- const buffalo = new Buffalo(Buffer.from([1, 2, 3, 4, 5]));
127
- const value = buffalo.readUInt40();
128
- expect(buffalo.getPosition()).toEqual(5);
129
- expect(value).toStrictEqual(21542142465);
130
- });
131
-
132
- it("INT48 write", () => {
133
- const buffalo = new Buffalo(Buffer.alloc(8), 2);
134
- buffalo.writeInt48(6618611909121);
135
- expect(buffalo.getPosition()).toEqual(8);
136
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 1, 2, 3, 4, 5, 6]));
137
- });
138
-
139
- it("INT48 read", () => {
140
- const buffalo = new Buffalo(Buffer.from([1, 2, 3, 4, 5, 6]));
141
- const value = buffalo.readInt48();
142
- expect(buffalo.getPosition()).toEqual(6);
143
- expect(value).toStrictEqual(6618611909121);
144
- });
145
-
146
- it("UINT48 write", () => {
147
- const buffalo = new Buffalo(Buffer.alloc(8), 2);
148
- buffalo.writeUInt48(6618611909121);
149
- expect(buffalo.getPosition()).toEqual(8);
150
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 1, 2, 3, 4, 5, 6]));
151
- });
152
-
153
- it("UINT48 read", () => {
154
- const buffalo = new Buffalo(Buffer.from([1, 2, 3, 4, 5, 6]));
155
- const value = buffalo.readUInt48();
156
- expect(buffalo.getPosition()).toEqual(6);
157
- expect(value).toStrictEqual(6618611909121);
158
- });
159
-
160
- it("UINT56 write", () => {
161
- const buffalo = new Buffalo(Buffer.alloc(9), 2);
162
- buffalo.writeUInt56(72057594037927934n);
163
- expect(buffalo.getPosition()).toEqual(9);
164
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 254, 255, 255, 255, 255, 255, 255]));
165
- });
166
-
167
- it("UINT56 read", () => {
168
- const buffalo = new Buffalo(Buffer.from([254, 255, 255, 255, 255, 255, 255]));
169
- const value = buffalo.readUInt56();
170
- expect(buffalo.getPosition()).toEqual(7);
171
- expect(value).toStrictEqual(72057594037927934n);
172
- });
173
-
174
- it.each([
175
- [36028797018963964n, [0, 0, 252, 255, 255, 255, 255, 255, 127]],
176
- [-36028797018963964n, [0, 0, 4, 0, 0, 0, 0, 0, 128]],
177
- ])("INT56 write", (value: bigint, expectedValues: number[]) => {
178
- const buffalo = new Buffalo(Buffer.alloc(9), 2);
179
- buffalo.writeInt56(value);
180
- expect(buffalo.getPosition()).toEqual(9);
181
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from(expectedValues));
182
- });
183
-
184
- it.each([
185
- [36028797018963964n, [252, 255, 255, 255, 255, 255, 127]],
186
- [-36028797018963964n, [4, 0, 0, 0, 0, 0, 128]],
187
- ])("INT56 read", (expectedValue: bigint, values: number[]) => {
188
- const buffalo = new Buffalo(Buffer.from(values));
189
- const value = buffalo.readInt56();
190
- expect(buffalo.getPosition()).toEqual(7);
191
- expect(value).toStrictEqual(expectedValue);
192
- });
193
-
194
- it("UINT64 write", () => {
195
- const buffalo = new Buffalo(Buffer.alloc(10), 2);
196
- buffalo.writeUInt64(18446744073709551613n);
197
- expect(buffalo.getPosition()).toEqual(10);
198
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 253, 255, 255, 255, 255, 255, 255, 255]));
199
- });
200
-
201
- it("UINT64 read", () => {
202
- const buffalo = new Buffalo(Buffer.from([253, 255, 255, 255, 255, 255, 255, 255]));
203
- const value = buffalo.readUInt64();
204
- expect(buffalo.getPosition()).toEqual(8);
205
- expect(value).toStrictEqual(18446744073709551613n);
206
- });
207
-
208
- it("INT64 write", () => {
209
- const buffalo = new Buffalo(Buffer.alloc(10), 2);
210
- buffalo.writeInt64(9223372036854775806n);
211
- expect(buffalo.getPosition()).toEqual(10);
212
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0, 0, 254, 255, 255, 255, 255, 255, 255, 127]));
213
- });
214
-
215
- it("INT64 read", () => {
216
- const buffalo = new Buffalo(Buffer.from([254, 255, 255, 255, 255, 255, 255, 127]));
217
- const value = buffalo.readInt64();
218
- expect(buffalo.getPosition()).toEqual(8);
219
- expect(value).toStrictEqual(9223372036854775806n);
220
- });
221
-
222
- it("IEEEADDR write", () => {
223
- const buffalo = new Buffalo(Buffer.alloc(8));
224
- buffalo.writeIeeeAddr(ieeeaAddr1.string);
225
- expect(buffalo.getPosition()).toEqual(8);
226
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from(ieeeaAddr1.hex));
227
- });
228
-
229
- it("IEEEADDR read", () => {
230
- const buffalo = new Buffalo(Buffer.from(ieeeaAddr2.hex));
231
- const value = buffalo.readIeeeAddr();
232
- expect(buffalo.getPosition()).toEqual(8);
233
- expect(value).toStrictEqual(ieeeaAddr2.string);
234
- });
235
-
236
- it("BUFFER write", () => {
237
- const buffalo = new Buffalo(Buffer.alloc(5), 1);
238
- const payload = Buffer.from([0x00, 0x01, 0x02]);
239
- buffalo.writeBuffer(payload, payload.length);
240
- expect(buffalo.getPosition()).toEqual(4);
241
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, ...payload, 0x00]));
242
- });
243
-
244
- it("BUFFER write as array", () => {
245
- const buffalo = new Buffalo(Buffer.alloc(5), 1);
246
- const payload = [0x00, 0x01, 0x02];
247
- buffalo.writeBuffer(payload, payload.length);
248
- expect(buffalo.getPosition()).toEqual(4);
249
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, ...payload, 0x00]));
250
- });
251
-
252
- it("BUFFER read", () => {
253
- const buffalo = new Buffalo(Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09]), 2);
254
- const value = buffalo.readBuffer(5);
255
- expect(buffalo.getPosition()).toEqual(7);
256
- expect(value).toStrictEqual(Buffer.from([0x02, 0x03, 0x04, 0x05, 0x06]));
257
- });
258
-
259
- it("LIST_UINT8 write", () => {
260
- const buffalo = new Buffalo(Buffer.alloc(4), 1);
261
- const payload = [200, 100];
262
- buffalo.writeListUInt8(payload);
263
- expect(buffalo.getPosition()).toStrictEqual(3);
264
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0xc8, 0x64, 0x00]));
265
- });
266
-
267
- it("LIST_UINT8 read", () => {
268
- const buffalo = new Buffalo(Buffer.from([0x00, 0x00, 0x04, 0x08]), 2);
269
- const value = buffalo.readListUInt8(2);
270
- expect(buffalo.getPosition()).toStrictEqual(4);
271
- expect(value).toStrictEqual([4, 8]);
272
- });
273
-
274
- it("LIST_UINT16 write", () => {
275
- const buffalo = new Buffalo(Buffer.alloc(5), 1);
276
- const payload = [1024, 2048];
277
- buffalo.writeListUInt16(payload);
278
- expect(buffalo.getPosition()).toStrictEqual(5);
279
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00, 0x04, 0x00, 0x08]));
280
- });
281
-
282
- it("LIST_UINT16 read", () => {
283
- const buffalo = new Buffalo(Buffer.from([0x00, 0x00, 0x04, 0x00, 0x08]), 1);
284
- const value = buffalo.readListUInt16(2);
285
- expect(buffalo.getPosition()).toStrictEqual(5);
286
- expect(value).toStrictEqual([1024, 2048]);
287
- });
288
-
289
- it("LIST_UINT24 write", () => {
290
- const buffalo = new Buffalo(Buffer.alloc(8), 1);
291
- const payload = [100000, 110110];
292
- buffalo.writeListUInt24(payload);
293
- expect(buffalo.getPosition()).toStrictEqual(7);
294
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0xa0, 0x86, 0x01, 0x1e, 0xae, 0x01, 0x00]));
295
- });
296
-
297
- it("LIST_UINT24 read", () => {
298
- const buffalo = new Buffalo(Buffer.from([0x00, 0xa0, 0x86, 0x01, 0x1e, 0xae, 0x01, 0x00]), 1);
299
- const value = buffalo.readListUInt24(2);
300
- expect(buffalo.getPosition()).toStrictEqual(7);
301
- expect(value).toStrictEqual([100000, 110110]);
302
- });
303
-
304
- it("LIST_UINT32 write", () => {
305
- const buffalo = new Buffalo(Buffer.alloc(8));
306
- const payload = [4294967295, 10];
307
- buffalo.writeListUInt32(payload);
308
- expect(buffalo.getPosition()).toStrictEqual(8);
309
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0xff, 0xff, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00]));
310
- });
311
-
312
- it("LIST_UINT32 read", () => {
313
- const buffalo = new Buffalo(Buffer.from([0xff, 0xff, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00]));
314
- const value = buffalo.readListUInt32(2);
315
- expect(buffalo.getPosition()).toStrictEqual(8);
316
- expect(value).toStrictEqual([4294967295, 10]);
317
- });
318
-
319
- it("UINT24 write", () => {
320
- const buffalo = new Buffalo(Buffer.alloc(4), 1);
321
- const payload = 16777200;
322
- buffalo.writeUInt24(payload);
323
- expect(buffalo.getPosition()).toStrictEqual(4);
324
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0xf0, 0xff, 0xff]));
325
- });
326
-
327
- it("UINT24 read", () => {
328
- const buffalo = new Buffalo(Buffer.from([0x01, 0xa0, 0x86, 0x01, 0x02]), 1);
329
- const value = buffalo.readUInt24();
330
- expect(buffalo.getPosition()).toStrictEqual(4);
331
- expect(value).toStrictEqual(100000);
332
- });
333
-
334
- it("INT24 write +", () => {
335
- const buffalo = new Buffalo(Buffer.alloc(3));
336
- buffalo.writeInt24(65536);
337
- expect(buffalo.getPosition()).toStrictEqual(3);
338
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00, 0x01]));
339
- });
340
-
341
- it("INT24 read +", () => {
342
- const buffalo = new Buffalo(Buffer.from([0x7f, 0xff, 0xff, 0x7f]), 1);
343
- const value = buffalo.readInt24();
344
- expect(buffalo.getPosition()).toStrictEqual(4);
345
- expect(value).toStrictEqual(8388607);
346
- });
347
-
348
- it("INT24 write -", () => {
349
- const buffalo = new Buffalo(Buffer.alloc(3));
350
- buffalo.writeInt24(-65536);
351
- expect(buffalo.getPosition()).toStrictEqual(3);
352
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00, 0xff]));
353
- });
354
-
355
- it("INT24 read -", () => {
356
- const buffalo = new Buffalo(Buffer.from([0x00, 0x00, 0xff]));
357
- const value = buffalo.readInt24();
358
- expect(buffalo.getPosition()).toStrictEqual(3);
359
- expect(value).toStrictEqual(-65536);
360
- });
361
-
362
- it("INT32 write", () => {
363
- const buffalo = new Buffalo(Buffer.alloc(4));
364
- buffalo.writeInt32(2147483647);
365
- expect(buffalo.getPosition()).toStrictEqual(4);
366
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0xff, 0xff, 0xff, 0x7f]));
367
- });
368
-
369
- it("INT32 read", () => {
370
- const buffalo = new Buffalo(Buffer.from([0x08, 0xff, 0x03, 0xff]));
371
- const value = buffalo.readInt32();
372
- expect(buffalo.getPosition()).toStrictEqual(4);
373
- expect(value).toStrictEqual(-16515320);
374
- });
375
-
376
- it("INT48 write", () => {
377
- const buffalo = new Buffalo(Buffer.alloc(6));
378
- buffalo.writeInt48(-1082348273920);
379
- expect(buffalo.getPosition()).toStrictEqual(6);
380
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0xff, 0x03, 0xff, 0x03, 0xff]));
381
- });
382
-
383
- it("INT48 read", () => {
384
- const buffalo = new Buffalo(Buffer.from([0x00, 0xff, 0x03, 0xff, 0x03, 0xff]));
385
- const value = buffalo.readInt48();
386
- expect(buffalo.getPosition()).toStrictEqual(6);
387
- expect(value).toStrictEqual(-1082348273920);
388
- });
389
-
390
- it("FLOATLE write", () => {
391
- const buffalo = new Buffalo(Buffer.alloc(4));
392
- buffalo.writeFloatLE(400.5);
393
- expect(buffalo.getPosition()).toStrictEqual(4);
394
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x40, 0xc8, 0x43]));
395
- });
396
-
397
- it("FLOATLE read", () => {
398
- const buffalo = new Buffalo(Buffer.from([0x00, 0x40, 0xc8, 0x43]));
399
- const value = buffalo.readFloatLE();
400
- expect(buffalo.getPosition()).toStrictEqual(4);
401
- expect(value).toStrictEqual(400.5);
402
- });
403
-
404
- it("DOUBLELE write", () => {
405
- const buffalo = new Buffalo(Buffer.alloc(8));
406
- buffalo.writeDoubleLE(809880.6);
407
- expect(buffalo.getPosition()).toStrictEqual(8);
408
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x33, 0x33, 0x33, 0x33, 0x31, 0xb7, 0x28, 0x41]));
409
- });
410
-
411
- it("DOUBLELE read", () => {
412
- const buffalo = new Buffalo(Buffer.from([0x33, 0x33, 0x33, 0x33, 0x31, 0xb7, 0x28, 0x41]), 0);
413
- const value = buffalo.readDoubleLE();
414
- expect(buffalo.getPosition()).toStrictEqual(8);
415
- expect(value).toStrictEqual(809880.6);
416
- });
417
-
418
- it("UTF8 STRING write", () => {
419
- const buffalo = new Buffalo(Buffer.alloc(4));
420
- buffalo.writeUtf8String("abcd");
421
- expect(buffalo.getPosition()).toStrictEqual(4);
422
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x61, 0x62, 0x63, 0x64]));
423
- });
424
-
425
- it("UTF8 STRING read", () => {
426
- const buffalo = new Buffalo(Buffer.from([0x61, 0x62, 0x63, 0x64]), 0);
427
- const value = buffalo.readUtf8String(4);
428
- expect(buffalo.getPosition()).toStrictEqual(4);
429
- expect(value).toStrictEqual("abcd");
430
- });
431
- });
@@ -1,214 +0,0 @@
1
- import {bench, describe} from "vitest";
2
- import Adapter from "../src/adapter/adapter";
3
- import {FIXED_ENDPOINTS} from "../src/adapter/ember/adapter/endpoints";
4
- import type {ZclPayload} from "../src/adapter/events";
5
- import {Controller} from "../src/controller";
6
- import Database from "../src/controller/database";
7
- import {setLogger} from "../src/utils/logger";
8
- import * as Zcl from "../src/zspec/zcl";
9
- import * as Zdo from "../src/zspec/zdo";
10
- import {BENCH_OPTIONS} from "./benchOptions";
11
-
12
- // mock necessary functions to avoid system calls / adapter interactions
13
-
14
- // no-op, makes up for too much of the perf loss (with console logging by default)
15
- setLogger({
16
- debug: () => {},
17
- info: () => {},
18
- warning: () => {},
19
- error: () => {},
20
- });
21
-
22
- const NETWORK_OPTIONS = {
23
- panID: 0x1a62,
24
- extendedPanID: [0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd],
25
- channelList: [11],
26
- networkKey: [1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 13],
27
- // networkKeyDistribute?: boolean;
28
- };
29
- const COORD_IEEE = "0x1234567812345678";
30
-
31
- let controller: Controller;
32
- let adapter: Adapter;
33
-
34
- const makeController = () => {
35
- controller = new Controller({
36
- network: NETWORK_OPTIONS,
37
- serialPort: {
38
- baudRate: 115200,
39
- rtscts: false,
40
- path: "/dev/ttyDummy0",
41
- adapter: "ember",
42
- },
43
- databasePath: "database.db",
44
- databaseBackupPath: "database.db.backup",
45
- backupPath: "coordinator_backup.json",
46
- adapter: {
47
- // concurrent?: number;
48
- // delay?: number;
49
- disableLED: false,
50
- // transmitPower?: number;
51
- // forceStartWithInconsistentAdapterConfiguration?: boolean;
52
- },
53
- acceptJoiningDeviceHandler: async () => true,
54
- });
55
- controller.backup = async () => {};
56
-
57
- const dbOpen = Database.open;
58
- Database.open = (path) => {
59
- const db = dbOpen(path);
60
- // no-op
61
- db.write = () => {};
62
-
63
- return db;
64
- };
65
- const adapterCreate = Adapter.create;
66
- Adapter.create = async (networkOptions, serialPortOptions, backupPath, adapterOptions) => {
67
- adapter = await adapterCreate(networkOptions, serialPortOptions, backupPath, adapterOptions);
68
- adapter.start = async () => await Promise.resolve("resumed");
69
- adapter.getCoordinatorIEEE = async () => await Promise.resolve(COORD_IEEE);
70
- adapter.getNetworkParameters = async () =>
71
- await Promise.resolve({
72
- panID: NETWORK_OPTIONS.panID,
73
- extendedPanID: `${Buffer.from(NETWORK_OPTIONS.extendedPanID!).toString("hex")}`,
74
- channel: NETWORK_OPTIONS.channelList[0],
75
- nwkUpdateID: 1,
76
- });
77
- // @ts-expect-error ignore overrides typing
78
- adapter.sendZdo = async (
79
- _ieeeAddress: string,
80
- networkAddress: number,
81
- clusterId: Zdo.ClusterId,
82
- payload: Buffer,
83
- _disableResponse: boolean,
84
- ) => {
85
- if (networkAddress === 0x0000) {
86
- switch (clusterId) {
87
- case Zdo.ClusterId.ACTIVE_ENDPOINTS_REQUEST: {
88
- return await Promise.resolve([
89
- Zdo.Status.SUCCESS,
90
- {
91
- nwkAddress: 0x0000,
92
- endpointList: [FIXED_ENDPOINTS[0].endpoint, FIXED_ENDPOINTS[1].endpoint],
93
- },
94
- ]);
95
- }
96
- case Zdo.ClusterId.SIMPLE_DESCRIPTOR_REQUEST: {
97
- if (payload.readUInt8(3) === FIXED_ENDPOINTS[0].endpoint) {
98
- return await Promise.resolve([
99
- Zdo.Status.SUCCESS,
100
- {
101
- nwkAddress: 0x0000,
102
- length: 1, // unused
103
- ...FIXED_ENDPOINTS[0],
104
- },
105
- ]);
106
- }
107
-
108
- if (payload.readUInt8(3) === FIXED_ENDPOINTS[1].endpoint) {
109
- return await Promise.resolve([
110
- Zdo.Status.SUCCESS,
111
- {
112
- nwkAddress: 0x0000,
113
- length: 1, // unused
114
- ...FIXED_ENDPOINTS[1],
115
- },
116
- ]);
117
- }
118
- }
119
- }
120
- }
121
-
122
- return await Promise.resolve([Zdo.Status.NOT_SUPPORTED]);
123
- };
124
-
125
- return adapter;
126
- };
127
-
128
- return controller;
129
- };
130
-
131
- const BASIC_RESP = Zcl.Frame.create(
132
- 0,
133
- 1,
134
- true,
135
- undefined,
136
- 10,
137
- "readRsp",
138
- 0,
139
- [
140
- {
141
- attrId: 5,
142
- dataType: Zcl.DataType.CHAR_STR,
143
- attrData: "Herd-01",
144
- status: 0,
145
- },
146
- {
147
- attrId: 4,
148
- dataType: Zcl.DataType.CHAR_STR,
149
- attrData: "Herdsman",
150
- status: 0,
151
- },
152
- ],
153
- {},
154
- ).toBuffer();
155
-
156
- describe("Controller", () => {
157
- bench(
158
- "Startup with dummy adapter",
159
- async () => {
160
- makeController(); // always use brand new Controller for this bench
161
-
162
- await controller.start();
163
- },
164
- BENCH_OPTIONS,
165
- );
166
-
167
- bench(
168
- "Receive ZCL message",
169
- () => {
170
- adapter.emit("zclPayload", {
171
- clusterID: Zcl.Clusters.genBasic.ID,
172
- header: Zcl.Header.fromBuffer(BASIC_RESP),
173
- address: 0x0000,
174
- data: BASIC_RESP,
175
- endpoint: 1,
176
- linkquality: 200,
177
- groupID: 0,
178
- wasBroadcast: false,
179
- destinationEndpoint: 1,
180
- } satisfies ZclPayload);
181
- },
182
- {
183
- ...BENCH_OPTIONS,
184
- setup: async (task, mode) => {
185
- await BENCH_OPTIONS.setup!(task, mode);
186
- makeController();
187
- await controller.start();
188
- },
189
- },
190
- );
191
-
192
- bench(
193
- "Receive ZDO message",
194
- () => {
195
- adapter.emit("zdoResponse", Zdo.ClusterId.NETWORK_ADDRESS_RESPONSE, [
196
- Zdo.Status.SUCCESS,
197
- {
198
- eui64: COORD_IEEE,
199
- nwkAddress: 0x0000,
200
- startIndex: 1,
201
- assocDevList: [],
202
- },
203
- ]);
204
- },
205
- {
206
- ...BENCH_OPTIONS,
207
- setup: async (task, mode) => {
208
- await BENCH_OPTIONS.setup!(task, mode);
209
- makeController();
210
- await controller.start();
211
- },
212
- },
213
- );
214
- });