zigbee-herdsman 6.0.2 → 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 (252) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +12 -3
  3. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  4. package/.github/dependabot.yml +0 -22
  5. package/.github/workflows/ci.yml +0 -69
  6. package/.github/workflows/release-please.yml +0 -18
  7. package/.github/workflows/stale.yml +0 -20
  8. package/.github/workflows/typedoc.yaml +0 -47
  9. package/.release-please-manifest.json +0 -3
  10. package/.vscode/extensions.json +0 -3
  11. package/.vscode/settings.json +0 -11
  12. package/biome.json +0 -98
  13. package/examples/join-and-log.js +0 -24
  14. package/release-please-config.json +0 -9
  15. package/src/adapter/adapter.ts +0 -189
  16. package/src/adapter/adapterDiscovery.ts +0 -666
  17. package/src/adapter/const.ts +0 -12
  18. package/src/adapter/deconz/adapter/deconzAdapter.ts +0 -877
  19. package/src/adapter/deconz/driver/constants.ts +0 -246
  20. package/src/adapter/deconz/driver/driver.ts +0 -1540
  21. package/src/adapter/deconz/driver/frame.ts +0 -11
  22. package/src/adapter/deconz/driver/frameParser.ts +0 -753
  23. package/src/adapter/deconz/driver/parser.ts +0 -45
  24. package/src/adapter/deconz/driver/writer.ts +0 -22
  25. package/src/adapter/deconz/types.d.ts +0 -13
  26. package/src/adapter/ember/adapter/emberAdapter.ts +0 -2265
  27. package/src/adapter/ember/adapter/endpoints.ts +0 -86
  28. package/src/adapter/ember/adapter/oneWaitress.ts +0 -324
  29. package/src/adapter/ember/adapter/tokensManager.ts +0 -782
  30. package/src/adapter/ember/consts.ts +0 -178
  31. package/src/adapter/ember/enums.ts +0 -1746
  32. package/src/adapter/ember/ezsp/buffalo.ts +0 -1392
  33. package/src/adapter/ember/ezsp/consts.ts +0 -148
  34. package/src/adapter/ember/ezsp/enums.ts +0 -1114
  35. package/src/adapter/ember/ezsp/ezsp.ts +0 -9061
  36. package/src/adapter/ember/ezspError.ts +0 -10
  37. package/src/adapter/ember/types.ts +0 -866
  38. package/src/adapter/ember/uart/ash.ts +0 -1960
  39. package/src/adapter/ember/uart/consts.ts +0 -109
  40. package/src/adapter/ember/uart/enums.ts +0 -192
  41. package/src/adapter/ember/uart/parser.ts +0 -48
  42. package/src/adapter/ember/uart/queues.ts +0 -247
  43. package/src/adapter/ember/uart/writer.ts +0 -53
  44. package/src/adapter/ember/utils/initters.ts +0 -58
  45. package/src/adapter/ember/utils/math.ts +0 -73
  46. package/src/adapter/events.ts +0 -21
  47. package/src/adapter/ezsp/adapter/backup.ts +0 -109
  48. package/src/adapter/ezsp/adapter/ezspAdapter.ts +0 -614
  49. package/src/adapter/ezsp/driver/commands.ts +0 -2497
  50. package/src/adapter/ezsp/driver/consts.ts +0 -11
  51. package/src/adapter/ezsp/driver/driver.ts +0 -1002
  52. package/src/adapter/ezsp/driver/ezsp.ts +0 -802
  53. package/src/adapter/ezsp/driver/frame.ts +0 -101
  54. package/src/adapter/ezsp/driver/index.ts +0 -4
  55. package/src/adapter/ezsp/driver/multicast.ts +0 -78
  56. package/src/adapter/ezsp/driver/parser.ts +0 -81
  57. package/src/adapter/ezsp/driver/types/basic.ts +0 -201
  58. package/src/adapter/ezsp/driver/types/index.ts +0 -239
  59. package/src/adapter/ezsp/driver/types/named.ts +0 -2330
  60. package/src/adapter/ezsp/driver/types/struct.ts +0 -844
  61. package/src/adapter/ezsp/driver/uart.ts +0 -460
  62. package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +0 -44
  63. package/src/adapter/ezsp/driver/utils/index.ts +0 -32
  64. package/src/adapter/ezsp/driver/writer.ts +0 -64
  65. package/src/adapter/index.ts +0 -3
  66. package/src/adapter/serialPort.ts +0 -58
  67. package/src/adapter/socketPortUtils.ts +0 -16
  68. package/src/adapter/tstype.ts +0 -78
  69. package/src/adapter/z-stack/adapter/adapter-backup.ts +0 -519
  70. package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +0 -457
  71. package/src/adapter/z-stack/adapter/endpoints.ts +0 -57
  72. package/src/adapter/z-stack/adapter/manager.ts +0 -543
  73. package/src/adapter/z-stack/adapter/tstype.ts +0 -6
  74. package/src/adapter/z-stack/adapter/zStackAdapter.ts +0 -1190
  75. package/src/adapter/z-stack/constants/af.ts +0 -27
  76. package/src/adapter/z-stack/constants/common.ts +0 -285
  77. package/src/adapter/z-stack/constants/dbg.ts +0 -23
  78. package/src/adapter/z-stack/constants/index.ts +0 -11
  79. package/src/adapter/z-stack/constants/mac.ts +0 -128
  80. package/src/adapter/z-stack/constants/sapi.ts +0 -25
  81. package/src/adapter/z-stack/constants/sys.ts +0 -72
  82. package/src/adapter/z-stack/constants/util.ts +0 -82
  83. package/src/adapter/z-stack/constants/utils.ts +0 -14
  84. package/src/adapter/z-stack/constants/zdo.ts +0 -103
  85. package/src/adapter/z-stack/models/startup-options.ts +0 -13
  86. package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +0 -44
  87. package/src/adapter/z-stack/structs/entries/address-manager-table.ts +0 -19
  88. package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +0 -12
  89. package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +0 -21
  90. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +0 -19
  91. package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +0 -21
  92. package/src/adapter/z-stack/structs/entries/channel-list.ts +0 -8
  93. package/src/adapter/z-stack/structs/entries/has-configured.ts +0 -16
  94. package/src/adapter/z-stack/structs/entries/index.ts +0 -16
  95. package/src/adapter/z-stack/structs/entries/nib.ts +0 -66
  96. package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +0 -15
  97. package/src/adapter/z-stack/structs/entries/nwk-key.ts +0 -13
  98. package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +0 -8
  99. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +0 -20
  100. package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +0 -19
  101. package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +0 -33
  102. package/src/adapter/z-stack/structs/entries/security-manager-table.ts +0 -22
  103. package/src/adapter/z-stack/structs/index.ts +0 -4
  104. package/src/adapter/z-stack/structs/serializable-memory-object.ts +0 -14
  105. package/src/adapter/z-stack/structs/struct.ts +0 -367
  106. package/src/adapter/z-stack/structs/table.ts +0 -198
  107. package/src/adapter/z-stack/unpi/constants.ts +0 -33
  108. package/src/adapter/z-stack/unpi/frame.ts +0 -62
  109. package/src/adapter/z-stack/unpi/index.ts +0 -4
  110. package/src/adapter/z-stack/unpi/parser.ts +0 -56
  111. package/src/adapter/z-stack/unpi/writer.ts +0 -21
  112. package/src/adapter/z-stack/utils/channel-list.ts +0 -40
  113. package/src/adapter/z-stack/utils/index.ts +0 -2
  114. package/src/adapter/z-stack/utils/network-options.ts +0 -26
  115. package/src/adapter/z-stack/znp/buffaloZnp.ts +0 -175
  116. package/src/adapter/z-stack/znp/definition.ts +0 -2713
  117. package/src/adapter/z-stack/znp/index.ts +0 -2
  118. package/src/adapter/z-stack/znp/parameterType.ts +0 -22
  119. package/src/adapter/z-stack/znp/tstype.ts +0 -44
  120. package/src/adapter/z-stack/znp/utils.ts +0 -10
  121. package/src/adapter/z-stack/znp/znp.ts +0 -342
  122. package/src/adapter/z-stack/znp/zpiObject.ts +0 -148
  123. package/src/adapter/zboss/adapter/zbossAdapter.ts +0 -526
  124. package/src/adapter/zboss/commands.ts +0 -1184
  125. package/src/adapter/zboss/consts.ts +0 -9
  126. package/src/adapter/zboss/driver.ts +0 -422
  127. package/src/adapter/zboss/enums.ts +0 -360
  128. package/src/adapter/zboss/frame.ts +0 -227
  129. package/src/adapter/zboss/reader.ts +0 -65
  130. package/src/adapter/zboss/types.ts +0 -0
  131. package/src/adapter/zboss/uart.ts +0 -428
  132. package/src/adapter/zboss/utils.ts +0 -58
  133. package/src/adapter/zboss/writer.ts +0 -49
  134. package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +0 -27
  135. package/src/adapter/zigate/adapter/zigateAdapter.ts +0 -618
  136. package/src/adapter/zigate/driver/LICENSE +0 -17
  137. package/src/adapter/zigate/driver/buffaloZiGate.ts +0 -212
  138. package/src/adapter/zigate/driver/commandType.ts +0 -418
  139. package/src/adapter/zigate/driver/constants.ts +0 -150
  140. package/src/adapter/zigate/driver/frame.ts +0 -197
  141. package/src/adapter/zigate/driver/messageType.ts +0 -287
  142. package/src/adapter/zigate/driver/parameterType.ts +0 -32
  143. package/src/adapter/zigate/driver/ziGateObject.ts +0 -146
  144. package/src/adapter/zigate/driver/zigate.ts +0 -423
  145. package/src/adapter/zoh/adapter/utils.ts +0 -27
  146. package/src/adapter/zoh/adapter/zohAdapter.ts +0 -838
  147. package/src/buffalo/buffalo.ts +0 -342
  148. package/src/buffalo/index.ts +0 -1
  149. package/src/controller/controller.ts +0 -1022
  150. package/src/controller/database.ts +0 -124
  151. package/src/controller/events.ts +0 -52
  152. package/src/controller/greenPower.ts +0 -603
  153. package/src/controller/helpers/index.ts +0 -1
  154. package/src/controller/helpers/installCodes.ts +0 -107
  155. package/src/controller/helpers/request.ts +0 -96
  156. package/src/controller/helpers/requestQueue.ts +0 -125
  157. package/src/controller/helpers/zclFrameConverter.ts +0 -47
  158. package/src/controller/helpers/zclTransactionSequenceNumber.ts +0 -19
  159. package/src/controller/index.ts +0 -6
  160. package/src/controller/model/device.ts +0 -1249
  161. package/src/controller/model/endpoint.ts +0 -1105
  162. package/src/controller/model/entity.ts +0 -23
  163. package/src/controller/model/group.ts +0 -424
  164. package/src/controller/model/index.ts +0 -5
  165. package/src/controller/model/zigbeeEntity.ts +0 -30
  166. package/src/controller/touchlink.ts +0 -189
  167. package/src/controller/tstype.ts +0 -274
  168. package/src/index.ts +0 -12
  169. package/src/models/backup-storage-legacy.ts +0 -48
  170. package/src/models/backup-storage-unified.ts +0 -47
  171. package/src/models/backup.ts +0 -37
  172. package/src/models/index.ts +0 -5
  173. package/src/models/network-options.ts +0 -11
  174. package/src/utils/backup.ts +0 -152
  175. package/src/utils/index.ts +0 -5
  176. package/src/utils/logger.ts +0 -20
  177. package/src/utils/patchBigIntSerialization.ts +0 -8
  178. package/src/utils/queue.ts +0 -76
  179. package/src/utils/types.d.ts +0 -3
  180. package/src/utils/utils.ts +0 -19
  181. package/src/utils/wait.ts +0 -5
  182. package/src/utils/waitress.ts +0 -96
  183. package/src/zspec/consts.ts +0 -84
  184. package/src/zspec/enums.ts +0 -22
  185. package/src/zspec/index.ts +0 -3
  186. package/src/zspec/tstypes.ts +0 -18
  187. package/src/zspec/utils.ts +0 -247
  188. package/src/zspec/zcl/buffaloZcl.ts +0 -1220
  189. package/src/zspec/zcl/definition/cluster.ts +0 -5915
  190. package/src/zspec/zcl/definition/clusters-typegen.ts +0 -588
  191. package/src/zspec/zcl/definition/clusters-types.ts +0 -7331
  192. package/src/zspec/zcl/definition/consts.ts +0 -24
  193. package/src/zspec/zcl/definition/enums.ts +0 -203
  194. package/src/zspec/zcl/definition/foundation.ts +0 -329
  195. package/src/zspec/zcl/definition/manufacturerCode.ts +0 -729
  196. package/src/zspec/zcl/definition/status.ts +0 -69
  197. package/src/zspec/zcl/definition/tstype.ts +0 -377
  198. package/src/zspec/zcl/index.ts +0 -11
  199. package/src/zspec/zcl/utils.ts +0 -321
  200. package/src/zspec/zcl/zclFrame.ts +0 -356
  201. package/src/zspec/zcl/zclHeader.ts +0 -102
  202. package/src/zspec/zcl/zclStatusError.ts +0 -10
  203. package/src/zspec/zdo/buffaloZdo.ts +0 -2336
  204. package/src/zspec/zdo/definition/clusters.ts +0 -722
  205. package/src/zspec/zdo/definition/consts.ts +0 -16
  206. package/src/zspec/zdo/definition/enums.ts +0 -99
  207. package/src/zspec/zdo/definition/status.ts +0 -105
  208. package/src/zspec/zdo/definition/tstypes.ts +0 -1062
  209. package/src/zspec/zdo/index.ts +0 -7
  210. package/src/zspec/zdo/utils.ts +0 -76
  211. package/src/zspec/zdo/zdoStatusError.ts +0 -10
  212. package/test/adapter/adapter.test.ts +0 -1062
  213. package/test/adapter/ember/ash.test.ts +0 -337
  214. package/test/adapter/ember/consts.ts +0 -131
  215. package/test/adapter/ember/emberAdapter.test.ts +0 -3449
  216. package/test/adapter/ember/ezsp.test.ts +0 -385
  217. package/test/adapter/ember/ezspBuffalo.test.ts +0 -93
  218. package/test/adapter/ember/ezspError.test.ts +0 -12
  219. package/test/adapter/ember/math.test.ts +0 -206
  220. package/test/adapter/ezsp/frame.test.ts +0 -30
  221. package/test/adapter/ezsp/uart.test.ts +0 -181
  222. package/test/adapter/z-stack/adapter.test.ts +0 -3984
  223. package/test/adapter/z-stack/constants.test.ts +0 -33
  224. package/test/adapter/z-stack/structs.test.ts +0 -115
  225. package/test/adapter/z-stack/unpi.test.ts +0 -213
  226. package/test/adapter/z-stack/znp.test.ts +0 -1284
  227. package/test/adapter/zboss/fixZdoResponse.test.ts +0 -179
  228. package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +0 -81
  229. package/test/adapter/zigate/zdo.test.ts +0 -187
  230. package/test/adapter/zoh/utils.test.ts +0 -36
  231. package/test/adapter/zoh/zohAdapter.test.ts +0 -1307
  232. package/test/benchOptions.ts +0 -14
  233. package/test/buffalo.test.ts +0 -431
  234. package/test/controller.bench.ts +0 -214
  235. package/test/controller.test.ts +0 -8702
  236. package/test/greenpower.test.ts +0 -1408
  237. package/test/mockAdapters.ts +0 -65
  238. package/test/mockDevices.ts +0 -598
  239. package/test/requests.bench.ts +0 -229
  240. package/test/testUtils.ts +0 -20
  241. package/test/tsconfig.json +0 -9
  242. package/test/utils/math.ts +0 -19
  243. package/test/utils.test.ts +0 -279
  244. package/test/vitest.config.mts +0 -26
  245. package/test/zcl.test.ts +0 -2831
  246. package/test/zspec/utils.test.ts +0 -68
  247. package/test/zspec/zcl/buffalo.test.ts +0 -1374
  248. package/test/zspec/zcl/frame.test.ts +0 -960
  249. package/test/zspec/zcl/utils.test.ts +0 -273
  250. package/test/zspec/zdo/buffalo.test.ts +0 -1850
  251. package/test/zspec/zdo/utils.test.ts +0 -241
  252. package/tsconfig.json +0 -24
