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
@@ -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
- ];