zigbee-herdsman 6.0.1 → 6.0.3

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 (260) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/adapter/ezsp/driver/uart.js +1 -1
  3. package/dist/adapter/ezsp/driver/uart.js.map +1 -1
  4. package/dist/adapter/z-stack/adapter/zStackAdapter.js +4 -4
  5. package/dist/adapter/z-stack/adapter/zStackAdapter.js.map +1 -1
  6. package/dist/adapter/zigate/adapter/zigateAdapter.js +4 -4
  7. package/dist/adapter/zigate/adapter/zigateAdapter.js.map +1 -1
  8. package/dist/controller/model/device.d.ts.map +1 -1
  9. package/dist/controller/model/device.js +1 -0
  10. package/dist/controller/model/device.js.map +1 -1
  11. package/package.json +14 -6
  12. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  13. package/.github/dependabot.yml +0 -22
  14. package/.github/workflows/ci.yml +0 -64
  15. package/.github/workflows/release-please.yml +0 -18
  16. package/.github/workflows/stale.yml +0 -20
  17. package/.github/workflows/typedoc.yaml +0 -47
  18. package/.release-please-manifest.json +0 -3
  19. package/.vscode/extensions.json +0 -3
  20. package/.vscode/settings.json +0 -11
  21. package/biome.json +0 -98
  22. package/examples/join-and-log.js +0 -24
  23. package/release-please-config.json +0 -9
  24. package/src/adapter/adapter.ts +0 -189
  25. package/src/adapter/adapterDiscovery.ts +0 -666
  26. package/src/adapter/const.ts +0 -12
  27. package/src/adapter/deconz/adapter/deconzAdapter.ts +0 -877
  28. package/src/adapter/deconz/driver/constants.ts +0 -246
  29. package/src/adapter/deconz/driver/driver.ts +0 -1540
  30. package/src/adapter/deconz/driver/frame.ts +0 -11
  31. package/src/adapter/deconz/driver/frameParser.ts +0 -753
  32. package/src/adapter/deconz/driver/parser.ts +0 -45
  33. package/src/adapter/deconz/driver/writer.ts +0 -22
  34. package/src/adapter/deconz/types.d.ts +0 -13
  35. package/src/adapter/ember/adapter/emberAdapter.ts +0 -2265
  36. package/src/adapter/ember/adapter/endpoints.ts +0 -86
  37. package/src/adapter/ember/adapter/oneWaitress.ts +0 -324
  38. package/src/adapter/ember/adapter/tokensManager.ts +0 -782
  39. package/src/adapter/ember/consts.ts +0 -178
  40. package/src/adapter/ember/enums.ts +0 -1746
  41. package/src/adapter/ember/ezsp/buffalo.ts +0 -1392
  42. package/src/adapter/ember/ezsp/consts.ts +0 -148
  43. package/src/adapter/ember/ezsp/enums.ts +0 -1114
  44. package/src/adapter/ember/ezsp/ezsp.ts +0 -9061
  45. package/src/adapter/ember/ezspError.ts +0 -10
  46. package/src/adapter/ember/types.ts +0 -866
  47. package/src/adapter/ember/uart/ash.ts +0 -1960
  48. package/src/adapter/ember/uart/consts.ts +0 -109
  49. package/src/adapter/ember/uart/enums.ts +0 -192
  50. package/src/adapter/ember/uart/parser.ts +0 -48
  51. package/src/adapter/ember/uart/queues.ts +0 -247
  52. package/src/adapter/ember/uart/writer.ts +0 -53
  53. package/src/adapter/ember/utils/initters.ts +0 -58
  54. package/src/adapter/ember/utils/math.ts +0 -73
  55. package/src/adapter/events.ts +0 -21
  56. package/src/adapter/ezsp/adapter/backup.ts +0 -109
  57. package/src/adapter/ezsp/adapter/ezspAdapter.ts +0 -614
  58. package/src/adapter/ezsp/driver/commands.ts +0 -2497
  59. package/src/adapter/ezsp/driver/consts.ts +0 -11
  60. package/src/adapter/ezsp/driver/driver.ts +0 -1002
  61. package/src/adapter/ezsp/driver/ezsp.ts +0 -802
  62. package/src/adapter/ezsp/driver/frame.ts +0 -101
  63. package/src/adapter/ezsp/driver/index.ts +0 -4
  64. package/src/adapter/ezsp/driver/multicast.ts +0 -78
  65. package/src/adapter/ezsp/driver/parser.ts +0 -81
  66. package/src/adapter/ezsp/driver/types/basic.ts +0 -201
  67. package/src/adapter/ezsp/driver/types/index.ts +0 -239
  68. package/src/adapter/ezsp/driver/types/named.ts +0 -2330
  69. package/src/adapter/ezsp/driver/types/struct.ts +0 -844
  70. package/src/adapter/ezsp/driver/uart.ts +0 -460
  71. package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +0 -44
  72. package/src/adapter/ezsp/driver/utils/index.ts +0 -32
  73. package/src/adapter/ezsp/driver/writer.ts +0 -64
  74. package/src/adapter/index.ts +0 -3
  75. package/src/adapter/serialPort.ts +0 -58
  76. package/src/adapter/socketPortUtils.ts +0 -16
  77. package/src/adapter/tstype.ts +0 -78
  78. package/src/adapter/z-stack/adapter/adapter-backup.ts +0 -519
  79. package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +0 -457
  80. package/src/adapter/z-stack/adapter/endpoints.ts +0 -57
  81. package/src/adapter/z-stack/adapter/manager.ts +0 -543
  82. package/src/adapter/z-stack/adapter/tstype.ts +0 -6
  83. package/src/adapter/z-stack/adapter/zStackAdapter.ts +0 -1190
  84. package/src/adapter/z-stack/constants/af.ts +0 -27
  85. package/src/adapter/z-stack/constants/common.ts +0 -285
  86. package/src/adapter/z-stack/constants/dbg.ts +0 -23
  87. package/src/adapter/z-stack/constants/index.ts +0 -11
  88. package/src/adapter/z-stack/constants/mac.ts +0 -128
  89. package/src/adapter/z-stack/constants/sapi.ts +0 -25
  90. package/src/adapter/z-stack/constants/sys.ts +0 -72
  91. package/src/adapter/z-stack/constants/util.ts +0 -82
  92. package/src/adapter/z-stack/constants/utils.ts +0 -14
  93. package/src/adapter/z-stack/constants/zdo.ts +0 -103
  94. package/src/adapter/z-stack/models/startup-options.ts +0 -13
  95. package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +0 -44
  96. package/src/adapter/z-stack/structs/entries/address-manager-table.ts +0 -19
  97. package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +0 -12
  98. package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +0 -21
  99. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +0 -19
  100. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +0 -21
  101. package/src/adapter/z-stack/structs/entries/channel-list.ts +0 -8
  102. package/src/adapter/z-stack/structs/entries/has-configured.ts +0 -16
  103. package/src/adapter/z-stack/structs/entries/index.ts +0 -16
  104. package/src/adapter/z-stack/structs/entries/nib.ts +0 -66
  105. package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +0 -15
  106. package/src/adapter/z-stack/structs/entries/nwk-key.ts +0 -13
  107. package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +0 -8
  108. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +0 -20
  109. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +0 -19
  110. package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +0 -33
  111. package/src/adapter/z-stack/structs/entries/security-manager-table.ts +0 -22
  112. package/src/adapter/z-stack/structs/index.ts +0 -4
  113. package/src/adapter/z-stack/structs/serializable-memory-object.ts +0 -14
  114. package/src/adapter/z-stack/structs/struct.ts +0 -367
  115. package/src/adapter/z-stack/structs/table.ts +0 -198
  116. package/src/adapter/z-stack/unpi/constants.ts +0 -33
  117. package/src/adapter/z-stack/unpi/frame.ts +0 -62
  118. package/src/adapter/z-stack/unpi/index.ts +0 -4
  119. package/src/adapter/z-stack/unpi/parser.ts +0 -56
  120. package/src/adapter/z-stack/unpi/writer.ts +0 -21
  121. package/src/adapter/z-stack/utils/channel-list.ts +0 -40
  122. package/src/adapter/z-stack/utils/index.ts +0 -2
  123. package/src/adapter/z-stack/utils/network-options.ts +0 -26
  124. package/src/adapter/z-stack/znp/buffaloZnp.ts +0 -175
  125. package/src/adapter/z-stack/znp/definition.ts +0 -2713
  126. package/src/adapter/z-stack/znp/index.ts +0 -2
  127. package/src/adapter/z-stack/znp/parameterType.ts +0 -22
  128. package/src/adapter/z-stack/znp/tstype.ts +0 -44
  129. package/src/adapter/z-stack/znp/utils.ts +0 -10
  130. package/src/adapter/z-stack/znp/znp.ts +0 -342
  131. package/src/adapter/z-stack/znp/zpiObject.ts +0 -148
  132. package/src/adapter/zboss/adapter/zbossAdapter.ts +0 -526
  133. package/src/adapter/zboss/commands.ts +0 -1184
  134. package/src/adapter/zboss/consts.ts +0 -9
  135. package/src/adapter/zboss/driver.ts +0 -422
  136. package/src/adapter/zboss/enums.ts +0 -360
  137. package/src/adapter/zboss/frame.ts +0 -227
  138. package/src/adapter/zboss/reader.ts +0 -65
  139. package/src/adapter/zboss/types.ts +0 -0
  140. package/src/adapter/zboss/uart.ts +0 -428
  141. package/src/adapter/zboss/utils.ts +0 -58
  142. package/src/adapter/zboss/writer.ts +0 -49
  143. package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +0 -27
  144. package/src/adapter/zigate/adapter/zigateAdapter.ts +0 -618
  145. package/src/adapter/zigate/driver/LICENSE +0 -17
  146. package/src/adapter/zigate/driver/buffaloZiGate.ts +0 -212
  147. package/src/adapter/zigate/driver/commandType.ts +0 -418
  148. package/src/adapter/zigate/driver/constants.ts +0 -150
  149. package/src/adapter/zigate/driver/frame.ts +0 -197
  150. package/src/adapter/zigate/driver/messageType.ts +0 -287
  151. package/src/adapter/zigate/driver/parameterType.ts +0 -32
  152. package/src/adapter/zigate/driver/ziGateObject.ts +0 -146
  153. package/src/adapter/zigate/driver/zigate.ts +0 -423
  154. package/src/adapter/zoh/adapter/utils.ts +0 -27
  155. package/src/adapter/zoh/adapter/zohAdapter.ts +0 -838
  156. package/src/buffalo/buffalo.ts +0 -342
  157. package/src/buffalo/index.ts +0 -1
  158. package/src/controller/controller.ts +0 -1022
  159. package/src/controller/database.ts +0 -124
  160. package/src/controller/events.ts +0 -52
  161. package/src/controller/greenPower.ts +0 -603
  162. package/src/controller/helpers/index.ts +0 -1
  163. package/src/controller/helpers/installCodes.ts +0 -107
  164. package/src/controller/helpers/request.ts +0 -96
  165. package/src/controller/helpers/requestQueue.ts +0 -125
  166. package/src/controller/helpers/zclFrameConverter.ts +0 -47
  167. package/src/controller/helpers/zclTransactionSequenceNumber.ts +0 -19
  168. package/src/controller/index.ts +0 -6
  169. package/src/controller/model/device.ts +0 -1248
  170. package/src/controller/model/endpoint.ts +0 -1105
  171. package/src/controller/model/entity.ts +0 -23
  172. package/src/controller/model/group.ts +0 -424
  173. package/src/controller/model/index.ts +0 -5
  174. package/src/controller/model/zigbeeEntity.ts +0 -30
  175. package/src/controller/touchlink.ts +0 -189
  176. package/src/controller/tstype.ts +0 -274
  177. package/src/index.ts +0 -12
  178. package/src/models/backup-storage-legacy.ts +0 -48
  179. package/src/models/backup-storage-unified.ts +0 -47
  180. package/src/models/backup.ts +0 -37
  181. package/src/models/index.ts +0 -5
  182. package/src/models/network-options.ts +0 -11
  183. package/src/utils/backup.ts +0 -152
  184. package/src/utils/index.ts +0 -5
  185. package/src/utils/logger.ts +0 -20
  186. package/src/utils/patchBigIntSerialization.ts +0 -8
  187. package/src/utils/queue.ts +0 -76
  188. package/src/utils/types.d.ts +0 -3
  189. package/src/utils/utils.ts +0 -19
  190. package/src/utils/wait.ts +0 -5
  191. package/src/utils/waitress.ts +0 -96
  192. package/src/zspec/consts.ts +0 -84
  193. package/src/zspec/enums.ts +0 -22
  194. package/src/zspec/index.ts +0 -3
  195. package/src/zspec/tstypes.ts +0 -18
  196. package/src/zspec/utils.ts +0 -247
  197. package/src/zspec/zcl/buffaloZcl.ts +0 -1220
  198. package/src/zspec/zcl/definition/cluster.ts +0 -5915
  199. package/src/zspec/zcl/definition/clusters-typegen.ts +0 -588
  200. package/src/zspec/zcl/definition/clusters-types.ts +0 -7331
  201. package/src/zspec/zcl/definition/consts.ts +0 -24
  202. package/src/zspec/zcl/definition/enums.ts +0 -203
  203. package/src/zspec/zcl/definition/foundation.ts +0 -329
  204. package/src/zspec/zcl/definition/manufacturerCode.ts +0 -729
  205. package/src/zspec/zcl/definition/status.ts +0 -69
  206. package/src/zspec/zcl/definition/tstype.ts +0 -377
  207. package/src/zspec/zcl/index.ts +0 -11
  208. package/src/zspec/zcl/utils.ts +0 -321
  209. package/src/zspec/zcl/zclFrame.ts +0 -356
  210. package/src/zspec/zcl/zclHeader.ts +0 -102
  211. package/src/zspec/zcl/zclStatusError.ts +0 -10
  212. package/src/zspec/zdo/buffaloZdo.ts +0 -2336
  213. package/src/zspec/zdo/definition/clusters.ts +0 -722
  214. package/src/zspec/zdo/definition/consts.ts +0 -16
  215. package/src/zspec/zdo/definition/enums.ts +0 -99
  216. package/src/zspec/zdo/definition/status.ts +0 -105
  217. package/src/zspec/zdo/definition/tstypes.ts +0 -1062
  218. package/src/zspec/zdo/index.ts +0 -7
  219. package/src/zspec/zdo/utils.ts +0 -76
  220. package/src/zspec/zdo/zdoStatusError.ts +0 -10
  221. package/test/adapter/adapter.test.ts +0 -1062
  222. package/test/adapter/ember/ash.test.ts +0 -337
  223. package/test/adapter/ember/consts.ts +0 -131
  224. package/test/adapter/ember/emberAdapter.test.ts +0 -3449
  225. package/test/adapter/ember/ezsp.test.ts +0 -385
  226. package/test/adapter/ember/ezspBuffalo.test.ts +0 -93
  227. package/test/adapter/ember/ezspError.test.ts +0 -12
  228. package/test/adapter/ember/math.test.ts +0 -206
  229. package/test/adapter/ezsp/frame.test.ts +0 -30
  230. package/test/adapter/ezsp/uart.test.ts +0 -181
  231. package/test/adapter/z-stack/adapter.test.ts +0 -3984
  232. package/test/adapter/z-stack/constants.test.ts +0 -33
  233. package/test/adapter/z-stack/structs.test.ts +0 -115
  234. package/test/adapter/z-stack/unpi.test.ts +0 -213
  235. package/test/adapter/z-stack/znp.test.ts +0 -1284
  236. package/test/adapter/zboss/fixZdoResponse.test.ts +0 -179
  237. package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +0 -81
  238. package/test/adapter/zigate/zdo.test.ts +0 -187
  239. package/test/adapter/zoh/utils.test.ts +0 -36
  240. package/test/adapter/zoh/zohAdapter.test.ts +0 -1307
  241. package/test/buffalo.test.ts +0 -431
  242. package/test/controller.bench.ts +0 -193
  243. package/test/controller.test.ts +0 -8702
  244. package/test/greenpower.test.ts +0 -1408
  245. package/test/mockAdapters.ts +0 -65
  246. package/test/mockDevices.ts +0 -598
  247. package/test/requests.bench.ts +0 -206
  248. package/test/testUtils.ts +0 -20
  249. package/test/tsconfig.json +0 -9
  250. package/test/utils/math.ts +0 -19
  251. package/test/utils.test.ts +0 -279
  252. package/test/vitest.config.mts +0 -27
  253. package/test/zcl.test.ts +0 -2831
  254. package/test/zspec/utils.test.ts +0 -68
  255. package/test/zspec/zcl/buffalo.test.ts +0 -1374
  256. package/test/zspec/zcl/frame.test.ts +0 -960
  257. package/test/zspec/zcl/utils.test.ts +0 -273
  258. package/test/zspec/zdo/buffalo.test.ts +0 -1850
  259. package/test/zspec/zdo/utils.test.ts +0 -241
  260. package/tsconfig.json +0 -24