@@ -1,321 +0,0 @@
1
- import {Clusters} from "./definition/cluster";
2
- import {DataType, DataTypeClass} from "./definition/enums";
3
- import {Foundation, type FoundationCommandName, type FoundationDefinition} from "./definition/foundation";
4
- import type {Attribute, Cluster, ClusterDefinition, ClusterName, Command, CustomClusters} from "./definition/tstype";
5
-
6
- const DATA_TYPE_CLASS_DISCRETE = [
7
- DataType.DATA8,
8
- DataType.DATA16,
9
- DataType.DATA24,
10
- DataType.DATA32,
11
- DataType.DATA40,
12
- DataType.DATA48,
13
- DataType.DATA56,
14
- DataType.DATA64,
15
- DataType.BOOLEAN,
16
- DataType.BITMAP8,
17
- DataType.BITMAP16,
18
- DataType.BITMAP24,
19
- DataType.BITMAP32,
20
- DataType.BITMAP40,
21
- DataType.BITMAP48,
22
- DataType.BITMAP56,
23
- DataType.BITMAP64,
24
- DataType.ENUM8,
25
- DataType.ENUM16,
26
- DataType.OCTET_STR,
27
- DataType.CHAR_STR,
28
- DataType.LONG_OCTET_STR,
29
- DataType.LONG_CHAR_STR,
30
- DataType.ARRAY,
31
- DataType.STRUCT,
32
- DataType.SET,
33
- DataType.BAG,
34
- DataType.CLUSTER_ID,
35
- DataType.ATTR_ID,
36
- DataType.BAC_OID,
37
- DataType.IEEE_ADDR,
38
- DataType.SEC_KEY,
39
- ];
40
- const DATA_TYPE_CLASS_ANALOG = [
41
- DataType.UINT8,
42
- DataType.UINT16,
43
- DataType.UINT24,
44
- DataType.UINT32,
45
- DataType.UINT40,
46
- DataType.UINT48,
47
- DataType.UINT56,
48
- DataType.INT8,
49
- DataType.INT16,
50
- DataType.INT24,
51
- DataType.INT32,
52
- DataType.INT40,
53
- DataType.INT48,
54
- DataType.INT56,
55
- DataType.SEMI_PREC,
56
- DataType.SINGLE_PREC,
57
- DataType.DOUBLE_PREC,
58
- DataType.TOD,
59
- DataType.DATE,
60
- DataType.UTC,
61
- ];
62
-
63
- const FOUNDATION_DISCOVER_RSP_IDS = [
64
- Foundation.discoverRsp.ID,
65
- Foundation.discoverCommandsRsp.ID,
66
- Foundation.discoverCommandsGenRsp.ID,
67
- Foundation.discoverExtRsp.ID,
68
- ];
69
-
70
- export function getDataTypeClass(dataType: DataType): DataTypeClass {
71
- if (DATA_TYPE_CLASS_DISCRETE.includes(dataType)) {
72
- return DataTypeClass.DISCRETE;
73
- }
74
-
75
- if (DATA_TYPE_CLASS_ANALOG.includes(dataType)) {
76
- return DataTypeClass.ANALOG;
77
- }
78
-
79
- throw new Error(`Don't know value type for '${DataType[dataType]}'`);
80
- }
81
-
82
- function hasCustomClusters(customClusters: CustomClusters): boolean {
83
- // XXX: was there a good reason to not set the parameter `customClusters` optional? it would allow simple undefined check
84
- // below is twice faster than checking `Object.keys(customClusters).length`
85
- for (const _k in customClusters) return true;
86
- return false;
87
- }
88
-
89
- function findClusterNameByID(
90
- id: number,
91
- manufacturerCode: number | undefined,
92
- clusters: CustomClusters,
93
- ): [name: string | undefined, partialMatch: boolean] {
94
- let name: string | undefined;
95
- // if manufacturer code is given, consider partial match if didn't match against manufacturer code
96
- let partialMatch = Boolean(manufacturerCode);
97
-
98
- for (const clusterName in clusters) {
99
- const cluster = clusters[clusterName as ClusterName];
100
-
101
- if (cluster.ID === id) {
102
- // priority on first match when matching only ID
103
- if (name === undefined) {
104
- name = clusterName;
105
- }
106
-
107
- if (manufacturerCode && cluster.manufacturerCode === manufacturerCode) {
108
- name = clusterName;
109
- partialMatch = false;
110
- break;
111
- }
112
-
113
- if (!cluster.manufacturerCode) {
114
- name = clusterName;
115
- break;
116
- }
117
- }
118
- }
119
-
120
- return [name, partialMatch];
121
- }
122
-
123
- function getClusterDefinition(
124
- key: string | number,
125
- manufacturerCode: number | undefined,
126
- customClusters: CustomClusters,
127
- ): {name: string; cluster: ClusterDefinition} {
128
- let name: string | undefined;
129
-
130
- if (typeof key === "number") {
131
- let partialMatch: boolean;
132
-
133
- // custom clusters have priority over Zcl clusters, except in case of better match (see below)
134
- [name, partialMatch] = findClusterNameByID(key, manufacturerCode, customClusters);
135
-
136
- if (!name) {
137
- [name, partialMatch] = findClusterNameByID(key, manufacturerCode, Clusters);
138
- } else if (partialMatch) {
139
- let zclName: string | undefined;
140
- [zclName, partialMatch] = findClusterNameByID(key, manufacturerCode, Clusters);
141
-
142
- // Zcl clusters contain a better match, use that one
143
- if (zclName !== undefined && !partialMatch) {
144
- name = zclName;
145
- }
146
- }
147
- } else {
148
- name = key;
149
- }
150
-
151
- let cluster =
152
- name !== undefined && hasCustomClusters(customClusters)
153
- ? {
154
- ...Clusters[name as ClusterName],
155
- ...customClusters[name], // should override Zcl clusters
156
- }
157
- : Clusters[name as ClusterName];
158
-
159
- if (!cluster || cluster.ID === undefined) {
160
- if (typeof key === "number") {
161
- name = key.toString();
162
- cluster = {attributes: {}, commands: {}, commandsResponse: {}, manufacturerCode: undefined, ID: key};
163
- } else {
164
- name = undefined;
165
- }
166
- }
167
-
168
- if (!name) {
169
- throw new Error(`Cluster with name '${key}' does not exist`);
170
- }
171
-
172
- return {name, cluster};
173
- }
174
-
175
- function cloneClusterEntriesWithName<T extends Record<string, unknown>>(entries: Record<string, T>): Record<string, {name: string} & T> {
176
- const clone: Record<string, {name: string} & T> = {};
177
-
178
- for (const key in entries) {
179
- clone[key] = {...entries[key], name: key};
180
- }
181
-
182
- return clone;
183
- }
184
-
185
- function createCluster(name: string, cluster: ClusterDefinition, manufacturerCode?: number): Cluster {
186
- const attributes: Record<string, Attribute> = cloneClusterEntriesWithName(cluster.attributes);
187
- const commands: Record<string, Command> = cloneClusterEntriesWithName(cluster.commands);
188
- const commandsResponse: Record<string, Command> = cloneClusterEntriesWithName(cluster.commandsResponse);
189
-
190
- const getAttribute = (key: number | string): Attribute | undefined => {
191
- if (typeof key === "number") {
192
- let partialMatchAttr: Attribute | undefined;
193
-
194
- for (const attrKey in attributes) {
195
- const attr = attributes[attrKey];
196
-
197
- if (attr.ID === key) {
198
- if (manufacturerCode && attr.manufacturerCode === manufacturerCode) {
199
- return attr;
200
- }
201
-
202
- if (attr.manufacturerCode === undefined) {
203
- partialMatchAttr = attr;
204
- }
205
- }
206
- }
207
-
208
- return partialMatchAttr;
209
- }
210
-
211
- return attributes[key];
212
- };
213
-
214
- const getCommand = (key: number | string): Command => {
215
- if (typeof key === "number") {
216
- for (const cmdKey in commands) {
217
- const cmd = commands[cmdKey];
218
-
219
- if (cmd.ID === key) {
220
- return cmd;
221
- }
222
- }
223
- } else {
224
- const cmd = commands[key];
225
-
226
- if (cmd) {
227
- return cmd;
228
- }
229
- }
230
-
231
- throw new Error(`Cluster '${name}' has no command '${key}'`);
232
- };
233
-
234
- const getCommandResponse = (key: number | string): Command => {
235
- if (typeof key === "number") {
236
- for (const cmdKey in commandsResponse) {
237
- const cmd = commandsResponse[cmdKey];
238
-
239
- if (cmd.ID === key) {
240
- return cmd;
241
- }
242
- }
243
- } else {
244
- const cmd = commandsResponse[key];
245
-
246
- if (cmd) {
247
- return cmd;
248
- }
249
- }
250
-
251
- throw new Error(`Cluster '${name}' has no command response '${key}'`);
252
- };
253
-
254
- return {
255
- ID: cluster.ID,
256
- attributes,
257
- manufacturerCode: cluster.manufacturerCode,
258
- name,
259
- commands,
260
- commandsResponse,
261
- getAttribute,
262
- getCommand,
263
- getCommandResponse,
264
- };
265
- }
266
-
267
- export function getCluster(key: string | number, manufacturerCode: number | undefined = undefined, customClusters: CustomClusters = {}): Cluster {
268
- const {name, cluster} = getClusterDefinition(key, manufacturerCode, customClusters);
269
- return createCluster(name, cluster, manufacturerCode);
270
- }
271
-
272
- function getGlobalCommandNameById(id: number): FoundationCommandName {
273
- for (const commandName in Foundation) {
274
- if (Foundation[commandName as FoundationCommandName].ID === id) {
275
- return commandName as FoundationCommandName;
276
- }
277
- }
278
-
279
- throw new Error(`Global command with id '${id}' does not exist.`);
280
- }
281
-
282
- export function getGlobalCommand(key: number | string): Command {
283
- const name = typeof key === "number" ? getGlobalCommandNameById(key) : (key as FoundationCommandName);
284
- const command = Foundation[name];
285
-
286
- if (!command) {
287
- throw new Error(`Global command with key '${key}' does not exist`);
288
- }
289
-
290
- const result: Command = {
291
- ID: command.ID,
292
- name,
293
- parameters: command.parameters,
294
- };
295
-
296
- if (command.response !== undefined) {
297
- result.response = command.response;
298
- }
299
-
300
- return result;
301
- }
302
-
303
- export function isClusterName(name: string): name is ClusterName {
304
- return name in Clusters;
305
- }
306
-
307
- export function getFoundationCommand(id: number): FoundationDefinition {
308
- for (const commandName in Foundation) {
309
- const command = Foundation[commandName as FoundationCommandName];
310
-
311
- if (command.ID === id) {
312
- return command;
313
- }
314
- }
315
-
316
- throw new Error(`Foundation command '${id}' does not exist.`);
317
- }
318
-
319
- export function isFoundationDiscoverRsp(id: number): boolean {
320
- return FOUNDATION_DISCOVER_RSP_IDS.includes(id);
321
- }
@@ -1,356 +0,0 @@
1
- import "../../utils/patchBigIntSerialization";
2
-
3
- import {BuffaloZcl} from "./buffaloZcl";
4
- import {BuffaloZclDataType, DataType, Direction, FrameType, ParameterCondition} from "./definition/enums";
5
- import type {FoundationCommandName} from "./definition/foundation";
6
- import type {BuffaloZclOptions, Cluster, ClusterName, Command, CustomClusters, ParameterDefinition} from "./definition/tstype";
7
- import * as Utils from "./utils";
8
- import {ZclHeader} from "./zclHeader";
9
-
10
- // biome-ignore lint/suspicious/noExplicitAny: API
11
- type ZclPayload = any;
12
-
13
- const ListTypes: number[] = [
14
- BuffaloZclDataType.LIST_UINT8,
15
- BuffaloZclDataType.LIST_UINT16,
16
- BuffaloZclDataType.LIST_UINT24,
17
- BuffaloZclDataType.LIST_UINT32,
18
- BuffaloZclDataType.LIST_ZONEINFO,
19
- ];
20
-
21
- export class ZclFrame {
22
- public readonly header: ZclHeader;
23
- public readonly payload: ZclPayload;
24
- public readonly cluster: Cluster;
25
- public readonly command: Command;
26
-
27
- private constructor(header: ZclHeader, payload: ZclPayload, cluster: Cluster, command: Command) {
28
- this.header = header;
29
- this.payload = payload;
30
- this.cluster = cluster;
31
- this.command = command;
32
- }
33
-
34
- public toString(): string {
35
- return JSON.stringify({header: this.header, payload: this.payload, command: this.command});
36
- }
37
-
38
- /**
39
- * Creating
40
- */
41
- public static create(
42
- frameType: FrameType,
43
- direction: Direction,
44
- disableDefaultResponse: boolean,
45
- manufacturerCode: number | undefined,
46
- transactionSequenceNumber: number,
47
- commandKey: number | string | Command,
48
- clusterKey: number | string | Cluster,
49
- payload: ZclPayload,
50
- customClusters: CustomClusters,
51
- reservedBits = 0,
52
- ): ZclFrame {
53
- const cluster = typeof clusterKey === "object" ? clusterKey : Utils.getCluster(clusterKey, manufacturerCode, customClusters);
54
- const command: Command =
55
- typeof commandKey === "object"
56
- ? commandKey
57
- : frameType === FrameType.GLOBAL
58
- ? Utils.getGlobalCommand(commandKey)
59
- : direction === Direction.CLIENT_TO_SERVER
60
- ? cluster.getCommand(commandKey)
61
- : cluster.getCommandResponse(commandKey);
62
-
63
- const header = new ZclHeader(
64
- {reservedBits, frameType, direction, disableDefaultResponse, manufacturerSpecific: manufacturerCode != null},
65
- manufacturerCode,
66
- transactionSequenceNumber,
67
- command.ID,
68
- );
69
-
70
- return new ZclFrame(header, payload, cluster, command);
71
- }
72
-
73
- public toBuffer(): Buffer {
74
- const buffalo = new BuffaloZcl(Buffer.alloc(250));
75
- this.header.write(buffalo);
76
-
77
- if (this.header.isGlobal) {
78
- this.writePayloadGlobal(buffalo);
79
- } else if (this.header.isSpecific) {
80
- this.writePayloadCluster(buffalo);
81
- } else {
82
- throw new Error(`Frametype '${this.header.frameControl.frameType}' not valid`);
83
- }
84
-
85
- return buffalo.getWritten();
86
- }
87
-
88
- private writePayloadGlobal(buffalo: BuffaloZcl): void {
89
- const command = Utils.getFoundationCommand(this.command.ID);
90
-
91
- if (command.parseStrategy === "repetitive") {
92
- for (const entry of this.payload) {
93
- for (const parameter of command.parameters) {
94
- const options: BuffaloZclOptions = {};
95
-
96
- if (!ZclFrame.conditionsValid(parameter, entry, undefined)) {
97
- continue;
98
- }
99
-
100
- if (parameter.type === BuffaloZclDataType.USE_DATA_TYPE && typeof entry.dataType === "number") {
101
- // We need to grab the dataType to parse useDataType
102
- options.dataType = entry.dataType;
103
- }
104
-
105
- buffalo.write(parameter.type, entry[parameter.name], options);
106
- }
107
- }
108
- } else if (command.parseStrategy === "flat") {
109
- for (const parameter of command.parameters) {
110
- buffalo.write(parameter.type, this.payload[parameter.name], {});
111
- }
112
- } else {
113
- if (command.parseStrategy === "oneof") {
114
- if (Utils.isFoundationDiscoverRsp(command.ID)) {
115
- buffalo.writeUInt8(this.payload.discComplete);
116
-
117
- for (const entry of this.payload.attrInfos) {
118
- for (const parameter of command.parameters) {
119
- buffalo.write(parameter.type, entry[parameter.name], {});
120
- }
121
- }
122
- }
123
- }
124
- }
125
- }
126
-
127
- private writePayloadCluster(buffalo: BuffaloZcl): void {
128
- for (const parameter of this.command.parameters) {
129
- if (!ZclFrame.conditionsValid(parameter, this.payload, undefined)) {
130
- continue;
131
- }
132
-
133
- // TODO: biome migration - safer
134
- if (this.payload[parameter.name] == null) {
135
- throw new Error(`Parameter '${parameter.name}' is missing`);
136
- }
137
-
138
- buffalo.write(parameter.type, this.payload[parameter.name], {});
139
- }
140
- }
141
-
142
- /**
143
- * Parsing
144
- */
145
- public static fromBuffer(clusterID: number, header: ZclHeader | undefined, buffer: Buffer, customClusters: CustomClusters): ZclFrame {
146
- if (!header) {
147
- throw new Error("Invalid ZclHeader.");
148
- }
149
-
150
- const buffalo = new BuffaloZcl(buffer, header.length);
151
- const cluster = Utils.getCluster(clusterID, header.manufacturerCode, customClusters);
152
- const command: Command = header.isGlobal
153
- ? Utils.getGlobalCommand(header.commandIdentifier)
154
- : header.frameControl.direction === Direction.CLIENT_TO_SERVER
155
- ? cluster.getCommand(header.commandIdentifier)
156
- : cluster.getCommandResponse(header.commandIdentifier);
157
- const payload = ZclFrame.parsePayload(header, cluster, buffalo);
158
-
159
- return new ZclFrame(header, payload, cluster, command);
160
- }
161
-
162
- private static parsePayload(header: ZclHeader, cluster: Cluster, buffalo: BuffaloZcl): ZclPayload {
163
- if (header.isGlobal) {
164
- return ZclFrame.parsePayloadGlobal(header, buffalo);
165
- }
166
-
167
- if (header.isSpecific) {
168
- return ZclFrame.parsePayloadCluster(header, cluster, buffalo);
169
- }
170
-
171
- throw new Error(`Unsupported frameType '${header.frameControl.frameType}'`);
172
- }
173
-
174
- private static parsePayloadCluster(header: ZclHeader, cluster: Cluster, buffalo: BuffaloZcl): ZclPayload {
175
- const command =
176
- header.frameControl.direction === Direction.CLIENT_TO_SERVER
177
- ? cluster.getCommand(header.commandIdentifier)
178
- : cluster.getCommandResponse(header.commandIdentifier);
179
- const payload: ZclPayload = {};
180
-
181
- for (const parameter of command.parameters) {
182
- const options: BuffaloZclOptions = {payload};
183
-
184
- if (!ZclFrame.conditionsValid(parameter, payload, buffalo.getBuffer().length - buffalo.getPosition())) {
185
- continue;
186
- }
187
-
188
- if (ListTypes.includes(parameter.type)) {
189
- const lengthParameter = command.parameters[command.parameters.indexOf(parameter) - 1];
190
- const length = payload[lengthParameter.name];
191
-
192
- if (typeof length === "number") {
193
- options.length = length;
194
- }
195
- }
196
-
197
- try {
198
- payload[parameter.name] = buffalo.read(parameter.type, options);
199
- } catch (error) {
200
- throw new Error(`Cannot parse '${command.name}:${parameter.name}' (${(error as Error).message})`);
201
- }
202
- }
203
-
204
- return payload;
205
- }
206
-
207
- private static parsePayloadGlobal(header: ZclHeader, buffalo: BuffaloZcl): ZclPayload {
208
- const command = Utils.getFoundationCommand(header.commandIdentifier);
209
-
210
- if (command.parseStrategy === "repetitive") {
211
- const payload = [];
212
-
213
- while (buffalo.isMore()) {
214
- // biome-ignore lint/suspicious/noExplicitAny: API
215
- const entry: {[s: string]: any} = {};
216
-
217
- for (const parameter of command.parameters) {
218
- const options: BuffaloZclOptions = {};
219
-
220
- if (!ZclFrame.conditionsValid(parameter, entry, buffalo.getBuffer().length - buffalo.getPosition())) {
221
- continue;
222
- }
223
-
224
- if (parameter.type === BuffaloZclDataType.USE_DATA_TYPE && typeof entry.dataType === "number") {
225
- // We need to grab the dataType to parse useDataType
226
- options.dataType = entry.dataType;
227
-
228
- if (entry.dataType === DataType.CHAR_STR && entry.attrId === 65281) {
229
- // [workaround] parse char str as Xiaomi struct
230
- options.dataType = BuffaloZclDataType.MI_STRUCT;
231
- }
232
- }
233
-
234
- entry[parameter.name] = buffalo.read(parameter.type, options);
235
-
236
- // TODO: not needed, but temp workaroudn to make payload equal to that of zcl-packet
237
- // XXX: is this still needed?
238
- if (parameter.type === BuffaloZclDataType.USE_DATA_TYPE && entry.dataType === DataType.STRUCT) {
239
- entry.structElms = entry.attrData;
240
- entry.numElms = entry.attrData.length;
241
- }
242
- }
243
-
244
- payload.push(entry);
245
- }
246
-
247
- return payload;
248
- }
249
-
250
- if (command.parseStrategy === "flat") {
251
- // biome-ignore lint/suspicious/noExplicitAny: API
252
- const payload: {[s: string]: any} = {};
253
-
254
- for (const parameter of command.parameters) {
255
- payload[parameter.name] = buffalo.read(parameter.type, {});
256
- }
257
-
258
- return payload;
259
- }
260
-
261
- if (command.parseStrategy === "oneof") {
262
- if (Utils.isFoundationDiscoverRsp(command.ID)) {
263
- // biome-ignore lint/suspicious/noExplicitAny: API
264
- const payload: {discComplete: number; attrInfos: {[k: string]: any}[]} = {
265
- discComplete: buffalo.readUInt8(),
266
- attrInfos: [],
267
- };
268
-
269
- while (buffalo.isMore()) {
270
- const entry: (typeof payload.attrInfos)[number] = {};
271
-
272
- for (const parameter of command.parameters) {
273
- entry[parameter.name] = buffalo.read(parameter.type, {});
274
- }
275
-
276
- payload.attrInfos.push(entry);
277
- }
278
-
279
- return payload;
280
- }
281
- }
282
- }
283
-
284
- /**
285
- * Utils
286
- */
287
-
288
- public static conditionsValid(parameter: ParameterDefinition, entry: ZclPayload, remainingBufferBytes: number | undefined): boolean {
289
- if (parameter.conditions) {
290
- for (const condition of parameter.conditions) {
291
- switch (condition.type) {
292
- case ParameterCondition.FIELD_EQUAL: {
293
- if (condition.reversed) {
294
- if (entry[condition.field] === condition.value) {
295
- return false;
296
- }
297
- } else if (entry[condition.field] !== condition.value) {
298
- return false;
299
- }
300
- break;
301
- }
302
- case ParameterCondition.BITMASK_SET: {
303
- if (condition.reversed) {
304
- if ((entry[condition.param] & condition.mask) === condition.mask) {
305
- return false;
306
- }
307
- } else if ((entry[condition.param] & condition.mask) !== condition.mask) {
308
- return false;
309
- }
310
- break;
311
- }
312
- case ParameterCondition.BITFIELD_ENUM: {
313
- if (((entry[condition.param] >> condition.offset) & ((1 << condition.size) - 1)) !== condition.value) {
314
- return false;
315
- }
316
- break;
317
- }
318
- case ParameterCondition.MINIMUM_REMAINING_BUFFER_BYTES: {
319
- if (remainingBufferBytes !== undefined && remainingBufferBytes < condition.value) {
320
- return false;
321
- }
322
- break;
323
- }
324
- case ParameterCondition.DATA_TYPE_CLASS_EQUAL: {
325
- if (Utils.getDataTypeClass(entry.dataType) !== condition.value) {
326
- return false;
327
- }
328
- break;
329
- }
330
- case ParameterCondition.FIELD_GT: {
331
- /*if (condition.reversed) {
332
- if (entry[condition.field] >= condition.value) {
333
- return false;
334
- }
335
- } else */
336
- if (entry[condition.field] <= condition.value) {
337
- return false;
338
- }
339
- break;
340
- }
341
- }
342
- }
343
- }
344
-
345
- return true;
346
- }
347
-
348
- public isCluster(clusterName: FoundationCommandName | ClusterName): boolean {
349
- return this.cluster.name === clusterName;
350
- }
351
-
352
- // List of commands is not completed, feel free to add more.
353
- public isCommand(commandName: FoundationCommandName | "remove" | "add" | "write" | "enrollReq" | "checkin" | "getAlarm" | "arm"): boolean {
354
- return this.command.name === commandName;
355
- }
356
- }