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,457 +0,0 @@
1
- import assert from "node:assert";
2
-
3
- import {NvItemsIds, type NvSystemIds, ZnpCommandStatus} from "../constants/common";
4
- import type * as Structs from "../structs";
5
- import type {BuiltTable} from "../structs";
6
- import {Subsystem} from "../unpi/constants";
7
- import type {Znp} from "../znp";
8
-
9
- /**
10
- * Adapter non-volatile memory instrumentation. This class provides interface to interact
11
- * with ZNP adapter's NV memory. Provided functionality covers basic operations from reading,
12
- * writing and deleting keys to extended table manipulation.
13
- */
14
- export class AdapterNvMemory {
15
- public memoryAlignment?: Structs.StructMemoryAlignment;
16
-
17
- private znp: Znp;
18
-
19
- public constructor(znp: Znp) {
20
- this.znp = znp;
21
- }
22
-
23
- /**
24
- * Initialize NV memory driver by examining target and determining memory alignment.
25
- */
26
- public async init(): Promise<void> {
27
- /* use `ZCD_NV_NWKKEY` to determine if target platform uses memory alignment (length 21 = unaligned, length 24 = aligned) */
28
- const rawNwkKey = await this.readItem(NvItemsIds.NWKKEY);
29
- this.memoryAlignment = rawNwkKey.length === 21 ? "unaligned" : "aligned";
30
- }
31
-
32
- /**
33
- * Reads a variable-length item from NV memory and returns buffer object. Read can be offset as required.
34
- *
35
- * @param id NV item identifier.
36
- * @param offset Desired data offset to read from.
37
- */
38
- public async readItem(id: NvItemsIds, offset?: number): Promise<Buffer>;
39
-
40
- /**
41
- * Reads a variable-length item from NV memory and creates a builds a requested struct.
42
- *
43
- * @param id NV item identifier.
44
- * @param offset Desired data offset to read from.
45
- * @param useStruct Struct factory to use to wrap the data in.
46
- */
47
- public async readItem<R extends Structs.BuiltStruct, T extends R | Structs.BuiltTable<R>>(
48
- id: NvItemsIds,
49
- offset?: number,
50
- useStruct?: Structs.MemoryObjectFactory<T>,
51
- ): Promise<T>;
52
-
53
- public async readItem<R extends Structs.BuiltStruct, T extends R | Structs.BuiltTable<R>>(
54
- id: NvItemsIds,
55
- offset = 0,
56
- useStruct?: Structs.MemoryObjectFactory<T>,
57
- ): Promise<Buffer | T | null> {
58
- if (useStruct) {
59
- this.checkMemoryAlignmentSetup();
60
- }
61
- const lengthResponse = await this.retry(() => this.znp.requestWithReply(Subsystem.SYS, "osalNvLength", {id}));
62
- if (!lengthResponse?.payload?.length || lengthResponse?.payload?.length === 0) {
63
- return null;
64
- }
65
- const length = lengthResponse.payload.length;
66
- const buffer = Buffer.alloc(length);
67
- while (offset < length) {
68
- const readResponse = await this.retry(() => this.znp.request(Subsystem.SYS, "osalNvReadExt", {id, offset}));
69
- /* v8 ignore start */
70
- if (!readResponse) {
71
- return null;
72
- }
73
- if (readResponse.payload?.status !== 0) {
74
- throw new Error(`Received non-success status while reading NV (id=${id}, offset=${offset}, status=${readResponse.payload.status})`);
75
- }
76
- /* v8 ignore stop */
77
- buffer.set(readResponse.payload.value, offset);
78
- offset += readResponse.payload.value.length;
79
- }
80
- if (useStruct) {
81
- return useStruct(buffer, this.memoryAlignment) as T;
82
- }
83
- return buffer;
84
- }
85
-
86
- /**
87
- * Writes data to adapter NV memory. Method fails if write fails.
88
- *
89
- * @param id NV item identifier.
90
- * @param data Data to be written.
91
- * @param offset Offset within NV item to write the data.
92
- * @param autoInit Whether NV item should be automatically initialized if not present.
93
- */
94
-
95
- public async writeItem(id: NvItemsIds, data: Buffer | Structs.SerializableMemoryObject, offset = 0, autoInit = true): Promise<void> {
96
- this.checkMemoryAlignmentSetup();
97
- const buffer = Buffer.isBuffer(data) ? data : data.serialize(this.memoryAlignment);
98
- const lengthResponse = await this.retry(() => this.znp.requestWithReply(Subsystem.SYS, "osalNvLength", {id}));
99
- const exists = lengthResponse.payload.length && lengthResponse.payload.length > 0;
100
- if (!exists) {
101
- /* v8 ignore next */
102
- const initLength = buffer.length > 240 ? 240 : buffer.length;
103
- /* v8 ignore start */
104
- if (!autoInit) {
105
- throw new Error(`Cannot write NV memory item which does not exist (id=${id})`);
106
- }
107
- /* v8 ignore stop */
108
- const initResponse = await this.retry(() =>
109
- this.znp.requestWithReply(
110
- Subsystem.SYS,
111
- "osalNvItemInit",
112
- {id, len: buffer.length, initlen: initLength, initvalue: buffer.slice(0, initLength)},
113
- undefined,
114
- undefined,
115
- [ZnpCommandStatus.SUCCESS, ZnpCommandStatus.NV_ITEM_INITIALIZED],
116
- ),
117
- );
118
- /* v8 ignore start */
119
- if (initResponse.payload.status !== 0x09) {
120
- throw new Error(
121
- `Failed to initialize NV memory item (id=${id}, name=${NvItemsIds[id]}, len=${buffer.length}, status=${initResponse.payload.status})`,
122
- );
123
- }
124
- /* v8 ignore stop */
125
- }
126
- let remaining = buffer.length;
127
- while (remaining > 0) {
128
- /* v8 ignore next */
129
- const writeLength = remaining > 240 ? 240 : remaining;
130
- const dataOffset = buffer.length - remaining;
131
- const writeData = buffer.slice(dataOffset, dataOffset + writeLength);
132
- const writeResponse = await this.retry(() =>
133
- this.znp.requestWithReply(Subsystem.SYS, "osalNvWriteExt", {id, offset: dataOffset, len: writeLength, value: writeData}),
134
- );
135
- /* v8 ignore start */
136
- if (writeResponse.payload.status !== 0) {
137
- throw new Error(`Received non-success status while writing NV (id=${id}, offset=${offset}, status=${writeResponse.payload.status})`);
138
- }
139
- /* v8 ignore stop */
140
- remaining -= writeLength;
141
- }
142
- }
143
-
144
- /**
145
- * Determines whether NV item is different from provided data and updates if necessary.
146
- *
147
- * @param id NV item identifier.
148
- * @param data Desired NV item value.
149
- * @param autoInit Whether NV item should be automatically initialized if not present.
150
- */
151
- public async updateItem(id: NvItemsIds, data: Buffer, autoInit = true): Promise<void> {
152
- this.checkMemoryAlignmentSetup();
153
- const current = await this.readItem(id);
154
- if (!current || !current.equals(data)) {
155
- await this.writeItem(id, data, 0, autoInit);
156
- }
157
- }
158
-
159
- /**
160
- * Deletes an NV memory item.
161
- *
162
- * @param id NV item identifier.
163
- */
164
- public async deleteItem(id: NvItemsIds): Promise<void> {
165
- this.checkMemoryAlignmentSetup();
166
- const lengthResponse = await this.retry(() => this.znp.requestWithReply(Subsystem.SYS, "osalNvLength", {id}));
167
- const exists = lengthResponse.payload.length && lengthResponse.payload.length > 0;
168
-
169
- if (exists) {
170
- const deleteResponse = await this.retry(() =>
171
- this.znp.requestWithReply(Subsystem.SYS, "osalNvDelete", {id, len: lengthResponse.payload.length}),
172
- );
173
- /* v8 ignore start */
174
- if (!deleteResponse || ![ZnpCommandStatus.SUCCESS, ZnpCommandStatus.NV_ITEM_INITIALIZED].includes(deleteResponse.payload.status)) {
175
- throw new Error(`Received non-success status while deleting NV (id=${id}, status=${deleteResponse.payload.status})`);
176
- }
177
- /* v8 ignore stop */
178
- }
179
- }
180
-
181
- /**
182
- * Reads extended table entry (used by Z-Stack 3.x+). NV tables within newer Z-Stack releases include 16-bit `subId`
183
- * identifying table entries.
184
- *
185
- * @param sysId SimpleLink system identifier.
186
- * @param id NV item identifier.
187
- * @param subId Entry index.
188
- * @param offset Data offset to read from.
189
- */
190
- public async readExtendedTableEntry(sysId: NvSystemIds, id: NvItemsIds, subId: number, offset?: number): Promise<Buffer>;
191
- public async readExtendedTableEntry<T extends Structs.BuiltStruct>(
192
- sysId: NvSystemIds,
193
- id: NvItemsIds,
194
- subId: number,
195
- offset?: number,
196
- useStruct?: Structs.MemoryObjectFactory<T>,
197
- ): Promise<T>;
198
- public async readExtendedTableEntry<T extends Structs.BuiltStruct>(
199
- sysId: NvSystemIds,
200
- id: NvItemsIds,
201
- subId: number,
202
- offset?: number,
203
- useStruct?: Structs.MemoryObjectFactory<T>,
204
- ): Promise<Buffer | T | null> {
205
- this.checkMemoryAlignmentSetup();
206
- const lengthResponse = await this.retry(() => this.znp.requestWithReply(Subsystem.SYS, "nvLength", {sysid: sysId, itemid: id, subid: subId}));
207
- const exists = lengthResponse.payload.len && lengthResponse.payload.len > 0;
208
- if (exists) {
209
- const readResponse = await this.retry(() =>
210
- this.znp.requestWithReply(Subsystem.SYS, "nvRead", {
211
- sysid: sysId,
212
- itemid: id,
213
- subid: subId,
214
- offset: offset || 0,
215
- len: lengthResponse.payload.len,
216
- }),
217
- );
218
- /* v8 ignore start */
219
- if (readResponse.payload.status !== 0) {
220
- throw new Error(
221
- `Received non-success status while reading NV extended table entry (sysId=${sysId}, id=${id}, subId=${subId}, offset=${offset}, status=${readResponse.payload.status})`,
222
- );
223
- }
224
- /* v8 ignore stop */
225
- /* v8 ignore next */
226
- return useStruct ? useStruct(readResponse.payload.value) : readResponse.payload.value;
227
- }
228
- return null;
229
- }
230
-
231
- /**
232
- * Writes extended table entry (user by Z-Stack 3.x+). NV tables within newer Z-Stack releases include 16-bit `subId`
233
- * identifying table tnreis.
234
- *
235
- * @param sysId SimpleLink system identifier.
236
- * @param id NV item identifier.
237
- * @param subId Entry index.
238
- * @param data Data to write to the table.
239
- * @param offset Offset to write at.
240
- * @param autoInit Whether non-existent entry should be automatically initialized.
241
- */
242
- public async writeExtendedTableEntry(
243
- sysId: NvSystemIds,
244
- id: NvItemsIds,
245
- subId: number,
246
- data: Buffer,
247
- offset?: number,
248
- autoInit = true,
249
- ): Promise<void> {
250
- this.checkMemoryAlignmentSetup();
251
- const lengthResponse = await this.retry(() => this.znp.requestWithReply(Subsystem.SYS, "nvLength", {sysid: sysId, itemid: id, subid: subId}));
252
- const exists = lengthResponse.payload.len && lengthResponse.payload.len > 0;
253
- /* v8 ignore start */
254
- if (!exists) {
255
- if (!autoInit) {
256
- throw new Error(`Cannot write NV memory extended table item which does not exist (sudId=${sysId}, id=${id}, subId=${subId})`);
257
- }
258
- const createResponse = await this.retry(() =>
259
- this.znp.request(Subsystem.SYS, "nvCreate", {sysid: sysId, itemid: id, subid: subId, len: data.length}),
260
- );
261
- if (!createResponse || createResponse.payload.status !== ZnpCommandStatus.SUCCESS) {
262
- throw new Error(`Failed to crate NV memory extended table item with status (sudId=${sysId}, id=${id}, subId=${subId})`);
263
- }
264
- }
265
- /* v8 ignore stop */
266
- const writeResponse = await this.retry(() =>
267
- this.znp.requestWithReply(Subsystem.SYS, "nvWrite", {
268
- sysid: sysId,
269
- itemid: id,
270
- subid: subId,
271
- offset: offset || 0,
272
- len: data.length,
273
- value: data,
274
- }),
275
- );
276
- /* v8 ignore start */
277
- if (writeResponse.payload.status !== 0) {
278
- throw new Error(
279
- `Received non-success status while writing NV extended table idem (sudId=${sysId}, id=${id}, subId=${subId}, offset=${offset}, status=${writeResponse.payload.status})`,
280
- );
281
- }
282
- /* v8 ignore stop */
283
- }
284
-
285
- /**
286
- * Reads a legacy NV table at defined index into raw `Buffer` object array. Providing maximum
287
- * length is necessary in order to prevent invalid memory access.
288
- *
289
- * @param mode Only legacy mode is supported with this signature.
290
- * @param id The item index at which the table starts.
291
- * @param maxLength Maximum number of items the table may contain.
292
- */
293
- public async readTable(mode: "legacy", id: NvItemsIds, maxLength: number): Promise<Buffer[]>;
294
-
295
- /**
296
- * Reads a legacy table at defined index into a table structure covering struct entries.
297
- * Providing maximum length is necessary in order to prevent invalid memory access.
298
- *
299
- * @param mode Only legacy mode is supported with this signature.
300
- * @param id The item index at which the table starts.
301
- * @param maxLength Maximum number of items the table may contain.
302
- * @param useTable Table factory to spawn a table and populate with retrieved data.
303
- */
304
- public async readTable<R extends Structs.BuiltStruct, T extends Structs.BuiltTable<R>>(
305
- mode: "legacy",
306
- id: NvItemsIds,
307
- maxLength: number,
308
- useTable?: Structs.MemoryObjectFactory<T>,
309
- ): Promise<T>;
310
-
311
- /**
312
- * Reads an extended (Z-Stack 3.x.0+) table into raw `Buffer` object array.
313
- * Maximum length is optional since the table boundary can be detected automatically.
314
- *
315
- * @param mode Only extended mode is supported with this signature.
316
- * @param sysId SimpleLink system identifier.
317
- * @param id Extended table NV index.
318
- * @param maxLength Maximum number of entries to load from the table.
319
- */
320
- public async readTable(mode: "extended", sysId: NvSystemIds, id: NvItemsIds, maxLength?: number): Promise<Buffer[]>;
321
-
322
- /**
323
- * Reads an extended (Z-Stack 3.x.0+) table into a table structure covering struct entries.
324
- * Maximum length is optional since the table boundary can be detected automatically.
325
- *
326
- * @param mode Only extended mode is supported with this signature.
327
- * @param sysId SimpleLink system identifier.
328
- * @param id Extended table NV index.
329
- * @param maxLength Maximum number of entries to load from the table.
330
- * @param useTable Table factory to spawn a table and populate with retrieved data.
331
- */
332
- public async readTable<R extends Structs.BuiltStruct, T extends Structs.BuiltTable<R>>(
333
- mode: "extended",
334
- sysId: NvSystemIds,
335
- id: NvItemsIds,
336
- maxLength?: number,
337
- useTable?: Structs.MemoryObjectFactory<T>,
338
- ): Promise<T>;
339
-
340
- public async readTable<R extends Structs.BuiltStruct, T extends Structs.BuiltTable<R>>(
341
- mode: "legacy" | "extended",
342
- p1: NvSystemIds | NvItemsIds,
343
- p2: NvItemsIds | number,
344
- p3?: Structs.MemoryObjectFactory<T> | number,
345
- p4?: Structs.MemoryObjectFactory<T>,
346
- ): Promise<Buffer[] | T> {
347
- const sysId = mode === "legacy" ? undefined : (p1 as NvSystemIds);
348
- const id = (mode === "legacy" ? p1 : p2) as NvItemsIds;
349
- const maxLength = (mode === "legacy" ? p2 : p3) as number;
350
- const useTable = (mode === "legacy" ? p3 : p4) as Structs.MemoryObjectFactory<T>;
351
-
352
- const rawEntries: Buffer[] = [];
353
- let entryOffset = 0;
354
- let rawEntry = null;
355
- if (mode === "legacy") {
356
- do {
357
- rawEntry = await this.readItem(id + entryOffset++);
358
- if (rawEntry) {
359
- rawEntries.push(rawEntry);
360
- }
361
- } while (rawEntry !== null && entryOffset < maxLength);
362
- } else {
363
- do {
364
- assert(sysId !== undefined);
365
- rawEntry = await this.readExtendedTableEntry(sysId, id, entryOffset++);
366
- if (rawEntry) {
367
- rawEntries.push(rawEntry);
368
- }
369
- /* v8 ignore next */
370
- } while (rawEntry !== null && (!maxLength || entryOffset < maxLength));
371
- }
372
-
373
- /* v8 ignore next */
374
- return useTable ? useTable(rawEntries) : rawEntries;
375
- }
376
-
377
- /**
378
- * Writes a struct-based table structure into a legacy NV memory position.
379
- *
380
- * @param mode Only legacy mode is supported with this signature.
381
- * @param id Start NV item index.
382
- * @param table Table structure to write to NV memory.
383
- */
384
- public async writeTable<R extends Structs.BuiltStruct>(mode: "legacy", id: NvItemsIds, table: BuiltTable<R>): Promise<void>;
385
-
386
- /**
387
- * Writes a struct-based table structure into an extended NV memory position.
388
- *
389
- * @param mode Only extended mode is supported with this signature.
390
- * @param sysId SimpleLink system identifier.
391
- * @param id Extended table NV item index.
392
- * @param table Table structure to write to NV memory.
393
- */
394
- public async writeTable<R extends Structs.BuiltStruct>(mode: "extended", sysId: NvSystemIds, id: NvItemsIds, table: BuiltTable<R>): Promise<void>;
395
-
396
- public async writeTable<R extends Structs.BuiltStruct>(
397
- mode: "extended" | "legacy",
398
- p1: NvSystemIds | NvItemsIds,
399
- p2: NvItemsIds | BuiltTable<R>,
400
- p3?: BuiltTable<R>,
401
- ): Promise<void> {
402
- this.checkMemoryAlignmentSetup();
403
- const sysId = mode === "legacy" ? undefined : (p1 as NvSystemIds);
404
- const id = (mode === "legacy" ? p1 : p2) as NvItemsIds;
405
- const table = (mode === "legacy" ? p2 : p3) as BuiltTable<R>;
406
-
407
- if (mode === "legacy") {
408
- for (const [index, entry] of table.entries.entries()) {
409
- await this.writeItem(id + index, entry.serialize(this.memoryAlignment));
410
- }
411
- } else {
412
- assert(sysId !== undefined);
413
- for (const [index, entry] of table.entries.entries()) {
414
- await this.writeExtendedTableEntry(sysId, id, index, entry.serialize(this.memoryAlignment));
415
- }
416
- }
417
- }
418
-
419
- /**
420
- * Internal function to prevent occasional ZNP request failures.
421
- *
422
- * *Some timeouts were present when working with SimpleLink Z-Stack 3.x.0+.*
423
- *
424
- * @param fn Function to retry.
425
- * @param retries Maximum number of retries.
426
- */
427
- // @ts-expect-error always returns something or throws an error as retries >= 1
428
- private async retry<R>(fn: () => Promise<R>, retries = 3): Promise<R> {
429
- assert(retries >= 1);
430
- let i = 0;
431
- while (i < retries) {
432
- try {
433
- const result = await fn();
434
- return result;
435
- /* v8 ignore start */
436
- } catch (error) {
437
- if (i >= retries) {
438
- throw error;
439
- }
440
- }
441
-
442
- i++;
443
- }
444
- /* v8 ignore stop */
445
- }
446
-
447
- /**
448
- * Internal function used by NV manipulation methods to check for correct driver initialization.
449
- */
450
- private checkMemoryAlignmentSetup(): void {
451
- /* v8 ignore start */
452
- if (this.memoryAlignment === undefined) {
453
- throw new Error("adapter memory alignment unknown - has nv memory driver been initialized?");
454
- }
455
- /* v8 ignore stop */
456
- }
457
- }
@@ -1,57 +0,0 @@
1
- import {Clusters} from "../../../zspec/zcl/definition/cluster";
2
- import * as Constants from "../constants";
3
-
4
- const EndpointDefaults: {
5
- appdeviceid: number;
6
- appdevver: number;
7
- appnuminclusters: number;
8
- appinclusterlist: number[];
9
- appnumoutclusters: number;
10
- appoutclusterlist: number[];
11
- latencyreq: number;
12
- } = {
13
- appdeviceid: 0x0005,
14
- appdevver: 0,
15
- appnuminclusters: 0,
16
- appinclusterlist: [],
17
- appnumoutclusters: 0,
18
- appoutclusterlist: [],
19
- latencyreq: Constants.AF.networkLatencyReq.NO_LATENCY_REQS,
20
- };
21
-
22
- export const Endpoints = [
23
- {...EndpointDefaults, endpoint: 1, appprofid: 0x0104},
24
- {...EndpointDefaults, endpoint: 2, appprofid: 0x0101},
25
- // Required for https://github.com/Koenkk/zigbee-herdsman-converters/commit/d0fb06c2429171f327950484ea3dec80864637cc
26
- {...EndpointDefaults, endpoint: 3, appprofid: 0x0104},
27
- {...EndpointDefaults, endpoint: 4, appprofid: 0x0107},
28
- {...EndpointDefaults, endpoint: 5, appprofid: 0x0108},
29
- {...EndpointDefaults, endpoint: 6, appprofid: 0x0109},
30
- {...EndpointDefaults, endpoint: 8, appprofid: 0x0104},
31
- {...EndpointDefaults, endpoint: 10, appprofid: 0x0104},
32
- {
33
- ...EndpointDefaults,
34
- endpoint: 11,
35
- appprofid: 0x0104,
36
- appdeviceid: 0x0400,
37
- appnumoutclusters: 2,
38
- appoutclusterlist: [Clusters.ssIasZone.ID, Clusters.ssIasWd.ID],
39
- appnuminclusters: 2,
40
- // genTime required for https://github.com/Koenkk/zigbee2mqtt/issues/10816
41
- appinclusterlist: [Clusters.ssIasAce.ID, Clusters.genTime.ID],
42
- },
43
- // TERNCY: https://github.com/Koenkk/zigbee-herdsman/issues/82
44
- {...EndpointDefaults, endpoint: 0x6e, appprofid: 0x0104},
45
- {...EndpointDefaults, endpoint: 12, appprofid: 0xc05e},
46
- {
47
- ...EndpointDefaults,
48
- endpoint: 13,
49
- appprofid: 0x0104,
50
- appnuminclusters: 1,
51
- appinclusterlist: [Clusters.genOta.ID],
52
- },
53
- // Insta/Jung/Gira: OTA fallback EP (since it's buggy in firmware 10023202 when it tries to find a matching EP for
54
- // OTA - it queries for ZLL profile, but then contacts with HA profile)
55
- {...EndpointDefaults, endpoint: 47, appprofid: 0x0104},
56
- {...EndpointDefaults, endpoint: 242, appprofid: 0xa1e0},
57
- ];