package/test/zcl.test.ts DELETED
@@ -1,2831 +0,0 @@
1
- import {beforeEach, describe, expect, it, test, vi} from "vitest";
2
- import * as Zcl from "../src/zspec/zcl";
3
- import {BuffaloZcl} from "../src/zspec/zcl/buffaloZcl";
4
- import {BuffaloZclDataType, DataType, Direction, FrameType, StructuredIndicatorType} from "../src/zspec/zcl/definition/enums";
5
-
6
- describe("Zcl", () => {
7
- it("Get cluster by name", () => {
8
- const cluster = Zcl.Utils.getCluster("genIdentify", undefined, {});
9
- expect(cluster.ID).toBe(3);
10
- expect(cluster.name).toBe("genIdentify");
11
- expect(cluster.commands.identifyQuery.ID).toBe(1);
12
- expect(cluster.commands.identifyQuery.name).toBe("identifyQuery");
13
- expect(cluster.commandsResponse.identifyQueryRsp.ID).toBe(0);
14
- expect(cluster.commandsResponse.identifyQueryRsp.name).toBe("identifyQueryRsp");
15
- });
16
-
17
- it("Get cluster by ID", () => {
18
- const cluster1 = Zcl.Utils.getCluster(0, undefined, {});
19
- // @ts-expect-error testing
20
- delete cluster1.getAttribute;
21
- // @ts-expect-error testing
22
- delete cluster1.getCommand;
23
- // @ts-expect-error testing
24
- delete cluster1.getCommandResponse;
25
- const cluster2 = Zcl.Utils.getCluster("genBasic", undefined, {});
26
- // @ts-expect-error testing
27
- delete cluster2.getAttribute;
28
- // @ts-expect-error testing
29
- delete cluster2.getCommand;
30
- // @ts-expect-error testing
31
- delete cluster2.getCommandResponse;
32
- expect(cluster1).toStrictEqual(cluster2);
33
- });
34
-
35
- it("Get cluster attribute by ID", () => {
36
- const cluster = Zcl.Utils.getCluster(0, undefined, {});
37
- const attribute = cluster.getAttribute(1);
38
- expect(attribute).toStrictEqual({ID: 1, type: DataType.UINT8, name: "appVersion"});
39
- });
40
-
41
- it("Cluster has attribute", () => {
42
- const cluster = Zcl.Utils.getCluster(0, undefined, {});
43
- expect(cluster.getAttribute("zclVersion")).not.toBeUndefined();
44
- expect(cluster.getAttribute("NOTEXISTING")).toBeUndefined();
45
- expect(cluster.getAttribute(0)).not.toBeUndefined();
46
- expect(cluster.getAttribute(910293)).toBeUndefined();
47
- });
48
-
49
- it("Get specific command by name", () => {
50
- const cluster = Zcl.Utils.getCluster("genIdentify", undefined, {});
51
- const command = cluster.getCommand("ezmodeInvoke");
52
- expect(command.ID).toBe(2);
53
- expect(command.name).toBe("ezmodeInvoke");
54
- });
55
-
56
- it("Get global command by name", () => {
57
- const command = Zcl.Utils.getGlobalCommand("readRsp");
58
- expect(command.ID).toBe(1);
59
- expect(command.name).toBe("readRsp");
60
- });
61
-
62
- it("Get global command non existing", () => {
63
- expect(() => {
64
- Zcl.Utils.getGlobalCommand("nonexisting");
65
- }).toThrow("Global command with key 'nonexisting' does not exist");
66
- });
67
-
68
- it("Get cluster by name non-existing", () => {
69
- expect(() => {
70
- Zcl.Utils.getCluster("notExisting", undefined, {});
71
- }).toThrow("Cluster with name 'notExisting' does not exist");
72
- });
73
-
74
- it("Get cluster by id non-existing", () => {
75
- expect(JSON.parse(JSON.stringify(Zcl.Utils.getCluster(0x190231, undefined, {})))).toStrictEqual({
76
- ID: 1638961,
77
- attributes: {},
78
- name: "1638961",
79
- commands: {},
80
- commandsResponse: {},
81
- });
82
- });
83
-
84
- it("Get specific command by ID", () => {
85
- const cluster = Zcl.Utils.getCluster("genIdentify", undefined, {});
86
- const command = cluster.getCommand(2);
87
- expect(command).toStrictEqual(cluster.getCommand("ezmodeInvoke"));
88
- });
89
-
90
- it("Get specific command by name server to client", () => {
91
- const cluster = Zcl.Utils.getCluster("genIdentify", undefined, {});
92
- const command = cluster.getCommandResponse(0);
93
- expect(command.ID).toBe(0);
94
- expect(command.name).toBe("identifyQueryRsp");
95
- });
96
-
97
- it("Get specific command by name non existing", () => {
98
- expect(() => {
99
- const cluster = Zcl.Utils.getCluster("genIdentify", undefined, {});
100
- cluster.getCommandResponse("nonexisting");
101
- }).toThrow("Cluster 'genIdentify' has no command response 'nonexisting'");
102
- });
103
-
104
- it("Get discrete or analog of unkown type", () => {
105
- expect(() => {
106
- // @ts-expect-error invalid on purpose
107
- Zcl.Utils.getDataTypeClass(99999);
108
- }).toThrow("Don't know value type for 'undefined'");
109
- });
110
-
111
- it("ZclFrame from buffer parse payload with unknown frame type", () => {
112
- expect(() => {
113
- // @ts-ignore
114
- Zcl.Frame.parsePayload({frameControl: {frameType: 9}}, undefined);
115
- }).toThrow("Unsupported frameType '9'");
116
- });
117
-
118
- it("ZclFrame from buffer report", () => {
119
- const buffer = Buffer.from([0x18, 0x4a, 0x0a, 0x55, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00]);
120
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genAnalogInput.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
121
- const header = new Zcl.Header(
122
- {
123
- reservedBits: 0,
124
- direction: 1,
125
- disableDefaultResponse: true,
126
- frameType: 0,
127
- manufacturerSpecific: false,
128
- },
129
- undefined,
130
- 74,
131
- 10,
132
- );
133
-
134
- const payload = [
135
- {
136
- attrData: 0,
137
- attrId: 85,
138
- dataType: 57,
139
- },
140
- ];
141
-
142
- expect(frame.header).toStrictEqual(header);
143
- expect(frame.payload).toStrictEqual(payload);
144
- expect(frame.header.isGlobal).toBe(true);
145
- expect(frame.header.isSpecific).toBe(false);
146
- expect(frame.isCluster("genAnalogInput")).toBe(true);
147
- expect(frame.isCommand("report")).toBe(true);
148
- });
149
-
150
- it("ZclFrame from buffer tradfriArrowSingle", () => {
151
- const buffer = Buffer.from([0x05, 0x7c, 0x11, 0x1d, 0x07, 0x00, 0x01, 0x0d, 0x00]);
152
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genScenes.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
153
- const header = new Zcl.Header(
154
- {
155
- reservedBits: 0,
156
- direction: 0,
157
- disableDefaultResponse: false,
158
- frameType: 1,
159
- manufacturerSpecific: true,
160
- },
161
- 4476,
162
- 29,
163
- 7,
164
- );
165
-
166
- const payload = {value: 256, value2: 13};
167
-
168
- expect(frame.header).toStrictEqual(header);
169
- expect(frame.payload).toStrictEqual(payload);
170
- expect(frame.command.ID).toStrictEqual(7);
171
- expect(frame.command.name).toStrictEqual("tradfriArrowSingle");
172
- });
173
-
174
- it("ZclFrame from buffer genGroups getMembership", () => {
175
- const buffer = Buffer.from([0x11, 0x7c, 0x02, 2, 10, 0, 20, 0]);
176
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genGroups.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
177
- const header = new Zcl.Header(
178
- {
179
- reservedBits: 0,
180
- direction: 0,
181
- disableDefaultResponse: true,
182
- frameType: 1,
183
- manufacturerSpecific: false,
184
- },
185
- undefined,
186
- 124,
187
- 2,
188
- );
189
-
190
- const payload = {groupcount: 2, grouplist: [10, 20]};
191
-
192
- expect(frame.header).toStrictEqual(header);
193
- expect(frame.payload).toStrictEqual(payload);
194
- });
195
-
196
- it("ZclFrame from buffer genGroups getMembership", () => {
197
- const buffer = Buffer.from([0x19, 0x7c, 0x03, 0, 10, 0]);
198
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genGroups.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
199
- const header = new Zcl.Header(
200
- {
201
- reservedBits: 0,
202
- direction: 1,
203
- disableDefaultResponse: true,
204
- frameType: 1,
205
- manufacturerSpecific: false,
206
- },
207
- undefined,
208
- 124,
209
- 3,
210
- );
211
-
212
- const payload = {groupid: 10, status: 0};
213
-
214
- expect(frame.header).toStrictEqual(header);
215
- expect(frame.payload).toStrictEqual(payload);
216
- });
217
-
218
- it("ZclFrame from buffer occupancy report", () => {
219
- const buffer = Buffer.from([24, 169, 10, 0, 0, 24, 1]);
220
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.msOccupancySensing.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
221
- const header = new Zcl.Header(
222
- {
223
- reservedBits: 0,
224
- direction: 1,
225
- disableDefaultResponse: true,
226
- frameType: 0,
227
- manufacturerSpecific: false,
228
- },
229
- undefined,
230
- 169,
231
- 10,
232
- );
233
-
234
- const payload = [{attrId: 0, dataType: 24, attrData: 1}];
235
-
236
- expect(frame.header).toStrictEqual(header);
237
- expect(frame.payload).toStrictEqual(payload);
238
- });
239
-
240
- it("ZclFrame from buffer configReportRsp - short", () => {
241
- const buffer = Buffer.from([0x08, 0x01, 0x07, 0x00]);
242
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genPowerCfg.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
243
- const header = new Zcl.Header(
244
- {
245
- reservedBits: 0,
246
- direction: 1,
247
- disableDefaultResponse: false,
248
- frameType: 0,
249
- manufacturerSpecific: false,
250
- },
251
- undefined,
252
- 1,
253
- 7,
254
- );
255
-
256
- const payload = [{status: 0}];
257
-
258
- expect(frame.header).toStrictEqual(header);
259
- expect(frame.payload).toStrictEqual(payload);
260
- });
261
-
262
- it("ZclFrame from buffer configReportRsp - long", () => {
263
- const buffer = Buffer.from([0x08, 0x01, 0x07, 0x00, 0x01, 0x34, 0x12, 0x01, 0x01, 0x35, 0x12]);
264
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genPowerCfg.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
265
- const header = new Zcl.Header(
266
- {
267
- reservedBits: 0,
268
- direction: 1,
269
- disableDefaultResponse: false,
270
- frameType: 0,
271
- manufacturerSpecific: false,
272
- },
273
- undefined,
274
- 1,
275
- 7,
276
- );
277
-
278
- const payload = [
279
- {status: 0, direction: 1, attrId: 0x1234},
280
- {status: 1, direction: 1, attrId: 0x1235},
281
- ];
282
-
283
- expect(frame.header).toStrictEqual(header);
284
- expect(frame.payload).toStrictEqual(payload);
285
- });
286
-
287
- it("ZclFrame from buffer configReportRsp (hvacThermostat)", () => {
288
- const buffer = Buffer.from([0x18, 0x03, 0x07, 0x00, 0x00, 0x12, 0x00]);
289
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.hvacThermostat.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
290
- const header = new Zcl.Header(
291
- {
292
- reservedBits: 0,
293
- direction: 1,
294
- disableDefaultResponse: true,
295
- frameType: 0,
296
- manufacturerSpecific: false,
297
- },
298
- undefined,
299
- 3,
300
- 7,
301
- );
302
-
303
- const payload = [{status: 0, direction: 0, attrId: 18}];
304
-
305
- expect(frame.payload).toStrictEqual(payload);
306
- expect(frame.header).toStrictEqual(header);
307
- });
308
-
309
- it("ZclFrame from buffer getWeeklyScheduleRsp (hvacThermostat)", () => {
310
- const bufferHeat = Buffer.from([
311
- 9, 7, 0, 6, 64, 1, 104, 1, 252, 8, 58, 2, 152, 8, 208, 2, 102, 8, 72, 3, 102, 8, 222, 3, 252, 8, 100, 5, 52, 8,
312
- ]);
313
- const frameHeat = Zcl.Frame.fromBuffer(Zcl.Clusters.hvacThermostat.ID, Zcl.Header.fromBuffer(bufferHeat)!, bufferHeat, {});
314
- expect(frameHeat.payload).toStrictEqual({
315
- numoftrans: 6,
316
- dayofweek: 64,
317
- mode: 1,
318
- transitions: [
319
- {transitionTime: 360, heatSetpoint: 2300},
320
- {transitionTime: 570, heatSetpoint: 2200},
321
- {transitionTime: 720, heatSetpoint: 2150},
322
- {transitionTime: 840, heatSetpoint: 2150},
323
- {transitionTime: 990, heatSetpoint: 2300},
324
- {transitionTime: 1380, heatSetpoint: 2100},
325
- ],
326
- });
327
-
328
- const bufferCool = Buffer.from([
329
- 9, 7, 0, 6, 64, 2, 104, 1, 252, 8, 58, 2, 152, 8, 208, 2, 102, 8, 72, 3, 102, 8, 222, 3, 252, 8, 100, 5, 52, 8,
330
- ]);
331
- const frameCool = Zcl.Frame.fromBuffer(Zcl.Clusters.hvacThermostat.ID, Zcl.Header.fromBuffer(bufferCool)!, bufferCool, {});
332
- expect(frameCool.payload).toStrictEqual({
333
- numoftrans: 6,
334
- dayofweek: 64,
335
- mode: 2,
336
- transitions: [
337
- {transitionTime: 360, coolSetpoint: 2300},
338
- {transitionTime: 570, coolSetpoint: 2200},
339
- {transitionTime: 720, coolSetpoint: 2150},
340
- {transitionTime: 840, coolSetpoint: 2150},
341
- {transitionTime: 990, coolSetpoint: 2300},
342
- {transitionTime: 1380, coolSetpoint: 2100},
343
- ],
344
- });
345
-
346
- const bufferHeatAndCool = Buffer.from([9, 7, 0, 1, 64, 3, 104, 1, 252, 8, 58, 2]);
347
- const frameHeatAndCool = Zcl.Frame.fromBuffer(
348
- Zcl.Clusters.hvacThermostat.ID,
349
- Zcl.Header.fromBuffer(bufferHeatAndCool)!,
350
- bufferHeatAndCool,
351
- {},
352
- );
353
- expect(frameHeatAndCool.payload).toStrictEqual({
354
- numoftrans: 1,
355
- dayofweek: 64,
356
- mode: 3,
357
- transitions: [{transitionTime: 360, coolSetpoint: 570, heatSetpoint: 2300}],
358
- });
359
- });
360
-
361
- it("ZclFrame to buffer setWeeklyScheduleRsp (hvacThermostat)", () => {
362
- const payloadHeat = {
363
- numoftrans: 6,
364
- dayofweek: 64,
365
- mode: 1,
366
- transitions: [
367
- {transitionTime: 360, heatSetpoint: 23},
368
- {transitionTime: 570, heatSetpoint: 2200},
369
- {transitionTime: 720, heatSetpoint: 2150},
370
- {transitionTime: 840, heatSetpoint: 2150},
371
- {transitionTime: 990, heatSetpoint: 2300},
372
- {transitionTime: 1380, heatSetpoint: 2100},
373
- ],
374
- };
375
- const frameHeat = Zcl.Frame.create(
376
- FrameType.SPECIFIC,
377
- Direction.CLIENT_TO_SERVER,
378
- false,
379
- undefined,
380
- 8,
381
- "setWeeklySchedule",
382
- 513,
383
- payloadHeat,
384
- {},
385
- );
386
- expect(frameHeat.toBuffer()).toStrictEqual(
387
- Buffer.from([1, 8, 1, 6, 64, 1, 104, 1, 23, 0, 58, 2, 152, 8, 208, 2, 102, 8, 72, 3, 102, 8, 222, 3, 252, 8, 100, 5, 52, 8]),
388
- );
389
-
390
- const payloadCool = {
391
- numoftrans: 6,
392
- dayofweek: 64,
393
- mode: 2,
394
- transitions: [
395
- {transitionTime: 360, coolSetpoint: 2300},
396
- {transitionTime: 570, coolSetpoint: 2200},
397
- {transitionTime: 720, coolSetpoint: 2150},
398
- {transitionTime: 840, coolSetpoint: 2150},
399
- {transitionTime: 990, coolSetpoint: 2300},
400
- {transitionTime: 1380, coolSetpoint: 2100},
401
- ],
402
- };
403
- const frameCool = Zcl.Frame.create(
404
- FrameType.SPECIFIC,
405
- Direction.CLIENT_TO_SERVER,
406
- false,
407
- undefined,
408
- 8,
409
- "setWeeklySchedule",
410
- 513,
411
- payloadCool,
412
- {},
413
- );
414
- expect(frameCool.toBuffer()).toStrictEqual(
415
- Buffer.from([1, 8, 1, 6, 64, 2, 104, 1, 252, 8, 58, 2, 152, 8, 208, 2, 102, 8, 72, 3, 102, 8, 222, 3, 252, 8, 100, 5, 52, 8]),
416
- );
417
-
418
- const payloadHeatAndCool = {
419
- numoftrans: 6,
420
- dayofweek: 64,
421
- mode: 2,
422
- transitions: [{transitionTime: 360, coolSetpoint: 570, heatSetpoint: 2300}],
423
- };
424
- const frameHeatAndCool = Zcl.Frame.create(
425
- FrameType.SPECIFIC,
426
- Direction.CLIENT_TO_SERVER,
427
- false,
428
- undefined,
429
- 8,
430
- "setWeeklySchedule",
431
- 513,
432
- payloadHeatAndCool,
433
- {},
434
- );
435
- expect(frameHeatAndCool.toBuffer()).toStrictEqual(Buffer.from([1, 8, 1, 6, 64, 2, 104, 1, 252, 8, 58, 2]));
436
- });
437
-
438
- it("ZclFrame from buffer configReportRsp failed", () => {
439
- const buffer = Buffer.from([0x08, 0x01, 0x07, 0x02, 0x01, 0x01, 0x01]);
440
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genPowerCfg.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
441
- const header = new Zcl.Header(
442
- {
443
- reservedBits: 0,
444
- direction: 1,
445
- disableDefaultResponse: false,
446
- frameType: 0,
447
- manufacturerSpecific: false,
448
- },
449
- undefined,
450
- 1,
451
- 7,
452
- );
453
-
454
- const payload = [{status: 2, direction: 1, attrId: 257}];
455
-
456
- expect(frame.header).toStrictEqual(header);
457
- expect(frame.payload).toStrictEqual(payload);
458
- });
459
-
460
- it("ZclFrame from buffer defaultRsp", () => {
461
- const buffer = Buffer.from([0x18, 0x04, 0x0b, 0x0c, 0x82]);
462
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
463
- const header = new Zcl.Header(
464
- {
465
- reservedBits: 0,
466
- direction: 1,
467
- disableDefaultResponse: true,
468
- frameType: 0,
469
- manufacturerSpecific: false,
470
- },
471
- undefined,
472
- 4,
473
- 11,
474
- );
475
-
476
- const payload = {cmdId: 12, statusCode: 130};
477
-
478
- expect(frame.header).toStrictEqual(header);
479
- expect(frame.payload).toStrictEqual(payload);
480
- });
481
-
482
- test.each([
483
- [
484
- [
485
- 28, 95, 17, 3, 10, 1, 255, 66, 68, 3, 40, 29, 5, 33, 190, 45, 8, 33, 47, 18, 9, 33, 2, 21, 100, 16, 1, 101, 16, 0, 110, 32, 255, 111,
486
- 32, 255, 148, 32, 4, 149, 57, 184, 30, 21, 62, 150, 57, 211, 249, 17, 69, 151, 57, 0, 48, 104, 59, 152, 57, 0, 0, 0, 0, 155, 33, 1, 0,
487
- 156, 32, 1, 10, 33, 56, 38, 12, 40, 0, 0,
488
- ],
489
- [
490
- {
491
- attrId: 65281,
492
- dataType: 66,
493
- attrData: {
494
- "3": 29,
495
- "5": 11710,
496
- "8": 4655,
497
- "9": 5378,
498
- "10": 9784,
499
- "12": 0,
500
- "100": 1,
501
- "101": 0,
502
- "110": Number.NaN,
503
- "111": Number.NaN,
504
- "148": 4,
505
- "149": 0.14562499523162842,
506
- "150": 2335.614013671875,
507
- "151": 0.0035429000854492188,
508
- "152": 0,
509
- "155": 1,
510
- "156": 1,
511
- },
512
- },
513
- ],
514
- ],
515
- [
516
- [
517
- 28, 95, 17, 3, 10, 5, 0, 66, 21, 108, 117, 109, 105, 46, 115, 101, 110, 115, 111, 114, 95, 119, 108, 101, 97, 107, 46, 97, 113, 49, 1,
518
- 255, 66, 34, 1, 33, 213, 12, 3, 40, 33, 4, 33, 168, 19, 5, 33, 43, 0, 6, 36, 0, 0, 5, 0, 0, 8, 33, 4, 2, 10, 33, 0, 0, 100, 16, 0,
519
- ],
520
- [
521
- {attrId: 5, dataType: 66, attrData: "lumi.sensor_wleak.aq1"},
522
- {attrId: 65281, dataType: 66, attrData: {"1": 3285, "3": 33, "4": 5032, "5": 43, "6": 327680, "8": 516, "10": 0, "100": 0}},
523
- ],
524
- ],
525
- ])("ZclFrame from buffer xiaomiStruct", (data, payload) => {
526
- const buffer = Buffer.from(data);
527
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
528
- const header = new Zcl.Header(
529
- {
530
- reservedBits: 0,
531
- direction: 1,
532
- disableDefaultResponse: true,
533
- frameType: 0,
534
- manufacturerSpecific: true,
535
- },
536
- 4447,
537
- 3,
538
- 10,
539
- );
540
-
541
- expect(frame.header).toStrictEqual(header);
542
- expect(frame.payload).toStrictEqual(payload);
543
- });
544
-
545
- it("ZclFrame from buffer struct", () => {
546
- const buffer = Buffer.from([28, 52, 18, 194, 10, 2, 255, 76, 6, 0, 16, 1, 33, 206, 11, 33, 168, 67, 36, 1, 0, 0, 0, 0, 33, 48, 2, 32, 86]);
547
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
548
- const header = new Zcl.Header(
549
- {
550
- reservedBits: 0,
551
- direction: 1,
552
- disableDefaultResponse: true,
553
- frameType: 0,
554
- manufacturerSpecific: true,
555
- },
556
- 4660,
557
- 194,
558
- 10,
559
- );
560
-
561
- const payload = [
562
- {
563
- attrId: 65282,
564
- dataType: 76,
565
- numElms: 6,
566
- structElms: [
567
- {elmType: 16, elmVal: 1},
568
- {elmType: 33, elmVal: 3022},
569
- {elmType: 33, elmVal: 17320},
570
- {elmType: 36, elmVal: 1},
571
- {elmType: 33, elmVal: 560},
572
- {elmType: 32, elmVal: 86},
573
- ],
574
- attrData: [
575
- {elmType: 16, elmVal: 1},
576
- {elmType: 33, elmVal: 3022},
577
- {elmType: 33, elmVal: 17320},
578
- {elmType: 36, elmVal: 1},
579
- {elmType: 33, elmVal: 560},
580
- {elmType: 32, elmVal: 86},
581
- ],
582
- },
583
- ];
584
-
585
- expect(frame.header).toStrictEqual(header);
586
- expect(frame.payload).toStrictEqual(payload);
587
- });
588
-
589
- it("ZclFrame from buffer discoverRsp", () => {
590
- const buffer = Buffer.from([24, 23, 13, 0, 32, 0, 32, 33, 0, 32, 49, 0, 48, 51, 0, 32, 53, 0, 24]);
591
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genPowerCfg.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
592
- const header = new Zcl.Header(
593
- {
594
- reservedBits: 0,
595
- direction: 1,
596
- disableDefaultResponse: true,
597
- frameType: 0,
598
- manufacturerSpecific: false,
599
- },
600
- undefined,
601
- 23,
602
- 13,
603
- );
604
-
605
- const payload = {
606
- discComplete: 0,
607
- attrInfos: [
608
- {attrId: 32, dataType: 32},
609
- {attrId: 33, dataType: 32},
610
- {attrId: 49, dataType: 48},
611
- {attrId: 51, dataType: 32},
612
- {attrId: 53, dataType: 24},
613
- ],
614
- };
615
-
616
- expect(frame.header).toStrictEqual(header);
617
- expect(frame.payload).toStrictEqual(payload);
618
- expect(frame.cluster.name).toEqual("genPowerCfg");
619
- expect(frame.command.name).toEqual("discoverRsp");
620
- });
621
-
622
- it("ZclFrame from buffer error on malformed", () => {
623
- const buffer = Buffer.from([0x08, 0x01]);
624
- expect(() => {
625
- Zcl.Frame.fromBuffer(Zcl.Clusters.genPowerCfg.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
626
- }).toThrow("Invalid ZclHeader");
627
- });
628
-
629
- it("ZclFrame from buffer readRsp failed", () => {
630
- const buffer = Buffer.from([8, 1, 1, 1, 0, 2]);
631
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
632
- const header = new Zcl.Header(
633
- {
634
- reservedBits: 0,
635
- direction: 1,
636
- disableDefaultResponse: false,
637
- frameType: 0,
638
- manufacturerSpecific: false,
639
- },
640
- undefined,
641
- 1,
642
- 1,
643
- );
644
-
645
- const payload = [{status: 2, attrId: 1}];
646
-
647
- expect(frame.header).toStrictEqual(header);
648
- expect(frame.payload).toStrictEqual(payload);
649
- });
650
-
651
- it("ZclFrame from buffer readRsp success", () => {
652
- const buffer = Buffer.from([8, 1, 1, 1, 0, 0, 32, 3]);
653
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
654
- const header = new Zcl.Header(
655
- {
656
- reservedBits: 0,
657
- direction: 1,
658
- disableDefaultResponse: false,
659
- frameType: 0,
660
- manufacturerSpecific: false,
661
- },
662
- undefined,
663
- 1,
664
- 1,
665
- );
666
-
667
- const payload = [{status: Zcl.Status.SUCCESS, attrId: 1, dataType: Zcl.DataType.UINT8, attrData: 3}];
668
-
669
- expect(frame.header).toStrictEqual(header);
670
- expect(frame.payload).toStrictEqual(payload);
671
- });
672
-
673
- it("ZclFrame from buffer GPD commission", () => {
674
- const buffer = Buffer.from([
675
- 0x11, 0x00, 0x04, 0x00, 0x00, 0xfe, 0xf4, 0x46, 0x00, 0xf9, 0x00, 0x00, 0x00, 0xe0, 0x1b, 0x02, 0x81, 0xf2, 0xf1, 0xec, 0x92, 0xab, 0xff,
676
- 0x8f, 0x13, 0x63, 0xe1, 0x46, 0xbe, 0xb5, 0x18, 0xc9, 0x0c, 0xab, 0xa4, 0x46, 0xd4, 0xd5, 0xf9, 0x01, 0x00, 0x00,
677
- ]);
678
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.greenPower.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
679
- const header = new Zcl.Header(
680
- {
681
- reservedBits: 0,
682
- direction: 0,
683
- disableDefaultResponse: true,
684
- frameType: 1,
685
- manufacturerSpecific: false,
686
- },
687
- undefined,
688
- 0,
689
- 4,
690
- );
691
-
692
- const payload = {
693
- options: 0,
694
- srcID: 4650238,
695
- frameCounter: 249,
696
- commandID: 224,
697
- payloadSize: 27,
698
- commandFrame: {
699
- deviceID: 2,
700
- options: 129,
701
- extendedOptions: 242,
702
- gpdClientClusters: Buffer.alloc(0),
703
- gpdServerClusters: Buffer.alloc(0),
704
- manufacturerID: 0,
705
- modelID: 0,
706
- numClientClusters: 0,
707
- numServerClusters: 0,
708
- securityKey: Buffer.from([0xf1, 0xec, 0x92, 0xab, 0xff, 0x8f, 0x13, 0x63, 0xe1, 0x46, 0xbe, 0xb5, 0x18, 0xc9, 0x0c, 0xab]),
709
- keyMic: 3587458724,
710
- outgoingCounter: 505,
711
- applicationInfo: 0,
712
- numGpdCommands: 0,
713
- gpdCommandIdList: Buffer.alloc(0),
714
- genericSwitchConfig: 0,
715
- currentContactStatus: 0,
716
- },
717
- };
718
-
719
- expect(frame.header).toStrictEqual(header);
720
- expect(frame.payload).toStrictEqual(payload);
721
- });
722
-
723
- it("ZclFrame from buffer GPD scene 0", () => {
724
- const buffer = Buffer.from([0x11, 0x00, 0x00, 0xa0, 0x14, 0xfe, 0xf4, 0x46, 0x00, 0xe5, 0x04, 0x00, 0x00, 0x10, 0xff]);
725
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.greenPower.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
726
- const header = new Zcl.Header(
727
- {
728
- reservedBits: 0,
729
- direction: 0,
730
- disableDefaultResponse: true,
731
- frameType: 1,
732
- manufacturerSpecific: false,
733
- },
734
- undefined,
735
- 0,
736
- 0,
737
- );
738
-
739
- const payload = {
740
- srcID: 4650238,
741
- commandFrame: {},
742
- commandID: 16,
743
- frameCounter: 1253,
744
- options: 5280,
745
- payloadSize: Number.NaN,
746
- };
747
-
748
- expect(frame.header).toStrictEqual(header);
749
- expect(frame.payload).toStrictEqual(payload);
750
- });
751
-
752
- it("ZclFrame from buffer GPD with extra data", () => {
753
- const buffer = Buffer.from([0x11, 0x00, 0x00, 0xa0, 0x14, 0xfe, 0xf4, 0x46, 0x00, 0xe5, 0x04, 0x00, 0x00, 0x10, 0x01, 0x01]);
754
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.greenPower.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
755
- const header = new Zcl.Header(
756
- {
757
- reservedBits: 0,
758
- direction: 0,
759
- disableDefaultResponse: true,
760
- frameType: 1,
761
- manufacturerSpecific: false,
762
- },
763
- undefined,
764
- 0,
765
- 0,
766
- );
767
-
768
- const payload = {
769
- srcID: 4650238,
770
- commandFrame: {raw: Buffer.from([1])},
771
- commandID: 16,
772
- frameCounter: 1253,
773
- options: 5280,
774
- payloadSize: 1,
775
- };
776
-
777
- expect(frame.header).toStrictEqual(header);
778
- expect(frame.payload).toStrictEqual(payload);
779
- });
780
-
781
- it("ZclFrame from buffer GPD pairing", () => {
782
- const buffer = Buffer.from([
783
- 0x19, 0x17, 0x01, 0x68, 0xe5, 0x00, 0xf8, 0x71, 0x71, 0x01, 0x47, 0x65, 0xa1, 0x1c, 0x00, 0x4b, 0x12, 0x00, 0x00, 0x00, 0x02, 0x1c, 0x12,
784
- 0x00, 0x00, 0x09, 0x3c, 0xed, 0x1d, 0xbf, 0x25, 0x63, 0xf9, 0x29, 0x5c, 0x0d, 0x3d, 0x9f, 0xc5, 0x76, 0xe1, 0, 0, 0, 0, 0, 0,
785
- ]);
786
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.greenPower.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
787
- const header = new Zcl.Header(
788
- {
789
- reservedBits: 0,
790
- direction: 1,
791
- disableDefaultResponse: true,
792
- frameType: 1,
793
- manufacturerSpecific: false,
794
- },
795
- undefined,
796
- 23,
797
- 1,
798
- );
799
-
800
- const payload = {
801
- options: 0x00e568,
802
- srcID: 0x017171f8,
803
- sinkIEEEAddr: "0x00124b001ca16547",
804
- sinkNwkAddr: 0,
805
- deviceID: 2,
806
- frameCounter: 4636,
807
- gpdKey: Buffer.from([0x09, 0x3c, 0xed, 0x1d, 0xbf, 0x25, 0x63, 0xf9, 0x29, 0x5c, 0x0d, 0x3d, 0x9f, 0xc5, 0x76, 0xe1]),
808
- };
809
-
810
- expect(frame.header).toStrictEqual(header);
811
- expect(frame.payload).toStrictEqual(payload);
812
- });
813
-
814
- it("ZclFrame from buffer readRsp alias type", () => {
815
- const buffer = Buffer.from([8, 1, 1, 1, 0, 0, 8, 3]);
816
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
817
- const header = new Zcl.Header(
818
- {
819
- reservedBits: 0,
820
- direction: 1,
821
- disableDefaultResponse: false,
822
- frameType: 0,
823
- manufacturerSpecific: false,
824
- },
825
- undefined,
826
- 1,
827
- 1,
828
- );
829
-
830
- const payload = [{status: Zcl.Status.SUCCESS, attrId: 1, dataType: Zcl.DataType.DATA8, attrData: 3}];
831
-
832
- expect(frame.header).toStrictEqual(header);
833
- expect(frame.payload).toStrictEqual(payload);
834
- });
835
-
836
- it("ZclFrame from buffer configReportRsp server to client", () => {
837
- const buffer = Buffer.from([8, 1, 6, 1, 1, 0, 10, 10]);
838
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
839
- const header = new Zcl.Header(
840
- {
841
- reservedBits: 0,
842
- direction: 1,
843
- disableDefaultResponse: false,
844
- frameType: 0,
845
- manufacturerSpecific: false,
846
- },
847
- undefined,
848
- 1,
849
- 6,
850
- );
851
-
852
- const payload = [{attrId: 1, direction: 1, timeout: 2570}];
853
-
854
- expect(frame.header).toStrictEqual(header);
855
- expect(frame.payload).toStrictEqual(payload);
856
- });
857
-
858
- it("ZclFrame from buffer configReportRsp client to server analog", () => {
859
- const buffer = Buffer.from([8, 1, 6, 0, 0, 1, 32, 1, 0, 10, 0, 20]);
860
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
861
- const header = new Zcl.Header(
862
- {
863
- reservedBits: 0,
864
- direction: 1,
865
- disableDefaultResponse: false,
866
- frameType: 0,
867
- manufacturerSpecific: false,
868
- },
869
- undefined,
870
- 1,
871
- 6,
872
- );
873
-
874
- const payload = [{attrId: 256, dataType: 32, direction: 0, maxRepIntval: 10, minRepIntval: 1, repChange: 20}];
875
-
876
- expect(frame.header).toStrictEqual(header);
877
- expect(frame.payload).toStrictEqual(payload);
878
- });
879
-
880
- it("ZclFrame from buffer configReportRsp client to server analog", () => {
881
- const buffer = Buffer.from([8, 1, 6, 0, 0, 1, 8, 1, 0, 10, 0]);
882
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
883
- const header = new Zcl.Header(
884
- {
885
- reservedBits: 0,
886
- direction: 1,
887
- disableDefaultResponse: false,
888
- frameType: 0,
889
- manufacturerSpecific: false,
890
- },
891
- undefined,
892
- 1,
893
- 6,
894
- );
895
-
896
- const payload = [{attrId: 256, dataType: 8, direction: 0, maxRepIntval: 10, minRepIntval: 1}];
897
-
898
- expect(frame.header).toStrictEqual(header);
899
- expect(frame.payload).toStrictEqual(payload);
900
- });
901
-
902
- it("ZclFrame from buffer readRsp", () => {
903
- const buffer = Buffer.from([
904
- 24, 7, 1, 5, 0, 0, 66, 30, 84, 82, 65, 68, 70, 82, 73, 32, 98, 117, 108, 98, 32, 69, 50, 55, 32, 87, 83, 32, 111, 112, 97, 108, 32, 57,
905
- 56, 48, 108, 109, 6, 0, 0, 66, 8, 50, 48, 49, 55, 48, 51, 51, 49, 7, 0, 0, 48, 1, 10, 0, 0, 65, 15, 76, 69, 68, 49, 53, 52, 53, 71, 49,
906
- 50, 69, 50, 55, 69, 85,
907
- ]);
908
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
909
- const header = new Zcl.Header(
910
- {
911
- reservedBits: 0,
912
- direction: 1,
913
- disableDefaultResponse: true,
914
- frameType: 0,
915
- manufacturerSpecific: false,
916
- },
917
- undefined,
918
- 7,
919
- 1,
920
- );
921
-
922
- const payload = [
923
- {attrId: 5, status: 0, dataType: 66, attrData: "TRADFRI bulb E27 WS opal 980lm"},
924
- {attrId: 6, status: 0, dataType: 66, attrData: "20170331"},
925
- {attrId: 7, status: 0, dataType: 48, attrData: 1},
926
- {attrId: 10, status: 0, dataType: 65, attrData: Buffer.from([76, 69, 68, 49, 53, 52, 53, 71, 49, 50, 69, 50, 55, 69, 85])},
927
- ];
928
-
929
- expect(frame.header).toStrictEqual(header);
930
- expect(frame.payload).toStrictEqual(payload);
931
- });
932
-
933
- it("ZclFrame with Assa (manufacturer specific) cluster create", () => {
934
- const payload = [{attrId: 0x0012, status: 0, attrData: 1, dataType: 32}];
935
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, false, 0x101d, 8, "readRsp", 0xfc00, payload, {});
936
-
937
- expect(frame.cluster.name).toBe("manuSpecificAssaDoorLock");
938
- });
939
-
940
- it("ZclFrame with Assa (manufacturer specific) cluster create with non Assamanufcode", () => {
941
- const payload = [{attrId: 0x0012, status: 0, attrData: 1, dataType: 32}];
942
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, false, 0x10f3, 8, "readRsp", 0xfc00, payload, {});
943
-
944
- expect(frame.cluster.name).toBe("manuSpecificAssaDoorLock");
945
- });
946
-
947
- it("ZclFrame with Assa (manufacturer specific) cluster fromBuffer", () => {
948
- const buffer = Buffer.from([0x04, 0xf2, 0x10, 0x08, 0x01, 0x00, 0x00, 0x00, 0x20, 0x01]);
949
- const frame = Zcl.Frame.fromBuffer(0xfc00, Zcl.Header.fromBuffer(buffer)!, buffer, {});
950
- expect(frame.cluster.name).toBe("manuSpecificAssaDoorLock");
951
- });
952
-
953
- it("ZclFrame to buffer with reservered bits", () => {
954
- const expected = Buffer.from([224, 8, 12, 0, 0, 240]);
955
- const payload = {startAttrId: 0, maxAttrIds: 240};
956
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, false, undefined, 8, "discover", 0, payload, {}, 7);
957
-
958
- expect(frame.toBuffer()).toStrictEqual(expected);
959
- });
960
-
961
- it("ZclFrame from buffer with reservered bits", () => {
962
- const buffer = Buffer.from([224, 8, 12, 0, 0, 240]);
963
- const frame = Zcl.Frame.fromBuffer(0, Zcl.Header.fromBuffer(buffer)!, buffer, {});
964
- const header = new Zcl.Header(
965
- {
966
- reservedBits: 7,
967
- direction: 0,
968
- disableDefaultResponse: false,
969
- frameType: 0,
970
- manufacturerSpecific: false,
971
- },
972
- undefined,
973
- 8,
974
- 12,
975
- );
976
-
977
- const payload = {startAttrId: 0, maxAttrIds: 240};
978
-
979
- expect(frame.header).toStrictEqual(header);
980
- expect(frame.payload).toStrictEqual(payload);
981
- });
982
-
983
- it("ZclFrame to buffer discover", () => {
984
- const expected = Buffer.from([0, 8, 12, 0, 0, 240]);
985
- const payload = {startAttrId: 0, maxAttrIds: 240};
986
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, false, undefined, 8, "discover", 0, payload, {});
987
-
988
- expect(frame.toBuffer()).toStrictEqual(expected);
989
- });
990
-
991
- it("ZclFrame to buffer queryNextImageResponse with non zero status", () => {
992
- const expected = Buffer.from([9, 8, 2, 1]);
993
- const payload = {status: 1};
994
- const frame = Zcl.Frame.create(
995
- FrameType.SPECIFIC,
996
- Direction.SERVER_TO_CLIENT,
997
- false,
998
- undefined,
999
- 8,
1000
- "queryNextImageResponse",
1001
- 25,
1002
- payload,
1003
- {},
1004
- );
1005
-
1006
- expect(frame.toBuffer()).toStrictEqual(expected);
1007
- });
1008
-
1009
- it("ZclFrame to buffer queryNextImageResponse with zero status", () => {
1010
- const expected = Buffer.from([9, 8, 2, 0, 1, 0, 3, 0, 5, 0, 0, 0, 6, 0, 0, 0]);
1011
- const payload = {status: 0, manufacturerCode: 1, imageType: 3, fileVersion: 5, imageSize: 6};
1012
- const frame = Zcl.Frame.create(
1013
- FrameType.SPECIFIC,
1014
- Direction.SERVER_TO_CLIENT,
1015
- false,
1016
- undefined,
1017
- 8,
1018
- "queryNextImageResponse",
1019
- 25,
1020
- payload,
1021
- {},
1022
- );
1023
-
1024
- expect(frame.toBuffer()).toStrictEqual(expected);
1025
- });
1026
-
1027
- it("ZclFrame to buffer queryNextImageResponse with zero status and missing parameters", () => {
1028
- const payload = {status: 0};
1029
- const frame = Zcl.Frame.create(
1030
- FrameType.SPECIFIC,
1031
- Direction.SERVER_TO_CLIENT,
1032
- false,
1033
- undefined,
1034
- 8,
1035
- "queryNextImageResponse",
1036
- 25,
1037
- payload,
1038
- {},
1039
- );
1040
-
1041
- let error;
1042
- try {
1043
- frame.toBuffer();
1044
- } catch (e) {
1045
- error = e;
1046
- }
1047
- expect(error).toStrictEqual(new Error(`Parameter 'manufacturerCode' is missing`));
1048
- });
1049
-
1050
- it("ZclFrame to buffer readRsp UTC", () => {
1051
- const expected = Buffer.from([24, 74, 1, 0, 0, 0, 226, 234, 83, 218, 36]);
1052
- const payload = [{attrId: 0, status: 0, attrData: 618288106, dataType: 226}];
1053
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, undefined, 74, "readRsp", 0, payload, {});
1054
-
1055
- expect(frame.toBuffer()).toStrictEqual(expected);
1056
- });
1057
-
1058
- it("ZclFrame to buffer write Livolo malformed", () => {
1059
- // Created as example for https://github.com/Koenkk/zigbee-herdsman/issues/127
1060
- const expectedOn = Buffer.from([0x1c, 0xd2, 0x1a, 0xe9, 0x02, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
1061
- const payloadOn = [{attrId: 1, attrData: Buffer.from([1, 0, 0, 0, 0, 0, 0, 0]), dataType: 1}];
1062
- const frameOn = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, 0x1ad2, 233, "write", 0, payloadOn, {});
1063
- expect(frameOn.toBuffer()).toStrictEqual(expectedOn);
1064
-
1065
- const expectedOff = Buffer.from([0x1c, 0xd2, 0x1a, 0xe9, 0x02, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
1066
- const payloadOff = [{attrId: 1, attrData: Buffer.from([0, 0, 0, 0, 0, 0, 0, 0]), dataType: 1}];
1067
- const frameOff = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, 0x1ad2, 233, "write", 0, payloadOff, {});
1068
- expect(frameOff.toBuffer()).toStrictEqual(expectedOff);
1069
- });
1070
-
1071
- it("ZclFrame write request with string as bytes array", () => {
1072
- const payload = [{attrId: 0x0401, attrData: [0x07, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x14], dataType: 0x42}];
1073
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, 0x115f, 15, "write", 0, payload, {});
1074
-
1075
- const expected = [0x14, 0x5f, 0x11, 0x0f, 0x02, 0x01, 0x04, 0x42, 0x07, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x14];
1076
- expect(Buffer.from(expected)).toStrictEqual(frame.toBuffer());
1077
- });
1078
-
1079
- it("ZclFrame write rsp", () => {
1080
- const payload = [{status: 0x11, attrId: 0x22}];
1081
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, 0x115f, 15, "writeRsp", 0, payload, {});
1082
- const buffer = frame.toBuffer();
1083
-
1084
- const expected = [0x14, 0x5f, 0x11, 0x0f, 0x04, 0x11, 0x22, 0x00];
1085
- expect(Buffer.from(expected)).toStrictEqual(buffer);
1086
- });
1087
-
1088
- //{ frameType: 0, manufSpec: 0, direction: 0, disDefaultRsp: 0 } 0 8 'discover' { startAttrId: 0, maxAttrIds: 240 }
1089
- it("ZclFrame to buffer readRsp success", () => {
1090
- const expected = Buffer.from([8, 1, 1, 1, 0, 0, 32, 3]);
1091
- const payload = [{status: Zcl.Status.SUCCESS, attrId: 1, dataType: Zcl.DataType.UINT8, attrData: 3}];
1092
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, false, undefined, 1, 1, 0, payload, {});
1093
-
1094
- expect(frame.toBuffer()).toStrictEqual(expected);
1095
- });
1096
-
1097
- it("ZclFrame to buffer defaultRsp success", () => {
1098
- const expected = Buffer.from([0x18, 0x04, 0x0b, 0x0c, 0x82]);
1099
- const payload = {cmdId: 12, statusCode: 130};
1100
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, undefined, 4, 11, 0, payload, {});
1101
-
1102
- expect(frame.toBuffer()).toStrictEqual(expected);
1103
- });
1104
-
1105
- it("ZclFrame to buffer readStructured single element", () => {
1106
- const expected = Buffer.from([0x18, 0x02, 0x0e, 0x01, 0x00, 0x01, 0x02, 0x00]);
1107
- const payload = [{attrId: 0x0001, selector: {indexes: [2]}}];
1108
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, undefined, 2, 0x0e, Zcl.Clusters.genBasic.ID, payload, {});
1109
-
1110
- expect(frame.toBuffer()).toStrictEqual(expected);
1111
- });
1112
-
1113
- it("ZclFrame to buffer readStructured multiple elements", () => {
1114
- const expected = Buffer.from([
1115
- 0x18, 0x02, 0x0e, 0x02, 0x00, 0x02, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x03, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00,
1116
- ]);
1117
- const payload = [
1118
- {attrId: 0x0002, selector: {indexes: [3, 4]}},
1119
- {attrId: 0x0005, selector: {indexes: [6, 7, 8]}},
1120
- ];
1121
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, undefined, 2, 0x0e, Zcl.Clusters.genBasic.ID, payload, {});
1122
-
1123
- expect(frame.toBuffer()).toStrictEqual(expected);
1124
- });
1125
-
1126
- it("ZclFrame to buffer readStructured whole attribute", () => {
1127
- const expected = Buffer.from([0x18, 0x02, 0x0e, 0x09, 0x00, 0x00]);
1128
- const payload = [{attrId: 0x0009, selector: {}}];
1129
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, undefined, 2, 0x0e, Zcl.Clusters.genBasic.ID, payload, {});
1130
-
1131
- expect(frame.toBuffer()).toStrictEqual(expected);
1132
- });
1133
-
1134
- it("ZclFrame from buffer readStructured single elements", () => {
1135
- const buffer = Buffer.from([0x18, 0x02, 0x0e, 0x01, 0x00, 0x01, 0x02, 0x00]);
1136
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1137
- const header = new Zcl.Header(
1138
- {
1139
- reservedBits: 0,
1140
- direction: Direction.SERVER_TO_CLIENT,
1141
- disableDefaultResponse: true,
1142
- frameType: FrameType.GLOBAL,
1143
- manufacturerSpecific: false,
1144
- },
1145
- undefined,
1146
- 2,
1147
- 0x0e,
1148
- );
1149
- const payload = [{attrId: 0x0001, selector: {indexes: [2]}}];
1150
-
1151
- expect(frame.header).toStrictEqual(header);
1152
- expect(frame.payload).toStrictEqual(payload);
1153
- });
1154
-
1155
- it("ZclFrame from buffer readStructured multiple elements", () => {
1156
- const buffer = Buffer.from([
1157
- 0x18, 0x02, 0x0e, 0x02, 0x00, 0x02, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x03, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00,
1158
- ]);
1159
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1160
- const header = new Zcl.Header(
1161
- {
1162
- reservedBits: 0,
1163
- direction: Direction.SERVER_TO_CLIENT,
1164
- disableDefaultResponse: true,
1165
- frameType: FrameType.GLOBAL,
1166
- manufacturerSpecific: false,
1167
- },
1168
- undefined,
1169
- 2,
1170
- 0x0e,
1171
- );
1172
- const payload = [
1173
- {attrId: 0x0002, selector: {indexes: [3, 4]}},
1174
- {attrId: 0x0005, selector: {indexes: [6, 7, 8]}},
1175
- ];
1176
-
1177
- expect(frame.header).toStrictEqual(header);
1178
- expect(frame.payload).toStrictEqual(payload);
1179
- });
1180
-
1181
- it("ZclFrame from buffer readStructured whole attribute", () => {
1182
- const buffer = Buffer.from([0x18, 0x02, 0x0e, 0x09, 0x00, 0x00]);
1183
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1184
- const header = new Zcl.Header(
1185
- {
1186
- reservedBits: 0,
1187
- direction: Direction.SERVER_TO_CLIENT,
1188
- disableDefaultResponse: true,
1189
- frameType: FrameType.GLOBAL,
1190
- manufacturerSpecific: false,
1191
- },
1192
- undefined,
1193
- 2,
1194
- 0x0e,
1195
- );
1196
- const payload = [{attrId: 0x0009, selector: {indicatorType: StructuredIndicatorType.Whole}}];
1197
-
1198
- expect(frame.header).toStrictEqual(header);
1199
- expect(frame.payload).toStrictEqual(payload);
1200
- });
1201
-
1202
- it("ZclFrame to buffer writeStructured single element", () => {
1203
- const expected = Buffer.from([0x10, 0x02, 0x0f, 0x01, 0x00, 0x01, 0x02, 0x00, 0x20, 0x03]);
1204
- const payload = [{attrId: 0x0001, selector: {indexes: [2]}, dataType: Zcl.DataType.UINT8, elementData: 3}];
1205
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, undefined, 2, 0x0f, Zcl.Clusters.genBasic.ID, payload, {});
1206
-
1207
- expect(frame.toBuffer()).toStrictEqual(expected);
1208
- });
1209
-
1210
- it("ZclFrame to buffer writeStructured multiple elements", () => {
1211
- const expected = Buffer.from([
1212
- 0x10, 0x02, 0x0f, 0x02, 0x00, 0x02, 0x03, 0x00, 0x04, 0x00, 0x42, 0x03, 0x66, 0x6f, 0x6f, 0x05, 0x00, 0x03, 0x06, 0x00, 0x07, 0x00, 0x08,
1213
- 0x00, 0x42, 0x03, 0x62, 0x61, 0x72,
1214
- ]);
1215
- const payload = [
1216
- {attrId: 0x0002, selector: {indexes: [3, 4]}, dataType: Zcl.DataType.CHAR_STR, elementData: "foo"},
1217
- {attrId: 0x0005, selector: {indexes: [6, 7, 8]}, dataType: Zcl.DataType.CHAR_STR, elementData: "bar"},
1218
- ];
1219
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, undefined, 2, 0x0f, Zcl.Clusters.genBasic.ID, payload, {});
1220
-
1221
- expect(frame.toBuffer()).toStrictEqual(expected);
1222
- });
1223
-
1224
- it("ZclFrame to buffer writeStructured whole attribute", () => {
1225
- const expected = Buffer.from([0x10, 0x02, 0x0f, 0x09, 0x00, 0x00, 0x48, 0x20, 0x03, 0x00, 0x0a, 0x0b, 0x0c]);
1226
- const payload = [
1227
- {attrId: 0x0009, selector: {}, dataType: Zcl.DataType.ARRAY, elementData: {elementType: Zcl.DataType.UINT8, elements: [10, 11, 12]}},
1228
- ];
1229
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, undefined, 2, 0x0f, Zcl.Clusters.genBasic.ID, payload, {});
1230
-
1231
- expect(frame.toBuffer()).toStrictEqual(expected);
1232
- });
1233
-
1234
- it("ZclFrame to buffer writeStructured add element into set/bag", () => {
1235
- const expected = Buffer.from([0x10, 0x02, 0x0f, 0x0d, 0x00, 0x10, 0x42, 0x03, 0x66, 0x6f, 0x6f]);
1236
- const payload = [
1237
- {attrId: 0x000d, selector: {indicatorType: StructuredIndicatorType.WriteAdd}, dataType: Zcl.DataType.CHAR_STR, elementData: "foo"},
1238
- ];
1239
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, undefined, 2, 0x0f, Zcl.Clusters.genBasic.ID, payload, {});
1240
-
1241
- expect(frame.toBuffer()).toStrictEqual(expected);
1242
- });
1243
-
1244
- it("ZclFrame to buffer writeStructured remove element from set/bag", () => {
1245
- const expected = Buffer.from([0x10, 0x02, 0x0f, 0x0e, 0x00, 0x20, 0x42, 0x03, 0x62, 0x61, 0x72]);
1246
- const payload = [
1247
- {attrId: 0x000e, selector: {indicatorType: StructuredIndicatorType.WriteRemove}, dataType: Zcl.DataType.CHAR_STR, elementData: "bar"},
1248
- ];
1249
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.CLIENT_TO_SERVER, true, undefined, 2, 0x0f, Zcl.Clusters.genBasic.ID, payload, {});
1250
-
1251
- expect(frame.toBuffer()).toStrictEqual(expected);
1252
- });
1253
-
1254
- it("ZclFrame to buffer writeStructured Livolo malformed", () => {
1255
- const expected = Buffer.from([0x7c, 0xd2, 0x1a, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
1256
- const payload = [{attrId: 0x0000, selector: null, elementData: [0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]}];
1257
- const frame = Zcl.Frame.create(
1258
- FrameType.GLOBAL,
1259
- Direction.SERVER_TO_CLIENT,
1260
- true,
1261
- 0x1ad2,
1262
- 0xe9,
1263
- 0x0f,
1264
- Zcl.Clusters.genBasic.ID,
1265
- payload,
1266
- {},
1267
- 3,
1268
- );
1269
-
1270
- expect(frame.toBuffer()).toStrictEqual(expected);
1271
- });
1272
-
1273
- it("ZclFrame to buffer writeStructuredRsp success", () => {
1274
- const expected = Buffer.from([8, 1, 0x10, 0]);
1275
- const payload = [{status: Zcl.Status.SUCCESS}];
1276
- const frame = Zcl.Frame.create(
1277
- FrameType.GLOBAL,
1278
- Direction.SERVER_TO_CLIENT,
1279
- false,
1280
- undefined,
1281
- 1,
1282
- 0x10,
1283
- Zcl.Clusters.genBasic.ID,
1284
- payload,
1285
- {},
1286
- );
1287
-
1288
- expect(frame.toBuffer()).toStrictEqual(expected);
1289
- });
1290
-
1291
- it("ZclFrame to buffer writeStructuredRsp failed selector unknown or none for type", () => {
1292
- const expected = Buffer.from([8, 1, 0x10, 147, 1, 0, 0]);
1293
- const payload = [{status: Zcl.Status.ACTION_DENIED, attrId: 1, selector: {indicatorType: StructuredIndicatorType.Whole}}];
1294
- const frame = Zcl.Frame.create(
1295
- FrameType.GLOBAL,
1296
- Direction.SERVER_TO_CLIENT,
1297
- false,
1298
- undefined,
1299
- 1,
1300
- 0x10,
1301
- Zcl.Clusters.genBasic.ID,
1302
- payload,
1303
- {},
1304
- );
1305
-
1306
- expect(frame.toBuffer()).toStrictEqual(expected);
1307
- });
1308
-
1309
- it("ZclFrame to buffer writeStructuredRsp failed with selector", () => {
1310
- const expected = Buffer.from([8, 1, 0x10, 147, 1, 0, 1, 254, 0]);
1311
- const payload = [{status: Zcl.Status.ACTION_DENIED, attrId: 1, selector: {indexes: [254]}}];
1312
- const frame = Zcl.Frame.create(
1313
- FrameType.GLOBAL,
1314
- Direction.SERVER_TO_CLIENT,
1315
- false,
1316
- undefined,
1317
- 1,
1318
- 0x10,
1319
- Zcl.Clusters.genBasic.ID,
1320
- payload,
1321
- {},
1322
- );
1323
-
1324
- expect(frame.toBuffer()).toStrictEqual(expected);
1325
- });
1326
-
1327
- it("ZclFrame to buffer writeStructuredRsp failed mixed selectors", () => {
1328
- const expected = Buffer.from([8, 1, 0x10, 147, 16, 0, 0, 149, 14, 0, 2, 254, 0, 32, 0]);
1329
- const payload = [
1330
- {status: Zcl.Status.ACTION_DENIED, attrId: 16, selector: {indicatorType: StructuredIndicatorType.Whole}},
1331
- {status: Zcl.Status.ABORT, attrId: 14, selector: {indexes: [254, 32]}},
1332
- ];
1333
- const frame = Zcl.Frame.create(
1334
- FrameType.GLOBAL,
1335
- Direction.SERVER_TO_CLIENT,
1336
- false,
1337
- undefined,
1338
- 1,
1339
- 0x10,
1340
- Zcl.Clusters.genBasic.ID,
1341
- payload,
1342
- {},
1343
- );
1344
-
1345
- expect(frame.toBuffer()).toStrictEqual(expected);
1346
- });
1347
-
1348
- it("ZclFrame from buffer writeStructuredRsp success", () => {
1349
- const buffer = Buffer.from([8, 1, 0x10, 0]);
1350
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1351
- const header = new Zcl.Header(
1352
- {
1353
- reservedBits: 0,
1354
- direction: Direction.SERVER_TO_CLIENT,
1355
- disableDefaultResponse: false,
1356
- frameType: FrameType.GLOBAL,
1357
- manufacturerSpecific: false,
1358
- },
1359
- undefined,
1360
- 1,
1361
- 0x10,
1362
- );
1363
- const payload = [{status: Zcl.Status.SUCCESS}];
1364
-
1365
- expect(frame.header).toStrictEqual(header);
1366
- expect(frame.payload).toStrictEqual(payload);
1367
- });
1368
-
1369
- it("ZclFrame from buffer writeStructuredRsp failed selector unknown or none for type", () => {
1370
- const buffer = Buffer.from([8, 1, 0x10, 147, 1, 0, 0]);
1371
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1372
- const header = new Zcl.Header(
1373
- {
1374
- reservedBits: 0,
1375
- direction: Direction.SERVER_TO_CLIENT,
1376
- disableDefaultResponse: false,
1377
- frameType: FrameType.GLOBAL,
1378
- manufacturerSpecific: false,
1379
- },
1380
- undefined,
1381
- 1,
1382
- 0x10,
1383
- );
1384
- const payload = [{status: Zcl.Status.ACTION_DENIED, attrId: 1, selector: {indicatorType: StructuredIndicatorType.Whole}}];
1385
-
1386
- expect(frame.header).toStrictEqual(header);
1387
- expect(frame.payload).toStrictEqual(payload);
1388
- });
1389
-
1390
- it("ZclFrame from buffer writeStructuredRsp failed with selector", () => {
1391
- const buffer = Buffer.from([8, 1, 0x10, 147, 1, 0, 1, 254, 0]);
1392
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1393
- const header = new Zcl.Header(
1394
- {
1395
- reservedBits: 0,
1396
- direction: Direction.SERVER_TO_CLIENT,
1397
- disableDefaultResponse: false,
1398
- frameType: FrameType.GLOBAL,
1399
- manufacturerSpecific: false,
1400
- },
1401
- undefined,
1402
- 1,
1403
- 0x10,
1404
- );
1405
- const payload = [{status: Zcl.Status.ACTION_DENIED, attrId: 1, selector: {indexes: [254]}}];
1406
-
1407
- expect(frame.header).toStrictEqual(header);
1408
- expect(frame.payload).toStrictEqual(payload);
1409
- });
1410
-
1411
- it("ZclFrame from buffer writeStructuredRsp failed mixed selectors", () => {
1412
- const buffer = Buffer.from([8, 1, 0x10, 147, 16, 0, 0, 149, 14, 0, 2, 254, 0, 32, 0]);
1413
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.genBasic.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1414
- const header = new Zcl.Header(
1415
- {
1416
- reservedBits: 0,
1417
- direction: Direction.SERVER_TO_CLIENT,
1418
- disableDefaultResponse: false,
1419
- frameType: FrameType.GLOBAL,
1420
- manufacturerSpecific: false,
1421
- },
1422
- undefined,
1423
- 1,
1424
- 0x10,
1425
- );
1426
- const payload = [
1427
- {status: Zcl.Status.ACTION_DENIED, attrId: 16, selector: {indicatorType: StructuredIndicatorType.Whole}},
1428
- {status: Zcl.Status.ABORT, attrId: 14, selector: {indexes: [254, 32]}},
1429
- ];
1430
-
1431
- expect(frame.header).toStrictEqual(header);
1432
- expect(frame.payload).toStrictEqual(payload);
1433
- });
1434
-
1435
- it("ZclFrame from buffer ssIasAce arm command", () => {
1436
- const buffer = Buffer.from([1, 87, 0, 0, 6, 49, 50, 51, 52, 53, 54, 0]);
1437
- const frame = Zcl.Frame.fromBuffer(Zcl.Clusters.ssIasAce.ID, Zcl.Header.fromBuffer(buffer)!, buffer, {});
1438
- const header = new Zcl.Header(
1439
- {
1440
- reservedBits: 0,
1441
- direction: 0,
1442
- disableDefaultResponse: false,
1443
- frameType: 1,
1444
- manufacturerSpecific: false,
1445
- },
1446
- undefined,
1447
- 87,
1448
- 0,
1449
- );
1450
-
1451
- const payload = {
1452
- armmode: 0,
1453
- code: "123456",
1454
- zoneid: 0,
1455
- };
1456
-
1457
- expect(frame.header).toStrictEqual(header);
1458
- expect(frame.payload).toStrictEqual(payload);
1459
- expect(frame.header.isGlobal).toBe(false);
1460
- expect(frame.header.isSpecific).toBe(true);
1461
- expect(frame.isCluster("ssIasAce")).toBe(true);
1462
- expect(frame.isCommand("arm")).toBe(true);
1463
- });
1464
-
1465
- it("ZclFrame to buffer discoverRsp", () => {
1466
- const expected = Buffer.from([24, 23, 13, 0, 32, 0, 32, 33, 0, 32, 49, 0, 48, 51, 0, 32, 53, 0, 24]);
1467
- const payload = {
1468
- discComplete: 0,
1469
- attrInfos: [
1470
- {attrId: 32, dataType: 32},
1471
- {attrId: 33, dataType: 32},
1472
- {attrId: 49, dataType: 48},
1473
- {attrId: 51, dataType: 32},
1474
- {attrId: 53, dataType: 24},
1475
- ],
1476
- };
1477
-
1478
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, true, undefined, 23, 13, 0, payload, {});
1479
-
1480
- expect(frame.toBuffer()).toStrictEqual(expected);
1481
- });
1482
-
1483
- it("ZclFrame to buffer tradfriArrowSingle", () => {
1484
- const expected = Buffer.from([0x05, 0x7c, 0x11, 0x1d, 0x07, 0x00, 0x01, 0x0d, 0x00]);
1485
- const payload = {value: 256, value2: 13};
1486
-
1487
- const frame = Zcl.Frame.create(FrameType.SPECIFIC, Direction.CLIENT_TO_SERVER, false, 4476, 29, 7, 5, payload, {});
1488
-
1489
- expect(frame.toBuffer()).toStrictEqual(expected);
1490
- });
1491
-
1492
- it("ZclFrame to buffer readRsp failed", () => {
1493
- const expected = Buffer.from([8, 1, 1, 1, 0, 2]);
1494
- const payload = [{status: 2, attrId: 1}];
1495
-
1496
- const frame = Zcl.Frame.create(FrameType.GLOBAL, Direction.SERVER_TO_CLIENT, false, undefined, 1, 1, 0, payload, {});
1497
-
1498
- expect(frame.toBuffer()).toStrictEqual(expected);
1499
- });
1500
-
1501
- it("ZclFrame to buffer offWithEffect", () => {
1502
- const expected = Buffer.from([0x1, 1, 64, 1, 0]);
1503
- const payload = {effectid: 1, effectvariant: 0};
1504
-
1505
- const frame = Zcl.Frame.create(FrameType.SPECIFIC, Direction.CLIENT_TO_SERVER, false, undefined, 1, 64, 6, payload, {});
1506
-
1507
- expect(frame.toBuffer()).toStrictEqual(expected);
1508
- });
1509
-
1510
- it("ZclFrame to buffer offWithEffect", () => {
1511
- const expected = Buffer.from([9, 9, 0, 1]);
1512
-
1513
- const frame = Zcl.Frame.create(FrameType.SPECIFIC, Direction.SERVER_TO_CLIENT, false, undefined, 9, "restartDeviceRsp", 21, {status: 1}, {});
1514
-
1515
- expect(frame.toBuffer()).toStrictEqual(expected);
1516
- });
1517
-
1518
- it("ZclFrame to buffer invalid frametype", () => {
1519
- expect(() => {
1520
- Zcl.Frame.create(
1521
- // @ts-expect-error invalid on purpose
1522
- 3,
1523
- Direction.CLIENT_TO_SERVER,
1524
- false,
1525
- undefined,
1526
- 1,
1527
- 64,
1528
- 6,
1529
- {},
1530
- {},
1531
- ).toBuffer();
1532
- }).toThrow("Frametype '3' not valid");
1533
- });
1534
-
1535
- it("BuffaloZcl read array", () => {
1536
- const buffer = Buffer.from([32, 3, 0, 1, 2, 3]);
1537
- const buffalo = new BuffaloZcl(buffer);
1538
- const value = buffalo.read(DataType.ARRAY, {});
1539
- expect(buffalo.getPosition()).toBe(6);
1540
- expect(value).toStrictEqual([1, 2, 3]);
1541
- });
1542
-
1543
- it("BuffaloZcl read struct", () => {
1544
- const buffer = Buffer.from([0, 2, 0, 32, 8, 33, 4, 0]);
1545
- const buffalo = new BuffaloZcl(buffer, 1);
1546
- const value = buffalo.read(DataType.STRUCT, {});
1547
- expect(buffalo.getPosition()).toBe(8);
1548
- expect(value).toStrictEqual([
1549
- {elmType: 32, elmVal: 8},
1550
- {elmType: 33, elmVal: 4},
1551
- ]);
1552
- });
1553
-
1554
- it("BuffaloZcl read longCharStr", () => {
1555
- const buffer = Buffer.from([5, 0, 0x68, 0x65, 0x6c, 0x6c, 0x6f]);
1556
- const buffalo = new BuffaloZcl(buffer);
1557
- const value = buffalo.read(DataType.LONG_CHAR_STR, {});
1558
- expect(buffalo.getPosition()).toBe(7);
1559
- expect(value).toStrictEqual("hello");
1560
- });
1561
-
1562
- it("BuffaloZcl read longOctetStr", () => {
1563
- const buffer = Buffer.from([5, 0, 0x68, 0x65, 0x6c, 0x6c, 0x6f]);
1564
- const buffalo = new BuffaloZcl(buffer);
1565
- const value = buffalo.read(DataType.LONG_OCTET_STR, {});
1566
- expect(buffalo.getPosition()).toBe(7);
1567
- expect(value).toStrictEqual(buffer.subarray(2));
1568
- });
1569
-
1570
- it("BuffaloZcl read extensionFieldSets", () => {
1571
- const buffer = Buffer.from([0, 3, 8, 1, 0, 2, 0, 3, 0, 4, 5]);
1572
- const buffalo = new BuffaloZcl(buffer);
1573
- const value = buffalo.read(BuffaloZclDataType.EXTENSION_FIELD_SETS, {});
1574
- expect(buffalo.getPosition()).toBe(11);
1575
- expect(value).toStrictEqual([{clstId: 768, len: 8, extField: [1, 2, 3, 4, 5]}]);
1576
- });
1577
-
1578
- it("BuffaloZcl read list zoneinfo", () => {
1579
- const buffer = Buffer.from([1, 5, 0, 2, 6, 0]);
1580
- const buffalo = new BuffaloZcl(buffer);
1581
- const value = buffalo.read(BuffaloZclDataType.LIST_ZONEINFO, {length: 2});
1582
- expect(buffalo.getPosition()).toBe(6);
1583
- expect(value).toStrictEqual([
1584
- {zoneID: 1, zoneStatus: 5},
1585
- {zoneID: 2, zoneStatus: 6},
1586
- ]);
1587
- });
1588
-
1589
- it.each([DataType.UINT40, DataType.DATA40, DataType.BITMAP40])("BuffaloZcl read uint40, data40, bitmap40", (type) => {
1590
- const buffer = Buffer.from([1, 5, 4, 5, 6, 7]);
1591
- const buffalo = new BuffaloZcl(buffer);
1592
- const value = buffalo.read(type, {});
1593
- expect(buffalo.getPosition()).toBe(5);
1594
- expect(value).toStrictEqual(25853953281);
1595
- });
1596
-
1597
- it.each([DataType.UINT48, DataType.DATA48, DataType.BITMAP48])("BuffaloZcl read uint48, data48, bitmap48", (type) => {
1598
- const buffer = Buffer.from([1, 5, 4, 5, 6, 7]);
1599
- const buffalo = new BuffaloZcl(buffer);
1600
- const value = buffalo.read(type, {});
1601
- expect(buffalo.getPosition()).toBe(6);
1602
- expect(value).toStrictEqual(7722435347713);
1603
- });
1604
-
1605
- it.each([DataType.UINT56, DataType.DATA56, DataType.BITMAP56])("BuffaloZcl read uint56, data56, bitmap56", (type) => {
1606
- const buffer = Buffer.from([1, 5, 4, 5, 6, 7, 7]);
1607
- const buffalo = new BuffaloZcl(buffer);
1608
- const value = buffalo.read(type, {});
1609
- expect(buffalo.getPosition()).toBe(7);
1610
- expect(value).toStrictEqual(1978047272322305n);
1611
- });
1612
-
1613
- it.each([DataType.UINT64, DataType.DATA64, DataType.BITMAP64])("BuffaloZcl read uint64, data64, bitmap64", (type) => {
1614
- const buffer = Buffer.from([1, 5, 4, 5, 6, 7, 7, 9]);
1615
- const buffalo = new BuffaloZcl(buffer);
1616
- const value = buffalo.read(type, {});
1617
- expect(buffalo.getPosition()).toBe(8);
1618
- expect(value).toStrictEqual(0x0907070605040501n);
1619
- });
1620
-
1621
- it("BuffaloZcl read int40", () => {
1622
- const buffer = Buffer.from([254, 255, 255, 255, 127]);
1623
- const buffalo = new BuffaloZcl(buffer);
1624
- const value = buffalo.read(DataType.INT40, {});
1625
- expect(buffalo.getPosition()).toBe(5);
1626
- expect(value).toStrictEqual(549755813886);
1627
- });
1628
-
1629
- it("BuffaloZcl read int56", () => {
1630
- const buffer = Buffer.from([1, 5, 4, 5, 6, 7, 7]);
1631
- const buffalo = new BuffaloZcl(buffer);
1632
- const value = buffalo.read(DataType.INT56, {});
1633
- expect(buffalo.getPosition()).toBe(7);
1634
- expect(value).toStrictEqual(1978047272322305n);
1635
- });
1636
-
1637
- it("BuffaloZcl read int64", () => {
1638
- const buffer = Buffer.from([1, 5, 4, 5, 6, 7, 7, 9]);
1639
- const buffalo = new BuffaloZcl(buffer);
1640
- const value = buffalo.read(DataType.INT64, {});
1641
- expect(buffalo.getPosition()).toBe(8);
1642
- expect(value).toStrictEqual(650496393613673729n);
1643
- });
1644
-
1645
- it.each([
1646
- ["no data point", Buffer.from([]), []],
1647
- ["single data point", Buffer.from([1, 4, 0, 1, 1]), [{dp: 1, datatype: 4, data: Buffer.from([1])}]],
1648
- [
1649
- "two data points",
1650
- Buffer.from([1, 4, 0, 1, 1, 4, 2, 0, 4, 0, 0, 0, 90]),
1651
- [
1652
- {dp: 1, datatype: 4, data: Buffer.from([1])},
1653
- {dp: 4, datatype: 2, data: Buffer.from([0, 0, 0, 90])},
1654
- ],
1655
- ],
1656
- ["incomplete data point is ignored", Buffer.from([1, 4, 0, 1, 1, 4]), [{dp: 1, datatype: 4, data: Buffer.from([1])}]],
1657
- [
1658
- "incomplete data buffer",
1659
- Buffer.from([1, 4, 0, 1, 1, 4, 2, 0, 4, 0, 0, 0]),
1660
- [
1661
- {dp: 1, datatype: 4, data: Buffer.from([1])},
1662
- {dp: 4, datatype: 2, data: Buffer.from([0, 0, 0])},
1663
- ],
1664
- ],
1665
- ])("BuffaloZcl read readListTuyaDataPointValues %s", (_name, buffer, payload) => {
1666
- const buffalo = new BuffaloZcl(buffer);
1667
- const value = buffalo.read(BuffaloZclDataType.LIST_TUYA_DATAPOINT_VALUES, {});
1668
- expect(buffalo.isMore()).not.toBeTruthy();
1669
- expect(value).toStrictEqual(payload);
1670
- });
1671
-
1672
- it("BuffaloZcl write charStr", () => {
1673
- const payload = "hello";
1674
- const buffer = Buffer.alloc(7);
1675
- const expected = Buffer.from([5, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0]);
1676
- const buffalo = new BuffaloZcl(buffer);
1677
- buffalo.write(DataType.CHAR_STR, payload, {});
1678
- expect(buffalo.getPosition()).toBe(6);
1679
- expect(buffer).toStrictEqual(expected);
1680
- });
1681
-
1682
- it("BuffaloZcl write longCharStr", () => {
1683
- const payload = "hello";
1684
- const buffer = Buffer.alloc(7);
1685
- const expected = Buffer.from([5, 0, 0x68, 0x65, 0x6c, 0x6c, 0x6f]);
1686
- const buffalo = new BuffaloZcl(buffer);
1687
- buffalo.write(DataType.LONG_CHAR_STR, payload, {});
1688
- expect(buffalo.getPosition()).toBe(7);
1689
- expect(buffer).toStrictEqual(expected);
1690
- });
1691
-
1692
- it("BuffaloZcl write octetStr", () => {
1693
- const payload = [1, 2, 4];
1694
- const buffer = Buffer.alloc(5);
1695
- const expected = Buffer.from([3, 1, 2, 4, 0]);
1696
- const buffalo = new BuffaloZcl(buffer);
1697
- buffalo.write(DataType.OCTET_STR, payload, {});
1698
- expect(buffalo.getPosition()).toBe(4);
1699
- expect(buffer).toStrictEqual(expected);
1700
- });
1701
-
1702
- it("BuffaloZcl write longOctetStr", () => {
1703
- const payload = [1, 2, 3, 4, 5];
1704
- const buffer = Buffer.alloc(7);
1705
- const expected = Buffer.from([5, 0, 1, 2, 3, 4, 5]);
1706
- const buffalo = new BuffaloZcl(buffer);
1707
- buffalo.write(DataType.LONG_OCTET_STR, payload, {});
1708
- expect(buffalo.getPosition()).toBe(7);
1709
- expect(buffer).toStrictEqual(expected);
1710
- });
1711
-
1712
- it("BuffaloZcl write extensionFieldSets", () => {
1713
- const payload = [{clstId: 768, len: 8, extField: [1, 2, 3, 4, 5]}];
1714
- const buffer = Buffer.alloc(12);
1715
- const expected = Buffer.from([0, 3, 8, 1, 0, 2, 0, 3, 0, 4, 5, 0]);
1716
- const buffalo = new BuffaloZcl(buffer);
1717
- buffalo.write(BuffaloZclDataType.EXTENSION_FIELD_SETS, payload, {});
1718
- expect(buffalo.getPosition()).toBe(11);
1719
- expect(buffer).toStrictEqual(expected);
1720
- });
1721
-
1722
- it("BuffaloZcl write zoneinfo", () => {
1723
- const payload = [
1724
- {zoneID: 1, zoneStatus: 5},
1725
- {zoneID: 2, zoneStatus: 6},
1726
- ];
1727
- const buffer = Buffer.alloc(6);
1728
- const expected = Buffer.from([1, 5, 0, 2, 6, 0]);
1729
- const buffalo = new BuffaloZcl(buffer);
1730
- buffalo.write(BuffaloZclDataType.LIST_ZONEINFO, payload, {});
1731
- expect(buffalo.getPosition()).toBe(6);
1732
- expect(buffer).toStrictEqual(expected);
1733
- });
1734
-
1735
- it.each([DataType.UINT40, DataType.DATA40, DataType.BITMAP40])("BuffaloZcl write uint40, data40, bitmap40", (type) => {
1736
- const payload = 1099511627773;
1737
- const buffer = Buffer.alloc(5);
1738
- const expected = Buffer.from([253, 255, 255, 255, 255]);
1739
- const buffalo = new BuffaloZcl(buffer);
1740
- buffalo.write(type, payload, {});
1741
- expect(buffalo.getPosition()).toBe(5);
1742
- expect(buffer).toStrictEqual(expected);
1743
- });
1744
-
1745
- it.each([DataType.UINT48, DataType.DATA48, DataType.BITMAP48])("BuffaloZcl write uint48, data48, bitmap48", (type) => {
1746
- const payload = 281474976710653;
1747
- const buffer = Buffer.alloc(6);
1748
- const expected = Buffer.from([253, 255, 255, 255, 255, 255]);
1749
- const buffalo = new BuffaloZcl(buffer);
1750
- buffalo.write(type, payload, {});
1751
- expect(buffalo.getPosition()).toBe(6);
1752
- expect(buffer).toStrictEqual(expected);
1753
- });
1754
-
1755
- it.each([DataType.UINT56, DataType.DATA56, DataType.BITMAP56])("BuffaloZcl write uint56, data56, bitmap56", (type) => {
1756
- const payload = 1978047272322305n;
1757
- const buffer = Buffer.alloc(7);
1758
- const expected = Buffer.from([1, 5, 4, 5, 6, 7, 7]);
1759
- const buffalo = new BuffaloZcl(buffer);
1760
- buffalo.write(type, payload, {});
1761
- expect(buffalo.getPosition()).toBe(7);
1762
- expect(buffer).toStrictEqual(expected);
1763
- });
1764
-
1765
- it.each([DataType.UINT64, DataType.DATA64, DataType.BITMAP64])("BuffaloZcl write uint64, data64, bitmap64", (type) => {
1766
- const payload = 0x0907070605040501n;
1767
- const buffer = Buffer.alloc(8);
1768
- const expected = Buffer.from([1, 5, 4, 5, 6, 7, 7, 9]);
1769
- const buffalo = new BuffaloZcl(buffer);
1770
- buffalo.write(type, payload, {});
1771
- expect(buffalo.getPosition()).toBe(8);
1772
- expect(buffer).toStrictEqual(expected);
1773
- });
1774
-
1775
- it("BuffaloZcl write int40", () => {
1776
- const payload = 549755813886;
1777
- const buffer = Buffer.alloc(5);
1778
- const expected = Buffer.from([254, 255, 255, 255, 127]);
1779
- const buffalo = new BuffaloZcl(buffer);
1780
- buffalo.write(DataType.INT40, payload, {});
1781
- expect(buffalo.getPosition()).toBe(5);
1782
- expect(buffer).toStrictEqual(expected);
1783
- });
1784
-
1785
- it("BuffaloZcl write int56", () => {
1786
- const payload = 1978047272322305n;
1787
- const buffer = Buffer.alloc(7);
1788
- const expected = Buffer.from([1, 5, 4, 5, 6, 7, 7]);
1789
- const buffalo = new BuffaloZcl(buffer);
1790
- buffalo.write(DataType.INT56, payload, {});
1791
- expect(buffalo.getPosition()).toBe(7);
1792
- expect(buffer).toStrictEqual(expected);
1793
- });
1794
-
1795
- it("BuffaloZcl write int64", () => {
1796
- const payload = 650496393613673729n;
1797
- const buffer = Buffer.alloc(8);
1798
- const expected = Buffer.from([1, 5, 4, 5, 6, 7, 7, 9]);
1799
- const buffalo = new BuffaloZcl(buffer);
1800
- buffalo.write(DataType.INT64, payload, {});
1801
- expect(buffalo.getPosition()).toBe(8);
1802
- expect(buffer).toStrictEqual(expected);
1803
- });
1804
-
1805
- it("BuffaloZcl write array element type string", () => {
1806
- const payload = {
1807
- elementType: Zcl.DataType.OCTET_STR,
1808
- elements: [
1809
- [0, 13, 1, 6, 0, 2],
1810
- [1, 13, 2, 6, 0, 2],
1811
- [2, 13, 3, 6, 0, 2],
1812
- [3, 13, 4, 6, 0, 2],
1813
- ],
1814
- };
1815
- const expected = Buffer.from([0x41, 0x04, 0x00, 6, 0, 13, 1, 6, 0, 2, 6, 1, 13, 2, 6, 0, 2, 6, 2, 13, 3, 6, 0, 2, 6, 3, 13, 4, 6, 0, 2]);
1816
- const buffer = Buffer.alloc(expected.length);
1817
- const buffalo = new BuffaloZcl(buffer);
1818
- buffalo.write(DataType.ARRAY, payload, {});
1819
- expect(buffalo.getPosition()).toBe(expected.length);
1820
- expect(buffer).toStrictEqual(expected);
1821
- });
1822
-
1823
- it("BuffaloZcl write array element type numeric", () => {
1824
- const payload = {elementType: Zcl.DataType.DATA8, elements: [0, 0, 0, 0]};
1825
- const expected = Buffer.from([0x08, 0x04, 0x00, 0, 0, 0, 0]);
1826
- const buffer = Buffer.alloc(expected.length);
1827
- const buffalo = new BuffaloZcl(buffer);
1828
- buffalo.write(DataType.ARRAY, payload, {});
1829
- expect(buffalo.getPosition()).toBe(expected.length);
1830
- expect(buffer).toStrictEqual(expected);
1831
- });
1832
-
1833
- it("BuffaloZcl write array element type numeric passed as string of DataType", () => {
1834
- const payload = {elementType: "DATA8", elements: [0, 0, 0, 0]};
1835
- const expected = Buffer.from([0x08, 0x04, 0x00, 0, 0, 0, 0]);
1836
- const buffer = Buffer.alloc(expected.length);
1837
- const buffalo = new BuffaloZcl(buffer);
1838
- buffalo.write(DataType.ARRAY, payload, {});
1839
- expect(buffalo.getPosition()).toBe(expected.length);
1840
- expect(buffer).toStrictEqual(expected);
1841
- });
1842
-
1843
- it("BuffaloZcl write struct", () => {
1844
- const payload = [
1845
- {elmType: Zcl.DataType.UINT8, elmVal: 3},
1846
- {elmType: Zcl.DataType.CHAR_STR, elmVal: "a"},
1847
- ];
1848
- const expected = Buffer.from([2, 0, Zcl.DataType.UINT8, 3, Zcl.DataType.CHAR_STR, 1, 0x61]);
1849
- const buffer = Buffer.alloc(expected.length);
1850
- const buffalo = new BuffaloZcl(buffer);
1851
- buffalo.write(DataType.STRUCT, payload, {});
1852
- expect(buffalo.getPosition()).toBe(expected.length);
1853
- expect(buffer).toStrictEqual(expected);
1854
- });
1855
-
1856
- it("BuffaloZcl write security key", () => {
1857
- const payload = [0x09, 0x07, 0x07, 0x06, 0x05, 0x04, 0x05, 0x01, 0x09, 0x07, 0x07, 0x06, 0x05, 0x04, 0x05, 0x01];
1858
- const buffer = Buffer.alloc(16);
1859
- const expected = Buffer.from([0x09, 0x07, 0x07, 0x06, 0x05, 0x04, 0x05, 0x01, 0x09, 0x07, 0x07, 0x06, 0x05, 0x04, 0x05, 0x01]);
1860
- const buffalo = new BuffaloZcl(buffer);
1861
- buffalo.write(DataType.SEC_KEY, payload, {});
1862
- expect(buffalo.getPosition()).toBe(16);
1863
- expect(buffer).toStrictEqual(expected);
1864
- });
1865
-
1866
- it.each([
1867
- ["no data point", [], Buffer.from([])],
1868
- ["single data point", [{dp: 1, datatype: 4, data: Buffer.from([1])}], Buffer.from([1, 4, 0, 1, 1])],
1869
- [
1870
- "two data points",
1871
- [
1872
- {dp: 1, datatype: 4, data: Buffer.from([1])},
1873
- {dp: 4, datatype: 2, data: Buffer.from([0, 0, 0, 90])},
1874
- ],
1875
- Buffer.from([1, 4, 0, 1, 1, 4, 2, 0, 4, 0, 0, 0, 90]),
1876
- ],
1877
- ])("BuffaloZcl writeListTuyaDataPointValues %s", (_name, payload, expected) => {
1878
- const buffer = Buffer.alloc(expected.length);
1879
- const buffalo = new BuffaloZcl(buffer);
1880
- buffalo.write(BuffaloZclDataType.LIST_TUYA_DATAPOINT_VALUES, payload, {});
1881
- expect(buffalo.getPosition()).toBe(expected.length);
1882
- expect(buffer).toStrictEqual(expected);
1883
- });
1884
-
1885
- it("Zcl utils get cluster without manufacturerCode", () => {
1886
- const cluster = Zcl.Utils.getCluster(0xfc00, undefined, {});
1887
- expect(cluster.ID).toBe(0xfc00);
1888
- expect(cluster.name).toBe("manuSpecificAssaDoorLock");
1889
- });
1890
-
1891
- it("Zcl utils get cluster with manufacturerCode", () => {
1892
- const cluster = Zcl.Utils.getCluster(0xfc00, 0x100b, {});
1893
- expect(cluster.ID).toBe(0xfc00);
1894
- expect(cluster.name).toBe("manuSpecificPhilips");
1895
- });
1896
-
1897
- it("Zcl utils get cluster manufacturerCode", () => {
1898
- const cluster = Zcl.Utils.getCluster(0xfc00, 0x10f2, {});
1899
- expect(cluster.ID).toBe(0xfc00);
1900
- expect(cluster.name).toBe("manuSpecificAssaDoorLock");
1901
- });
1902
-
1903
- it("Zcl utils get cluster manufacturerCode wrong", () => {
1904
- const cluster = Zcl.Utils.getCluster(0xfc00, 123, {});
1905
- expect(cluster.ID).toBe(0xfc00);
1906
- expect(cluster.name).toBe("manuSpecificAssaDoorLock");
1907
- });
1908
-
1909
- it("Zcl utils get cluster attributes manufacturerCode", () => {
1910
- const cluster = Zcl.Utils.getCluster("closuresWindowCovering", 0x1021, {});
1911
- const attribute = cluster.getAttribute(0xf004);
1912
- expect(attribute).toStrictEqual({ID: 0xf004, manufacturerCode: 0x1021, name: "stepPositionTilt", type: 48});
1913
- });
1914
-
1915
- it("Zcl utils get cluster attributes manufacturerCode wrong", () => {
1916
- const cluster = Zcl.Utils.getCluster("closuresWindowCovering", 123, {});
1917
- expect(cluster.getAttribute(0x1000)).toBeUndefined();
1918
- });
1919
-
1920
- it("Zcl utils get command", () => {
1921
- const cluster = Zcl.Utils.getCluster("genOnOff", undefined, {});
1922
- const command = cluster.getCommand(0);
1923
- expect(command.name).toStrictEqual("off");
1924
- expect(cluster.getCommand("off")).toStrictEqual(command);
1925
- });
1926
-
1927
- it("Zcl utils get attribute", () => {
1928
- const cluster = Zcl.Utils.getCluster("genOnOff", undefined, {});
1929
- const attribute = cluster.getAttribute(16385);
1930
- expect(attribute?.name).toStrictEqual("onTime");
1931
- expect(cluster.getAttribute("onTime")).toStrictEqual(attribute);
1932
- });
1933
-
1934
- it("Zcl utils get attribute non-existing", () => {
1935
- const cluster = Zcl.Utils.getCluster("genOnOff", undefined, {});
1936
- expect(cluster.getAttribute("notExisting")).toBeUndefined();
1937
- });
1938
-
1939
- it("Zcl utils get command non-existing", () => {
1940
- const cluster = Zcl.Utils.getCluster("genOnOff", undefined, {});
1941
- expect(() => cluster.getCommand("notExisting")).toThrow("Cluster 'genOnOff' has no command 'notExisting'");
1942
- });
1943
-
1944
- it("Zcl green power readGpd commissioning", () => {
1945
- const buffer = [
1946
- 0xff, // device
1947
- 0x00, // options
1948
- ];
1949
- const frame = new BuffaloZcl(Buffer.from(buffer));
1950
-
1951
- expect(
1952
- frame.read(BuffaloZclDataType.GPD_FRAME, {
1953
- payload: {
1954
- payloadSize: buffer.length,
1955
- commandID: 0xe0,
1956
- },
1957
- }),
1958
- ).toStrictEqual({
1959
- deviceID: 0xff,
1960
- options: 0x00,
1961
- extendedOptions: 0x00,
1962
- securityKey: Buffer.alloc(16),
1963
- keyMic: 0,
1964
- outgoingCounter: 0,
1965
- manufacturerID: 0,
1966
- modelID: 0,
1967
- numGpdCommands: 0,
1968
- gpdCommandIdList: Buffer.alloc(0),
1969
- numServerClusters: 0,
1970
- numClientClusters: 0,
1971
- gpdServerClusters: Buffer.alloc(0),
1972
- gpdClientClusters: Buffer.alloc(0),
1973
- applicationInfo: 0x00,
1974
- genericSwitchConfig: 0,
1975
- currentContactStatus: 0,
1976
- });
1977
- });
1978
-
1979
- it("Zcl green power readGpd commissioning all options", () => {
1980
- const buffer = [
1981
- 0xff, // device
1982
- 0x80 | 0x04, // options
1983
- 0x20 | 0x40 | 0x80, // extended options
1984
- 0,
1985
- 0,
1986
- 0,
1987
- 0,
1988
- 0,
1989
- 0,
1990
- 0,
1991
- 0,
1992
- 0,
1993
- 0,
1994
- 0,
1995
- 0,
1996
- 0,
1997
- 0,
1998
- 0,
1999
- 0, // security key
2000
- 0,
2001
- 0,
2002
- 0,
2003
- 0, // key mic
2004
- 0,
2005
- 0,
2006
- 0,
2007
- 0, // outgoing counter
2008
- 0x01 | 0x02 | 0x04 | 0x08 | 0x10, // application info
2009
- 0,
2010
- 0, // manufacturer ID
2011
- 0,
2012
- 0, // model ID
2013
- 0, // num GPD commands + commands
2014
- 0, // clusters
2015
- 2, // switch info length
2016
- 0, // generic switch config
2017
- 1, // current contact status
2018
- ];
2019
- const frame = new BuffaloZcl(Buffer.from(buffer));
2020
-
2021
- expect(
2022
- frame.read(BuffaloZclDataType.GPD_FRAME, {
2023
- payload: {
2024
- payloadSize: buffer.length,
2025
- commandID: 0xe0,
2026
- },
2027
- }),
2028
- ).toStrictEqual({
2029
- deviceID: 0xff,
2030
- options: 0x80 | 0x04,
2031
- extendedOptions: 0x20 | 0x40 | 0x80,
2032
- securityKey: Buffer.alloc(16),
2033
- keyMic: 0,
2034
- outgoingCounter: 0,
2035
- manufacturerID: 0,
2036
- modelID: 0,
2037
- numGpdCommands: 0,
2038
- gpdCommandIdList: Buffer.alloc(0),
2039
- numServerClusters: 0,
2040
- numClientClusters: 0,
2041
- gpdServerClusters: Buffer.alloc(0),
2042
- gpdClientClusters: Buffer.alloc(0),
2043
- applicationInfo: 0x01 | 0x02 | 0x04 | 0x08 | 0x10,
2044
- genericSwitchConfig: 0,
2045
- currentContactStatus: 1,
2046
- });
2047
- });
2048
-
2049
- it("Zcl green power readGpd channel request", () => {
2050
- const buffer = [0xfa];
2051
- const frame = new BuffaloZcl(Buffer.from(buffer));
2052
-
2053
- expect(
2054
- frame.read(BuffaloZclDataType.GPD_FRAME, {
2055
- payload: {
2056
- payloadSize: buffer.length,
2057
- commandID: 0xe3,
2058
- },
2059
- }),
2060
- ).toStrictEqual({
2061
- nextChannel: 0xa,
2062
- nextNextChannel: 0xf,
2063
- });
2064
- });
2065
-
2066
- it("Zcl green power readGpd attribute report", () => {
2067
- const buffer = [
2068
- 0x12,
2069
- 0x34, // Manufacturer ID
2070
- 0xff,
2071
- 0xff, // Cluster ID
2072
- 0x00,
2073
- 0x00, // Attribute ID
2074
- DataType.UINT32, // Attribute Type
2075
- 0x00,
2076
- 0x01,
2077
- 0x02,
2078
- 0x03,
2079
- 0x01,
2080
- 0x00,
2081
- DataType.CHAR_STR,
2082
- 0x06,
2083
- 0x5a,
2084
- 0x49,
2085
- 0x47,
2086
- 0x42,
2087
- 0x45,
2088
- 0x45,
2089
- 0x02,
2090
- 0x00,
2091
- DataType.BOOLEAN,
2092
- 0x01,
2093
- ];
2094
- const frame = new BuffaloZcl(Buffer.from(buffer));
2095
-
2096
- expect(
2097
- frame.read(BuffaloZclDataType.GPD_FRAME, {
2098
- payload: {
2099
- commandID: 0xa1,
2100
- payloadSize: buffer.length,
2101
- },
2102
- }),
2103
- ).toStrictEqual({
2104
- manufacturerCode: 13330,
2105
- clusterID: 65535,
2106
- attributes: {
2107
- "0": 50462976,
2108
- "1": "ZIGBEE",
2109
- "2": 1,
2110
- },
2111
- });
2112
- });
2113
-
2114
- it("Zcl green power writeGpd commissioning", () => {
2115
- const expected = [
2116
- 1, // length
2117
- 0, // options
2118
- ];
2119
- const frame = new BuffaloZcl(Buffer.alloc(2));
2120
-
2121
- frame.write(
2122
- BuffaloZclDataType.GPD_FRAME,
2123
- {
2124
- commandID: 0xf0,
2125
- options: 0,
2126
- panID: 0,
2127
- securityKey: Buffer.alloc(16),
2128
- keyMic: 0,
2129
- frameCounter: 0,
2130
- },
2131
- {},
2132
- );
2133
-
2134
- expect(frame.getWritten()).toStrictEqual(Buffer.from(expected));
2135
- });
2136
-
2137
- it("Zcl green power writeGpd commissioning all options", () => {
2138
- const expected = [
2139
- 27, // length
2140
- 0b11111, // options
2141
- 0xff,
2142
- 0xff, // PAN ID
2143
- 0,
2144
- 0,
2145
- 0,
2146
- 0,
2147
- 0,
2148
- 0,
2149
- 0,
2150
- 0,
2151
- 0,
2152
- 0,
2153
- 0,
2154
- 0,
2155
- 0,
2156
- 0,
2157
- 0,
2158
- 0, // security key
2159
- 0,
2160
- 0,
2161
- 0,
2162
- 0, // key mic
2163
- 0,
2164
- 0,
2165
- 0,
2166
- 0, // frame counter
2167
- ];
2168
- const frame = new BuffaloZcl(Buffer.alloc(28));
2169
-
2170
- frame.write(
2171
- BuffaloZclDataType.GPD_FRAME,
2172
- {
2173
- commandID: 0xf0,
2174
- options: 0b11111,
2175
- panID: 0xffff,
2176
- securityKey: Buffer.alloc(16),
2177
- keyMic: 0,
2178
- frameCounter: 0,
2179
- },
2180
- {},
2181
- );
2182
-
2183
- expect(frame.getWritten()).toStrictEqual(Buffer.from(expected));
2184
- });
2185
-
2186
- it("Zcl green power writeGpd custom reply", () => {
2187
- const expected = [
2188
- 6, // length
2189
- 90,
2190
- 73,
2191
- 71,
2192
- 66,
2193
- 69,
2194
- 69, // ZIGBEE
2195
- ];
2196
-
2197
- const frame = new BuffaloZcl(Buffer.alloc(7));
2198
- frame.write(
2199
- BuffaloZclDataType.GPD_FRAME,
2200
- {
2201
- commandID: 0xf4,
2202
- buffer: Buffer.from("ZIGBEE"),
2203
- },
2204
- {},
2205
- );
2206
-
2207
- expect(frame.getWritten()).toStrictEqual(Buffer.from(expected));
2208
- });
2209
-
2210
- it("Zcl green power writeGpd unhandled command", () => {
2211
- const frame = new BuffaloZcl(Buffer.alloc(7));
2212
- frame.write(
2213
- BuffaloZclDataType.GPD_FRAME,
2214
- {
2215
- commandID: 0x1ff,
2216
- },
2217
- {},
2218
- );
2219
-
2220
- expect(frame.getWritten()).toStrictEqual(Buffer.alloc(0));
2221
- });
2222
-
2223
- it("Zcl green power writeGpd channel configuration", () => {
2224
- const expected = [
2225
- 1, // length
2226
- 0xf, // Channel 26
2227
- ];
2228
-
2229
- const frame = new BuffaloZcl(Buffer.alloc(2));
2230
- frame.write(
2231
- BuffaloZclDataType.GPD_FRAME,
2232
- {
2233
- commandID: 0xf3,
2234
- operationalChannel: 0xf,
2235
- basic: false,
2236
- },
2237
- {},
2238
- );
2239
-
2240
- expect(frame.getWritten()).toStrictEqual(Buffer.from(expected));
2241
- });
2242
-
2243
- it("Zcl green power writeGpd channel configuration basic", () => {
2244
- const expected = [
2245
- 1, // length
2246
- 0x1f, // Channel 26 + Basic
2247
- ];
2248
-
2249
- const frame = new BuffaloZcl(Buffer.alloc(2));
2250
- frame.write(
2251
- BuffaloZclDataType.GPD_FRAME,
2252
- {
2253
- commandID: 0xf3,
2254
- operationalChannel: 0xf,
2255
- basic: true,
2256
- },
2257
- {},
2258
- );
2259
-
2260
- expect(frame.getWritten()).toStrictEqual(Buffer.from(expected));
2261
- });
2262
-
2263
- it("ZclFrame parse MiBoxer zone configuration command", () => {
2264
- const zoneConfigPayload = Buffer.from([
2265
- 0x11, 0x01, 0xf0, 0x08, 0x84, 0x2b, 0x01, 0x98, 0x2b, 0x02, 0xac, 0x2b, 0x03, 0xc0, 0x2b, 0x04, 0xd4, 0x2b, 0x05, 0xe8, 0x2b, 0x06, 0xfc,
2266
- 0x2b, 0x07, 0x10, 0x2c, 0x08,
2267
- ]);
2268
- const zoneConfigFrame = Zcl.Frame.fromBuffer(Zcl.Clusters.genGroups.ID, Zcl.Header.fromBuffer(zoneConfigPayload)!, zoneConfigPayload, {});
2269
- expect(zoneConfigFrame.payload.zones).toStrictEqual([
2270
- {zoneNum: 1, groupId: 0x2b84},
2271
- {zoneNum: 2, groupId: 0x2b98},
2272
- {zoneNum: 3, groupId: 0x2bac},
2273
- {zoneNum: 4, groupId: 0x2bc0},
2274
- {zoneNum: 5, groupId: 0x2bd4},
2275
- {zoneNum: 6, groupId: 0x2be8},
2276
- {zoneNum: 7, groupId: 0x2bfc},
2277
- {zoneNum: 8, groupId: 0x2c10},
2278
- ]);
2279
- });
2280
- it("ZclFrame serialize MiBoxer zone configuration command", () => {
2281
- const testZones = [
2282
- {zoneNum: 1, groupId: 0x2b84},
2283
- {zoneNum: 2, groupId: 0x2b98},
2284
- {zoneNum: 3, groupId: 0x2bac},
2285
- {zoneNum: 4, groupId: 0x2bc0},
2286
- {zoneNum: 5, groupId: 0x2bd4},
2287
- {zoneNum: 6, groupId: 0x2be8},
2288
- {zoneNum: 7, groupId: 0x2bfc},
2289
- {zoneNum: 8, groupId: 0x2c10},
2290
- ];
2291
- const zoneConfigFrame = Zcl.Frame.create(
2292
- FrameType.SPECIFIC,
2293
- Direction.CLIENT_TO_SERVER,
2294
- true,
2295
- undefined,
2296
- 1,
2297
- "miboxerSetZones",
2298
- Zcl.Clusters.genGroups.ID,
2299
- {zones: testZones},
2300
- {},
2301
- );
2302
- expect(zoneConfigFrame.toBuffer()).toStrictEqual(
2303
- Buffer.from([
2304
- 0x11, 0x01, 0xf0, 0x08, 0x84, 0x2b, 0x01, 0x98, 0x2b, 0x02, 0xac, 0x2b, 0x03, 0xc0, 0x2b, 0x04, 0xd4, 0x2b, 0x05, 0xe8, 0x2b, 0x06,
2305
- 0xfc, 0x2b, 0x07, 0x10, 0x2c, 0x08,
2306
- ]),
2307
- );
2308
- });
2309
-
2310
- it("BuffaloZcl read BIG_ENDIAN_UINT24", () => {
2311
- const buffer = Buffer.from([0x01, 0x01, 0x86, 0xa0, 0x02]);
2312
- const buffalo = new BuffaloZcl(buffer, 1);
2313
- const value = buffalo.read(BuffaloZclDataType.BIG_ENDIAN_UINT24, {});
2314
- expect(buffalo.getPosition()).toBe(4);
2315
- expect(value).toStrictEqual(100000);
2316
- });
2317
-
2318
- it("BuffaloZcl write BIG_ENDIAN_UINT24", () => {
2319
- const payload = 16777200;
2320
- const buffer = Buffer.alloc(4);
2321
- const expected = Buffer.from([0x00, 0xff, 0xff, 0xf0]);
2322
- const buffalo = new BuffaloZcl(buffer, 1);
2323
- buffalo.write(BuffaloZclDataType.BIG_ENDIAN_UINT24, payload, {});
2324
- expect(buffalo.getPosition()).toBe(4);
2325
- expect(buffer).toStrictEqual(expected);
2326
- });
2327
-
2328
- it("BuffaloZcl read BUFFER whole", () => {
2329
- const buffer = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]);
2330
- const buffalo = new BuffaloZcl(buffer);
2331
- const value = buffalo.read(BuffaloZclDataType.BUFFER, {});
2332
- expect(value).toStrictEqual(Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]));
2333
- });
2334
-
2335
- it("BuffaloZcl read BUFFER with length", () => {
2336
- const buffer = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]);
2337
- const buffalo = new BuffaloZcl(buffer);
2338
- const value = buffalo.read(BuffaloZclDataType.BUFFER, {length: 3});
2339
- expect(value).toStrictEqual(Buffer.from([0x01, 0x02, 0x03]));
2340
- });
2341
-
2342
- it("BuffaloZcl write BUFFER whole", () => {
2343
- const buffer = Buffer.alloc(5);
2344
- const expected = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]);
2345
- const buffalo = new BuffaloZcl(buffer);
2346
- buffalo.write(BuffaloZclDataType.BUFFER, expected, {});
2347
- expect(buffer).toStrictEqual(expected);
2348
- });
2349
-
2350
- it("BuffaloZcl write BUFFER always whole - length ignored", () => {
2351
- const buffer = Buffer.alloc(5);
2352
- const expected = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]);
2353
- const buffalo = new BuffaloZcl(buffer);
2354
- buffalo.write(BuffaloZclDataType.BUFFER, expected, {length: 3});
2355
- expect(buffer).toStrictEqual(expected);
2356
- });
2357
-
2358
- it("BuffaloZcl write non existing type", () => {
2359
- expect(() => {
2360
- const buffalo = new BuffaloZcl(Buffer.alloc(0));
2361
- // @ts-expect-error invalid typing
2362
- buffalo.write(9999, 1, {});
2363
- }).toThrow(new Error("Write for '9999' not available"));
2364
- });
2365
-
2366
- it("BuffaloZcl read non existing type", () => {
2367
- expect(() => {
2368
- const buffalo = new BuffaloZcl(Buffer.alloc(0));
2369
- // @ts-expect-error invalid typing
2370
- buffalo.read(9999, {});
2371
- }).toThrow(new Error("Read for '9999' not available"));
2372
- });
2373
-
2374
- it("BuffaloZcl write TOD", () => {
2375
- const buffer = Buffer.alloc(4);
2376
- const expected = Buffer.from([0, 59, 34, 88]);
2377
- const buffalo = new BuffaloZcl(buffer);
2378
- const payload = {hours: 0, minutes: 59, seconds: 34, hundredths: 88};
2379
- buffalo.write(DataType.TOD, payload, {});
2380
- expect(buffalo.getBuffer()).toStrictEqual(expected);
2381
- });
2382
-
2383
- it("BuffaloZcl read TOD", () => {
2384
- const expected = {hours: 0, minutes: 59, seconds: 34, hundredths: 88};
2385
- const buffalo = new BuffaloZcl(Buffer.from([0, 59, 34, 88]));
2386
- const value = buffalo.read(DataType.TOD, {});
2387
- expect(value).toStrictEqual(expected);
2388
- });
2389
-
2390
- it("BuffaloZcl write DATE", () => {
2391
- const buffer = Buffer.alloc(4);
2392
- const expected = Buffer.from([100, 8, 31, 3]);
2393
- const buffalo = new BuffaloZcl(buffer);
2394
- const payload = {year: 2000, month: 8, dayOfMonth: 31, dayOfWeek: 3};
2395
- buffalo.write(DataType.DATE, payload, {});
2396
- expect(buffalo.getBuffer()).toStrictEqual(expected);
2397
- });
2398
-
2399
- it("BuffaloZcl read DATE", () => {
2400
- const expected = {year: 2000, month: 8, dayOfMonth: 31, dayOfWeek: 3};
2401
- const buffalo = new BuffaloZcl(Buffer.from([100, 8, 31, 3]));
2402
- const value = buffalo.read(DataType.DATE, {});
2403
- expect(value).toStrictEqual(expected);
2404
- });
2405
-
2406
- it("BuffaloZcl write TOD non-value", () => {
2407
- const buffer = Buffer.alloc(4);
2408
- const expected = Buffer.from([0xff, 0xff, 0xff, 0xff]);
2409
- const buffalo = new BuffaloZcl(buffer);
2410
- const payload = {hours: Number.NaN, minutes: Number.NaN, seconds: Number.NaN, hundredths: Number.NaN};
2411
- buffalo.write(DataType.TOD, payload, {});
2412
- expect(buffalo.getBuffer()).toStrictEqual(expected);
2413
- });
2414
-
2415
- it("BuffaloZcl read DATE non-value", () => {
2416
- const buffer = Buffer.alloc(4);
2417
- const expected = Buffer.from([0xff, 0xff, 0xff, 0xff]);
2418
- const buffalo = new BuffaloZcl(buffer);
2419
- const payload = {year: Number.NaN, month: Number.NaN, dayOfMonth: Number.NaN, dayOfWeek: Number.NaN};
2420
- buffalo.write(DataType.DATE, payload, {});
2421
- expect(buffalo.getBuffer()).toStrictEqual(expected);
2422
- });
2423
-
2424
- it("BuffaloZcl read OCTET_STR non-value", () => {
2425
- const buffalo = new BuffaloZcl(Buffer.from([0xff]));
2426
- const value = buffalo.read(DataType.OCTET_STR, {});
2427
- expect(value).toStrictEqual(Buffer.from([]));
2428
- });
2429
-
2430
- it("BuffaloZcl read CHAR_STR non-value", () => {
2431
- const buffalo = new BuffaloZcl(Buffer.from([0xff]));
2432
- const value = buffalo.read(DataType.CHAR_STR, {});
2433
- expect(value).toStrictEqual("");
2434
- });
2435
-
2436
- it("BuffaloZcl read MI_STRUCT non-value", () => {
2437
- const buffalo = new BuffaloZcl(Buffer.from([0xff]));
2438
- const value = buffalo.read(BuffaloZclDataType.MI_STRUCT, {});
2439
- expect(value).toStrictEqual({});
2440
- });
2441
-
2442
- it("BuffaloZcl read LONG_OCTET_STR non-value", () => {
2443
- const buffalo = new BuffaloZcl(Buffer.from([0xff, 0xff]));
2444
- const value = buffalo.read(DataType.LONG_OCTET_STR, {});
2445
- expect(value).toStrictEqual(Buffer.from([]));
2446
- });
2447
-
2448
- it("BuffaloZcl read LONG_CHAR_STR non-value", () => {
2449
- const buffalo = new BuffaloZcl(Buffer.from([0xff, 0xff]));
2450
- const value = buffalo.read(DataType.LONG_CHAR_STR, {});
2451
- expect(value).toStrictEqual("");
2452
- });
2453
-
2454
- it("BuffaloZcl read ARRAY non-value", () => {
2455
- const buffalo = new BuffaloZcl(Buffer.from([DataType.UINT8, 0xff, 0xff]));
2456
- const value = buffalo.read(DataType.ARRAY, {});
2457
- expect(value).toStrictEqual([]);
2458
- });
2459
-
2460
- it("BuffaloZcl read STRUCT non-value", () => {
2461
- const buffalo = new BuffaloZcl(Buffer.from([0xff, 0xff]));
2462
- const value = buffalo.read(DataType.STRUCT, {});
2463
- expect(value).toStrictEqual([]);
2464
- });
2465
-
2466
- it("BuffaloZcl write NO_DATA", () => {
2467
- const buffalo = new BuffaloZcl(Buffer.alloc(2));
2468
- const payload = null;
2469
- buffalo.write(DataType.NO_DATA, payload, {});
2470
- expect(buffalo.getPosition()).toStrictEqual(0);
2471
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00]));
2472
- });
2473
-
2474
- it("BuffaloZcl read NO_DATA", () => {
2475
- const buffalo = new BuffaloZcl(Buffer.from([0x00, 0x00]), 1);
2476
- const value = buffalo.read(DataType.NO_DATA, {});
2477
- expect(buffalo.getPosition()).toStrictEqual(1);
2478
- expect(value).toStrictEqual(undefined);
2479
- });
2480
-
2481
- it("BuffaloZcl write UNKNOWN", () => {
2482
- const buffalo = new BuffaloZcl(Buffer.alloc(2));
2483
- const payload = null;
2484
- buffalo.write(DataType.UNKNOWN, payload, {});
2485
- expect(buffalo.getPosition()).toStrictEqual(0);
2486
- expect(buffalo.getBuffer()).toStrictEqual(Buffer.from([0x00, 0x00]));
2487
- });
2488
-
2489
- it("BuffaloZcl read UNKNOWN", () => {
2490
- const buffalo = new BuffaloZcl(Buffer.from([0x00, 0x00]), 1);
2491
- const value = buffalo.read(DataType.UNKNOWN, {});
2492
- expect(buffalo.getPosition()).toStrictEqual(1);
2493
- expect(value).toStrictEqual(undefined);
2494
- });
2495
-
2496
- it("ZclHeader return undefined when too short", () => {
2497
- const header = Zcl.Header.fromBuffer(Buffer.from([0, 8]));
2498
- expect(header).toStrictEqual(undefined);
2499
- });
2500
-
2501
- it("ZclHeader return undefined when too short manufacturer specific", () => {
2502
- const header = Zcl.Header.fromBuffer(Buffer.from([4, 8, 3]));
2503
- expect(header).toStrictEqual(undefined);
2504
- });
2505
-
2506
- describe("BuffaloZcl write passthrough to Buffalo", () => {
2507
- let buffalo: BuffaloZcl;
2508
-
2509
- beforeEach(() => {
2510
- buffalo = new BuffaloZcl(Buffer.alloc(255));
2511
- });
2512
-
2513
- it("uint8", () => {
2514
- const uint8Spy = vi.spyOn(buffalo, "writeUInt8");
2515
- const types = [DataType.DATA8, DataType.BOOLEAN, DataType.BITMAP8, DataType.UINT8, DataType.ENUM8];
2516
- let i = 0;
2517
-
2518
- for (const type of types) {
2519
- buffalo.write(type, 1, {});
2520
- expect(uint8Spy).toHaveBeenCalledTimes(++i);
2521
- }
2522
- });
2523
-
2524
- it("uint16", () => {
2525
- const uint16Spy = vi.spyOn(buffalo, "writeUInt16");
2526
- const types = [DataType.DATA16, DataType.BITMAP16, DataType.UINT16, DataType.ENUM16, DataType.CLUSTER_ID, DataType.ATTR_ID];
2527
- let i = 0;
2528
-
2529
- for (const type of types) {
2530
- buffalo.write(type, 1, {});
2531
- expect(uint16Spy).toHaveBeenCalledTimes(++i);
2532
- }
2533
- });
2534
-
2535
- it("uint24", () => {
2536
- const uint24Spy = vi.spyOn(buffalo, "writeUInt24");
2537
- const types = [DataType.DATA24, DataType.BITMAP24, DataType.UINT24];
2538
- let i = 0;
2539
-
2540
- for (const type of types) {
2541
- buffalo.write(type, 1, {});
2542
- expect(uint24Spy).toHaveBeenCalledTimes(++i);
2543
- }
2544
- });
2545
-
2546
- it("uint32", () => {
2547
- const uint32Spy = vi.spyOn(buffalo, "writeUInt32");
2548
- const types = [DataType.DATA32, DataType.BITMAP32, DataType.UINT32, DataType.UTC, DataType.BAC_OID];
2549
- let i = 0;
2550
-
2551
- for (const type of types) {
2552
- buffalo.write(type, 1, {});
2553
- expect(uint32Spy).toHaveBeenCalledTimes(++i);
2554
- }
2555
- });
2556
-
2557
- it("int8", () => {
2558
- const int8Spy = vi.spyOn(buffalo, "writeInt8");
2559
- buffalo.write(DataType.INT8, 1, {});
2560
- expect(int8Spy).toHaveBeenCalledTimes(1);
2561
- });
2562
-
2563
- it("int16", () => {
2564
- const int16Spy = vi.spyOn(buffalo, "writeInt16");
2565
- buffalo.write(DataType.INT16, 1, {});
2566
- expect(int16Spy).toHaveBeenCalledTimes(1);
2567
- });
2568
-
2569
- it("int24", () => {
2570
- const int24Spy = vi.spyOn(buffalo, "writeInt24");
2571
- buffalo.write(DataType.INT24, 1, {});
2572
- expect(int24Spy).toHaveBeenCalledTimes(1);
2573
- });
2574
-
2575
- it("int32", () => {
2576
- const int32Spy = vi.spyOn(buffalo, "writeInt32");
2577
- buffalo.write(DataType.INT32, 1, {});
2578
- expect(int32Spy).toHaveBeenCalledTimes(1);
2579
- });
2580
-
2581
- it("int48", () => {
2582
- const int48Spy = vi.spyOn(buffalo, "writeInt48");
2583
- buffalo.write(DataType.INT48, 1, {});
2584
- expect(int48Spy).toHaveBeenCalledTimes(1);
2585
- });
2586
-
2587
- it("list uint8", () => {
2588
- const listuint8Spy = vi.spyOn(buffalo, "writeListUInt8");
2589
- buffalo.write(BuffaloZclDataType.LIST_UINT8, [1], {});
2590
- expect(listuint8Spy).toHaveBeenCalledTimes(1);
2591
- });
2592
-
2593
- it("list uint16", () => {
2594
- const listuint16Spy = vi.spyOn(buffalo, "writeListUInt16");
2595
- buffalo.write(BuffaloZclDataType.LIST_UINT16, [1], {});
2596
- expect(listuint16Spy).toHaveBeenCalledTimes(1);
2597
- });
2598
-
2599
- it("list uint24", () => {
2600
- const listuint24Spy = vi.spyOn(buffalo, "writeListUInt24");
2601
- buffalo.write(BuffaloZclDataType.LIST_UINT24, [1], {});
2602
- expect(listuint24Spy).toHaveBeenCalledTimes(1);
2603
- });
2604
-
2605
- it("list uint32", () => {
2606
- const listuint32Spy = vi.spyOn(buffalo, "writeListUInt32");
2607
- buffalo.write(BuffaloZclDataType.LIST_UINT32, [1], {});
2608
- expect(listuint32Spy).toHaveBeenCalledTimes(1);
2609
- });
2610
-
2611
- // NOT SUPPORTED
2612
- // it('semi prec', () => {
2613
- // const semiPrecSpy = vi.spyOn(buffalo, 'writeSemiFloatLE');
2614
- // buffalo.write(DataType.SEMI_PREC, 1, {});
2615
- // expect(semiPrecSpy).toHaveBeenCalledTimes(1);
2616
- // });
2617
-
2618
- it("single prec", () => {
2619
- const singlePrecSpy = vi.spyOn(buffalo, "writeFloatLE");
2620
- buffalo.write(DataType.SINGLE_PREC, 1.1, {});
2621
- expect(singlePrecSpy).toHaveBeenCalledTimes(1);
2622
- });
2623
-
2624
- it("double prec", () => {
2625
- const doublePrecSpy = vi.spyOn(buffalo, "writeDoubleLE");
2626
- buffalo.write(DataType.DOUBLE_PREC, 1.1, {});
2627
- expect(doublePrecSpy).toHaveBeenCalledTimes(1);
2628
- });
2629
-
2630
- it("ieee add", () => {
2631
- const doublePrecSpy = vi.spyOn(buffalo, "writeIeeeAddr");
2632
- buffalo.write(DataType.IEEE_ADDR, "0xf1f1f1f1f1f1f1f1", {});
2633
- expect(doublePrecSpy).toHaveBeenCalledTimes(1);
2634
- });
2635
- });
2636
-
2637
- describe("BuffaloZcl read passthrough to Buffalo", () => {
2638
- let buffalo: BuffaloZcl;
2639
-
2640
- beforeEach(() => {
2641
- buffalo = new BuffaloZcl(Buffer.alloc(255));
2642
- });
2643
-
2644
- it("uint8", () => {
2645
- const uint8Spy = vi.spyOn(buffalo, "readUInt8");
2646
- const types = [DataType.DATA8, DataType.BOOLEAN, DataType.BITMAP8, DataType.UINT8, DataType.ENUM8];
2647
- let i = 0;
2648
-
2649
- for (const type of types) {
2650
- buffalo.read(type, {});
2651
- expect(uint8Spy).toHaveBeenCalledTimes(++i);
2652
- }
2653
- });
2654
-
2655
- it("uint16", () => {
2656
- const uint16Spy = vi.spyOn(buffalo, "readUInt16");
2657
- const types = [DataType.DATA16, DataType.BITMAP16, DataType.UINT16, DataType.ENUM16, DataType.CLUSTER_ID, DataType.ATTR_ID];
2658
- let i = 0;
2659
-
2660
- for (const type of types) {
2661
- buffalo.read(type, {});
2662
- expect(uint16Spy).toHaveBeenCalledTimes(++i);
2663
- }
2664
- });
2665
-
2666
- it("uint24", () => {
2667
- const uint24Spy = vi.spyOn(buffalo, "readUInt24");
2668
- const types = [DataType.DATA24, DataType.BITMAP24, DataType.UINT24];
2669
- let i = 0;
2670
-
2671
- for (const type of types) {
2672
- buffalo.read(type, {});
2673
- expect(uint24Spy).toHaveBeenCalledTimes(++i);
2674
- }
2675
- });
2676
-
2677
- it("uint32", () => {
2678
- const uint32Spy = vi.spyOn(buffalo, "readUInt32");
2679
- const types = [DataType.DATA32, DataType.BITMAP32, DataType.UINT32, DataType.UTC, DataType.BAC_OID];
2680
- let i = 0;
2681
-
2682
- for (const type of types) {
2683
- buffalo.read(type, {});
2684
- expect(uint32Spy).toHaveBeenCalledTimes(++i);
2685
- }
2686
- });
2687
-
2688
- it("int8", () => {
2689
- const int8Spy = vi.spyOn(buffalo, "readInt8");
2690
- buffalo.read(DataType.INT8, {});
2691
- expect(int8Spy).toHaveBeenCalledTimes(1);
2692
- });
2693
-
2694
- it("int16", () => {
2695
- const int16Spy = vi.spyOn(buffalo, "readInt16");
2696
- buffalo.read(DataType.INT16, {});
2697
- expect(int16Spy).toHaveBeenCalledTimes(1);
2698
- });
2699
-
2700
- it("int24", () => {
2701
- const int24Spy = vi.spyOn(buffalo, "readInt24");
2702
- buffalo.read(DataType.INT24, {});
2703
- expect(int24Spy).toHaveBeenCalledTimes(1);
2704
- });
2705
-
2706
- it("int32", () => {
2707
- const int32Spy = vi.spyOn(buffalo, "readInt32");
2708
- buffalo.read(DataType.INT32, {});
2709
- expect(int32Spy).toHaveBeenCalledTimes(1);
2710
- });
2711
-
2712
- it("int48", () => {
2713
- const int48Spy = vi.spyOn(buffalo, "readInt48");
2714
- buffalo.read(DataType.INT48, {});
2715
- expect(int48Spy).toHaveBeenCalledTimes(1);
2716
- });
2717
-
2718
- it("list uint8", () => {
2719
- const listuint8Spy = vi.spyOn(buffalo, "readListUInt8");
2720
- buffalo.read(BuffaloZclDataType.LIST_UINT8, {length: 1});
2721
- expect(listuint8Spy).toHaveBeenCalledTimes(1);
2722
- });
2723
-
2724
- it("list uint16", () => {
2725
- const listuint16Spy = vi.spyOn(buffalo, "readListUInt16");
2726
- buffalo.read(BuffaloZclDataType.LIST_UINT16, {length: 1});
2727
- expect(listuint16Spy).toHaveBeenCalledTimes(1);
2728
- });
2729
-
2730
- it("list uint24", () => {
2731
- const listuint24Spy = vi.spyOn(buffalo, "readListUInt24");
2732
- buffalo.read(BuffaloZclDataType.LIST_UINT24, {length: 1});
2733
- expect(listuint24Spy).toHaveBeenCalledTimes(1);
2734
- });
2735
-
2736
- it("list uint32", () => {
2737
- const listuint32Spy = vi.spyOn(buffalo, "readListUInt32");
2738
- buffalo.read(BuffaloZclDataType.LIST_UINT32, {length: 1});
2739
- expect(listuint32Spy).toHaveBeenCalledTimes(1);
2740
- });
2741
-
2742
- // NOT SUPPORTED
2743
- // it('semi prec', () => {
2744
- // const semiPrecSpy = vi.spyOn(buffalo, 'readSemiFloatLE');
2745
- // buffalo.read(DataType.SEMI_PREC, {});
2746
- // expect(semiPrecSpy).toHaveBeenCalledTimes(1);
2747
- // });
2748
-
2749
- it("single prec", () => {
2750
- const singlePrecSpy = vi.spyOn(buffalo, "readFloatLE");
2751
- buffalo.read(DataType.SINGLE_PREC, {});
2752
- expect(singlePrecSpy).toHaveBeenCalledTimes(1);
2753
- });
2754
-
2755
- it("double prec", () => {
2756
- const doublePrecSpy = vi.spyOn(buffalo, "readDoubleLE");
2757
- buffalo.read(DataType.DOUBLE_PREC, {});
2758
- expect(doublePrecSpy).toHaveBeenCalledTimes(1);
2759
- });
2760
-
2761
- it("ieee add", () => {
2762
- const doublePrecSpy = vi.spyOn(buffalo, "readIeeeAddr");
2763
- buffalo.read(DataType.IEEE_ADDR, {});
2764
- expect(doublePrecSpy).toHaveBeenCalledTimes(1);
2765
- });
2766
- });
2767
-
2768
- it.each([
2769
- BuffaloZclDataType.LIST_UINT8,
2770
- BuffaloZclDataType.LIST_UINT16,
2771
- BuffaloZclDataType.LIST_UINT24,
2772
- BuffaloZclDataType.LIST_UINT32,
2773
- BuffaloZclDataType.LIST_ZONEINFO,
2774
- ])("Throws when read is missing required length option - param %s", (type) => {
2775
- expect(() => {
2776
- const buffalo = new BuffaloZcl(Buffer.alloc(1));
2777
- buffalo.read(type, {});
2778
- }).toThrow(`Cannot read ${BuffaloZclDataType[type]} without length option specified`);
2779
- });
2780
-
2781
- it("Reads as buffer when USE_DATA_TYPE is missing dataType option", () => {
2782
- const buffalo = new BuffaloZcl(Buffer.from([12, 34]));
2783
- const value = buffalo.read(BuffaloZclDataType.USE_DATA_TYPE, {});
2784
- expect(value).toStrictEqual(Buffer.from([12, 34]));
2785
- buffalo.setPosition(1);
2786
- const value2 = buffalo.read(BuffaloZclDataType.USE_DATA_TYPE, {length: 1});
2787
- expect(value2).toStrictEqual(Buffer.from([34]));
2788
- });
2789
-
2790
- it("Writes as buffer when USE_DATA_TYPE is missing dataType option", () => {
2791
- const payload = Buffer.from([12, 34]);
2792
- const buffer = Buffer.alloc(2);
2793
- const buffalo = new BuffaloZcl(buffer);
2794
- buffalo.write(BuffaloZclDataType.USE_DATA_TYPE, payload, {});
2795
- expect(buffer).toStrictEqual(payload);
2796
- });
2797
-
2798
- it("Throws when write USE_DATA_TYPE is missing dataType option and value isnt buffer or number array", () => {
2799
- expect(() => {
2800
- const payload = "abcd";
2801
- const buffalo = new BuffaloZcl(Buffer.alloc(2));
2802
- buffalo.write(BuffaloZclDataType.USE_DATA_TYPE, payload, {});
2803
- }).toThrow("Cannot write USE_DATA_TYPE without dataType option specified");
2804
- });
2805
-
2806
- it("Throws when read GPD_FRAME is missing payload.payloadSize option", () => {
2807
- expect(() => {
2808
- const buffalo = new BuffaloZcl(Buffer.alloc(1));
2809
- buffalo.read(BuffaloZclDataType.GPD_FRAME, {payload: {commandID: 0xa1}});
2810
- }).toThrow("Cannot read GPD_FRAME without required payload options specified");
2811
- });
2812
-
2813
- it("Throws when read LIST_THERMO_TRANSITIONS is missing required payload options", () => {
2814
- expect(() => {
2815
- const buffalo = new BuffaloZcl(Buffer.alloc(1));
2816
- buffalo.read(BuffaloZclDataType.LIST_THERMO_TRANSITIONS, {});
2817
- }).toThrow("Cannot read LIST_THERMO_TRANSITIONS without required payload options specified");
2818
- expect(() => {
2819
- const buffalo = new BuffaloZcl(Buffer.alloc(1));
2820
- buffalo.read(BuffaloZclDataType.LIST_THERMO_TRANSITIONS, {payload: {}});
2821
- }).toThrow("Cannot read LIST_THERMO_TRANSITIONS without required payload options specified");
2822
- expect(() => {
2823
- const buffalo = new BuffaloZcl(Buffer.alloc(1));
2824
- buffalo.read(BuffaloZclDataType.LIST_THERMO_TRANSITIONS, {payload: {mode: 1}});
2825
- }).toThrow("Cannot read LIST_THERMO_TRANSITIONS without required payload options specified");
2826
- expect(() => {
2827
- const buffalo = new BuffaloZcl(Buffer.alloc(1));
2828
- buffalo.read(BuffaloZclDataType.LIST_THERMO_TRANSITIONS, {payload: {numoftrans: 1}});
2829
- }).toThrow("Cannot read LIST_THERMO_TRANSITIONS without required payload options specified");
2830
- });
2831
- });