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,1220 +0,0 @@
1
- import {Buffalo} from "../../buffalo";
2
- import {logger} from "../../utils/logger";
3
- import {isNumberArray} from "../../utils/utils";
4
- import {BuffaloZclDataType, DataType, StructuredIndicatorType} from "./definition/enums";
5
- import type {
6
- BuffaloZclOptions,
7
- ExtensionFieldSet,
8
- Gpd,
9
- GpdAttributeReport,
10
- GpdChannelConfiguration,
11
- GpdChannelRequest,
12
- GpdCommissioningReply,
13
- GpdCustomReply,
14
- KeyZclValue,
15
- MiboxerZone,
16
- Struct,
17
- StructuredSelector,
18
- ThermoTransition,
19
- TuyaDataPointValue,
20
- ZclArray,
21
- ZclDate,
22
- ZclTimeOfDay,
23
- ZoneInfo,
24
- } from "./definition/tstype";
25
- import * as Utils from "./utils";
26
-
27
- const NS = "zh:zcl:buffalo";
28
-
29
- const SEC_KEY_LENGTH = 16;
30
-
31
- const EXTENSION_FIELD_SETS_DATA_TYPE: {[key: number]: DataType[]} = {
32
- 6: [DataType.UINT8],
33
- 8: [DataType.UINT8],
34
- 258: [DataType.UINT8, DataType.UINT8],
35
- 768: [DataType.UINT16, DataType.UINT16, DataType.UINT16, DataType.UINT8, DataType.UINT8, DataType.UINT8, DataType.UINT16, DataType.UINT16],
36
- };
37
-
38
- export class BuffaloZcl extends Buffalo {
39
- // TODO: shuffles quite a lot of code (ZH is mostly typed `string | number` and ZHC requires lots of scrutiny)
40
- // private writeZclBoolean(value: boolean | undefined): void {
41
- // this.writeUInt8(value === undefined ? 0xff : value ? 1 : 0);
42
- // }
43
-
44
- // private readZclBoolean(): boolean | undefined {
45
- // const value = this.readUInt8();
46
-
47
- // return value === 0xff ? undefined : !!value;
48
- // }
49
-
50
- private writeZclUInt8(value: number): void {
51
- this.writeUInt8(Number.isNaN(value) ? 0xff : value);
52
- }
53
-
54
- private readZclUInt8(): number {
55
- const value = this.readUInt8();
56
-
57
- return value === 0xff ? Number.NaN : value;
58
- }
59
-
60
- private writeZclUInt16(value: number): void {
61
- this.writeUInt16(Number.isNaN(value) ? 0xffff : value);
62
- }
63
-
64
- private readZclUInt16(): number {
65
- const value = this.readUInt16();
66
-
67
- return value === 0xffff ? Number.NaN : value;
68
- }
69
-
70
- private writeZclUInt24(value: number): void {
71
- this.writeUInt24(Number.isNaN(value) ? 0xffffff : value);
72
- }
73
-
74
- private readZclUInt24(): number {
75
- const value = this.readUInt24();
76
-
77
- return value === 0xffffff ? Number.NaN : value;
78
- }
79
-
80
- private writeZclUInt32(value: number): void {
81
- this.writeUInt32(Number.isNaN(value) ? 0xffffffff : value);
82
- }
83
-
84
- private readZclUInt32(): number {
85
- const value = this.readUInt32();
86
-
87
- return value === 0xffffffff ? Number.NaN : value;
88
- }
89
-
90
- private writeZclUInt40(value: number): void {
91
- this.writeUInt40(Number.isNaN(value) ? 0xffffffffff : value);
92
- }
93
-
94
- private readZclUInt40(): number {
95
- const value = this.readUInt40();
96
-
97
- return value === 0xffffffffff ? Number.NaN : value;
98
- }
99
-
100
- private writeZclUInt48(value: number): void {
101
- this.writeUInt48(Number.isNaN(value) ? 0xffffffffffff : value);
102
- }
103
-
104
- private readZclUInt48(): number {
105
- const value = this.readUInt48();
106
-
107
- return value === 0xffffffffffff ? Number.NaN : value;
108
- }
109
-
110
- private writeZclUInt56(value: bigint | undefined): void {
111
- this.writeUInt56(value === undefined ? 0xffffffffffffffn : value);
112
- }
113
-
114
- private readZclUInt56(): bigint | undefined {
115
- const value = this.readUInt56();
116
-
117
- return value === 0xffffffffffffffn ? undefined : value;
118
- }
119
-
120
- private writeZclUInt64(value: bigint | undefined): void {
121
- this.writeUInt64(value === undefined ? 0xffffffffffffffffn : value);
122
- }
123
-
124
- private readZclUInt64(): bigint | undefined {
125
- const value = this.readUInt64();
126
-
127
- return value === 0xffffffffffffffffn ? undefined : value;
128
- }
129
-
130
- private writeZclInt8(value: number): void {
131
- this.writeInt8(Number.isNaN(value) ? -0x80 : value);
132
- }
133
-
134
- private readZclInt8(): number {
135
- const value = this.readInt8();
136
-
137
- return value === -0x80 ? Number.NaN : value;
138
- }
139
-
140
- private writeZclInt16(value: number): void {
141
- this.writeInt16(Number.isNaN(value) ? -0x8000 : value);
142
- }
143
-
144
- private readZclInt16(): number {
145
- const value = this.readInt16();
146
-
147
- return value === -0x8000 ? Number.NaN : value;
148
- }
149
-
150
- private writeZclInt24(value: number): void {
151
- this.writeInt24(Number.isNaN(value) ? -0x800000 : value);
152
- }
153
-
154
- private readZclInt24(): number {
155
- const value = this.readInt24();
156
-
157
- return value === -0x800000 ? Number.NaN : value;
158
- }
159
-
160
- private writeZclInt32(value: number): void {
161
- this.writeInt32(Number.isNaN(value) ? -0x80000000 : value);
162
- }
163
-
164
- private readZclInt32(): number {
165
- const value = this.readInt32();
166
-
167
- return value === -0x80000000 ? Number.NaN : value;
168
- }
169
-
170
- private writeZclInt40(value: number): void {
171
- this.writeInt40(Number.isNaN(value) ? -0x8000000000 : value);
172
- }
173
-
174
- private readZclInt40(): number {
175
- const value = this.readInt40();
176
-
177
- return value === -0x8000000000 ? Number.NaN : value;
178
- }
179
-
180
- private writeZclInt48(value: number): void {
181
- this.writeInt48(Number.isNaN(value) ? -0x800000000000 : value);
182
- }
183
-
184
- private readZclInt48(): number {
185
- const value = this.readInt48();
186
-
187
- return value === -0x800000000000 ? Number.NaN : value;
188
- }
189
-
190
- private writeZclInt56(value: bigint | undefined): void {
191
- this.writeInt56(value === undefined ? -0x80000000000000n : value);
192
- }
193
-
194
- private readZclInt56(): bigint | undefined {
195
- const value = this.readInt56();
196
-
197
- return value === -0x80000000000000n ? undefined : value;
198
- }
199
-
200
- private writeZclInt64(value: bigint | undefined): void {
201
- this.writeInt64(value === undefined ? -0x8000000000000000n : value);
202
- }
203
-
204
- private readZclInt64(): bigint | undefined {
205
- const value = this.readInt64();
206
-
207
- return value === -0x8000000000000000n ? undefined : value;
208
- }
209
-
210
- private writeOctetStr(value?: number[]): void {
211
- if (value) {
212
- this.writeUInt8(value.length);
213
- this.writeBuffer(value, value.length);
214
- } else {
215
- this.writeUInt8(0xff); // non-value
216
- }
217
- }
218
-
219
- private readOctetStr(): Buffer {
220
- const length = this.readZclUInt8();
221
- return Number.isNaN(length) ? Buffer.from([]) : this.readBuffer(length);
222
- }
223
-
224
- private writeCharStr(value?: string | number[]): void {
225
- if (value) {
226
- if (typeof value === "string") {
227
- this.writeUInt8(Buffer.byteLength(value, "utf8"));
228
- this.writeUtf8String(value);
229
- } else {
230
- // XXX: value.length not written?
231
- this.writeBuffer(value, value.length);
232
- }
233
- } else {
234
- this.writeUInt8(0xff); // non-value
235
- }
236
- }
237
-
238
- private readCharStr(): string {
239
- const length = this.readZclUInt8();
240
-
241
- return Number.isNaN(length) ? "" : this.readUtf8String(length);
242
- }
243
-
244
- private writeLongOctetStr(value?: number[]): void {
245
- if (value) {
246
- this.writeUInt16(value.length);
247
- this.writeBuffer(value, value.length);
248
- } else {
249
- this.writeUInt16(0xffff); // non-value
250
- }
251
- }
252
-
253
- private readLongOctetStr(): Buffer {
254
- const length = this.readZclUInt16();
255
- return Number.isNaN(length) ? Buffer.from([]) : this.readBuffer(length);
256
- }
257
-
258
- private writeLongCharStr(value?: string): void {
259
- if (value) {
260
- this.writeUInt16(Buffer.byteLength(value, "utf8"));
261
- this.writeUtf8String(value);
262
- } else {
263
- this.writeUInt16(0xffff); // non-value
264
- }
265
- }
266
-
267
- private readLongCharStr(): string {
268
- const length = this.readZclUInt16();
269
- return Number.isNaN(length) ? "" : this.readUtf8String(length);
270
- }
271
-
272
- private writeArray(value?: ZclArray): void {
273
- if (value) {
274
- const elTypeNumeric = typeof value.elementType === "number" ? value.elementType : DataType[value.elementType];
275
- this.writeUInt8(elTypeNumeric);
276
- this.writeUInt16(value.elements.length);
277
-
278
- for (const element of value.elements) {
279
- this.write(elTypeNumeric, element, {});
280
- }
281
- } else {
282
- this.writeUInt8(DataType.NO_DATA); // XXX: correct value?
283
- this.writeUInt16(0xffff); // non-value
284
- }
285
- }
286
-
287
- private readArray(): unknown[] {
288
- const values: unknown[] = [];
289
-
290
- const elementType = this.readUInt8();
291
- const numberOfElements = this.readZclUInt16();
292
-
293
- if (!Number.isNaN(numberOfElements)) {
294
- // not non-value
295
- for (let i = 0; i < numberOfElements; i++) {
296
- const value = this.read(elementType, {});
297
- values.push(value);
298
- }
299
- }
300
-
301
- return values;
302
- }
303
-
304
- private writeStruct(value?: Struct[]): void {
305
- if (value) {
306
- this.writeUInt16(value.length);
307
-
308
- for (const v of value) {
309
- this.writeUInt8(v.elmType);
310
- this.write(v.elmType, v.elmVal, {});
311
- }
312
- } else {
313
- this.writeUInt16(0xffff); // non-value
314
- }
315
- }
316
-
317
- private readStruct(): Struct[] {
318
- const values: Struct[] = [];
319
- const numberOfElements = this.readZclUInt16();
320
-
321
- if (!Number.isNaN(numberOfElements)) {
322
- // not non-value
323
- for (let i = 0; i < numberOfElements; i++) {
324
- const elementType = this.readUInt8();
325
- const value = this.read(elementType, {});
326
- values.push({elmType: elementType, elmVal: value});
327
- }
328
- }
329
-
330
- return values;
331
- }
332
-
333
- private writeToD(value: ZclTimeOfDay): void {
334
- this.writeUInt8(value.hours == null || Number.isNaN(value.hours) ? 0xff : value.hours);
335
- this.writeUInt8(value.minutes == null || Number.isNaN(value.minutes) ? 0xff : value.minutes);
336
- this.writeUInt8(value.seconds == null || Number.isNaN(value.seconds) ? 0xff : value.seconds);
337
- this.writeUInt8(value.hundredths == null || Number.isNaN(value.hundredths) ? 0xff : value.hundredths);
338
- }
339
-
340
- private readToD(): ZclTimeOfDay {
341
- const hours = this.readZclUInt8();
342
- const minutes = this.readZclUInt8();
343
- const seconds = this.readZclUInt8();
344
- const hundredths = this.readZclUInt8();
345
-
346
- return {
347
- hours,
348
- minutes,
349
- seconds,
350
- hundredths,
351
- };
352
- }
353
-
354
- private writeDate(value: ZclDate): void {
355
- this.writeUInt8(value.year == null || Number.isNaN(value.year) ? 0xff : value.year - 1900);
356
- this.writeUInt8(value.month == null || Number.isNaN(value.month) ? 0xff : value.month);
357
- this.writeUInt8(value.dayOfMonth == null || Number.isNaN(value.dayOfMonth) ? 0xff : value.dayOfMonth);
358
- this.writeUInt8(value.dayOfWeek == null || Number.isNaN(value.dayOfWeek) ? 0xff : value.dayOfWeek);
359
- }
360
-
361
- private readDate(): ZclDate {
362
- const year = this.readZclUInt8();
363
- const month = this.readZclUInt8();
364
- const dayOfMonth = this.readZclUInt8();
365
- const dayOfWeek = this.readZclUInt8();
366
-
367
- return {
368
- year: year + 1900, // remains NaN if year is NaN
369
- month,
370
- dayOfMonth,
371
- dayOfWeek,
372
- };
373
- }
374
-
375
- //--- BuffaloZclDataType
376
-
377
- private writeListZoneInfo(values: ZoneInfo[]): void {
378
- for (const value of values) {
379
- this.writeUInt8(value.zoneID);
380
- this.writeUInt16(value.zoneStatus);
381
- }
382
- }
383
-
384
- private readListZoneInfo(length: number): ZoneInfo[] {
385
- const value: ZoneInfo[] = [];
386
- for (let i = 0; i < length; i++) {
387
- value.push({
388
- zoneID: this.readUInt8(),
389
- zoneStatus: this.readUInt16(),
390
- });
391
- }
392
-
393
- return value;
394
- }
395
-
396
- private writeExtensionFieldSets(values: {clstId: number; len: number; extField: number[]}[]): void {
397
- for (const value of values) {
398
- this.writeUInt16(value.clstId);
399
- this.writeUInt8(value.len);
400
- let index = 0;
401
-
402
- for (const entry of value.extField) {
403
- this.write(EXTENSION_FIELD_SETS_DATA_TYPE[value.clstId][index], entry, {});
404
- index++;
405
- }
406
- }
407
- }
408
-
409
- private readExtensionFieldSets(): ExtensionFieldSet[] {
410
- const value: ExtensionFieldSet[] = [];
411
-
412
- // XXX: doesn't work if buffer has more unrelated fields after this one
413
- while (this.isMore()) {
414
- const clstId = this.readUInt16();
415
- const len = this.readUInt8();
416
- const end = this.getPosition() + len;
417
- let index = 0;
418
- const extField: unknown[] = [];
419
-
420
- while (this.getPosition() < end) {
421
- extField.push(this.read(EXTENSION_FIELD_SETS_DATA_TYPE[clstId][index], {}));
422
- index++;
423
- }
424
-
425
- value.push({extField, clstId, len});
426
- }
427
-
428
- return value;
429
- }
430
-
431
- private writeListThermoTransitions(value: ThermoTransition[]): void {
432
- for (const entry of value) {
433
- this.writeUInt16(entry.transitionTime);
434
-
435
- if (entry.heatSetpoint != null) {
436
- this.writeUInt16(entry.heatSetpoint);
437
- }
438
-
439
- if (entry.coolSetpoint != null) {
440
- this.writeUInt16(entry.coolSetpoint);
441
- }
442
- }
443
- }
444
-
445
- private readListThermoTransitions(options: BuffaloZclOptions): ThermoTransition[] {
446
- if (options.payload == null || options.payload.mode == null || options.payload.numoftrans == null) {
447
- throw new Error("Cannot read LIST_THERMO_TRANSITIONS without required payload options specified");
448
- }
449
-
450
- const heat = options.payload.mode & 1;
451
- const cool = options.payload.mode & 2;
452
- const result: ThermoTransition[] = [];
453
-
454
- for (let i = 0; i < options.payload.numoftrans; i++) {
455
- const entry: ThermoTransition = {
456
- transitionTime: this.readUInt16(),
457
- };
458
-
459
- if (heat) {
460
- entry.heatSetpoint = this.readUInt16();
461
- }
462
-
463
- if (cool) {
464
- entry.coolSetpoint = this.readUInt16();
465
- }
466
-
467
- result.push(entry);
468
- }
469
-
470
- return result;
471
- }
472
-
473
- private writeGpdFrame(value: GpdCommissioningReply | GpdChannelConfiguration | GpdCustomReply): void {
474
- if (value.commandID === 0xf0) {
475
- // Commissioning Reply
476
- const v = value as GpdCommissioningReply;
477
-
478
- const panIDPresent = Boolean(v.options & 0x1);
479
- const gpdSecurityKeyPresent = Boolean(v.options & 0x2);
480
- const gpdKeyEncryption = Boolean((v.options >> 2) & 0x1);
481
- const securityLevel = (v.options >> 3) & 0x3;
482
- const hasGPDKeyMIC = gpdKeyEncryption && gpdSecurityKeyPresent;
483
- const hasFrameCounter = gpdSecurityKeyPresent && gpdKeyEncryption && (securityLevel === 0b10 || securityLevel === 0b11);
484
-
485
- this.writeUInt8(1 + (panIDPresent ? 2 : 0) + (gpdSecurityKeyPresent ? 16 : 0) + (hasGPDKeyMIC ? 4 : 0) + (hasFrameCounter ? 4 : 0)); // Length
486
- this.writeUInt8(v.options);
487
-
488
- if (panIDPresent) {
489
- // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
490
- this.writeUInt16(v.panID!);
491
- }
492
-
493
- if (gpdSecurityKeyPresent) {
494
- // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
495
- this.writeBuffer(v.securityKey!, 16);
496
- }
497
-
498
- if (hasGPDKeyMIC) {
499
- // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
500
- this.writeUInt32(v.keyMic!);
501
- }
502
-
503
- if (hasFrameCounter) {
504
- // biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
505
- this.writeUInt32(v.frameCounter!);
506
- }
507
- } else if (value.commandID === 0xf3) {
508
- // Channel configuration
509
- const v = value as GpdChannelConfiguration;
510
-
511
- this.writeUInt8(1);
512
- this.writeUInt8((v.operationalChannel & 0xf) | ((v.basic ? 1 : 0) << 4));
513
- } else if (value.commandID === 0xf4 || value.commandID === 0xf5 || (value.commandID >= 0xf7 && value.commandID <= 0xff)) {
514
- // Other commands sent to GPD
515
- const v = value as GpdCustomReply;
516
-
517
- this.writeUInt8(v.buffer.length);
518
- this.writeBuffer(v.buffer, v.buffer.length);
519
- }
520
- // 0xf1: Write Attributes
521
- // 0xf2: Read Attributes
522
- // 0xf6: ZCL Tunneling
523
- }
524
-
525
- private readGpdFrame(options: BuffaloZclOptions): Gpd | GpdChannelRequest | GpdAttributeReport | {raw: Buffer} | Record<string, never> {
526
- if (options.payload?.payloadSize === undefined) {
527
- throw new Error("Cannot read GPD_FRAME without required payload options specified");
528
- }
529
-
530
- if (Number.isNaN(options.payload.payloadSize) || options.payload.payloadSize === 0) {
531
- return {}; // non-value, don't move position
532
- }
533
-
534
- // ensure offset by options.payload.payloadSize (if any) at end of parsing to not cause issues with spec changes (until supported)
535
- const startPosition = this.position;
536
-
537
- if (options.payload.commandID === 0xe0) {
538
- // Commisioning
539
- const frame = {
540
- deviceID: this.readUInt8(),
541
- options: this.readUInt8(),
542
- extendedOptions: 0,
543
- securityKey: Buffer.alloc(16),
544
- keyMic: 0,
545
- outgoingCounter: 0,
546
- applicationInfo: 0,
547
- manufacturerID: 0,
548
- modelID: 0,
549
- numGpdCommands: 0,
550
- gpdCommandIdList: Buffer.alloc(0),
551
- numServerClusters: 0,
552
- numClientClusters: 0,
553
- gpdServerClusters: Buffer.alloc(0),
554
- gpdClientClusters: Buffer.alloc(0),
555
- genericSwitchConfig: 0,
556
- currentContactStatus: 0,
557
- };
558
-
559
- if (frame.options & 0x80) {
560
- frame.extendedOptions = this.readUInt8();
561
- }
562
-
563
- if (frame.extendedOptions & 0x20) {
564
- frame.securityKey = this.readBuffer(16);
565
- }
566
-
567
- if (frame.extendedOptions & 0x40) {
568
- frame.keyMic = this.readUInt32();
569
- }
570
-
571
- if (frame.extendedOptions & 0x80) {
572
- frame.outgoingCounter = this.readUInt32();
573
- }
574
-
575
- if (frame.options & 0x04) {
576
- frame.applicationInfo = this.readUInt8();
577
- }
578
-
579
- if (frame.applicationInfo & 0x01) {
580
- frame.manufacturerID = this.readUInt16();
581
- }
582
-
583
- if (frame.applicationInfo & 0x02) {
584
- frame.modelID = this.readUInt16();
585
- }
586
-
587
- if (frame.applicationInfo & 0x04) {
588
- frame.numGpdCommands = this.readUInt8();
589
- frame.gpdCommandIdList = this.readBuffer(frame.numGpdCommands);
590
- }
591
-
592
- if (frame.applicationInfo & 0x08) {
593
- const len = this.readUInt8();
594
- frame.numServerClusters = len & 0xf;
595
- frame.numClientClusters = (len >> 4) & 0xf;
596
-
597
- frame.gpdServerClusters = this.readBuffer(2 * frame.numServerClusters);
598
- frame.gpdClientClusters = this.readBuffer(2 * frame.numClientClusters);
599
- }
600
-
601
- if (frame.applicationInfo & 0x10) {
602
- const len = this.readUInt8();
603
-
604
- if (len >= 1) {
605
- frame.genericSwitchConfig = this.readUInt8();
606
- }
607
-
608
- if (len >= 2) {
609
- frame.currentContactStatus = this.readUInt8();
610
- }
611
- }
612
-
613
- this.setPosition(startPosition + options.payload.payloadSize);
614
-
615
- return frame;
616
- }
617
-
618
- if (options.payload.commandID === 0xe3) {
619
- // Channel Request
620
- const channelOpts = this.readUInt8();
621
-
622
- this.setPosition(startPosition + options.payload.payloadSize);
623
-
624
- return {
625
- nextChannel: channelOpts & 0xf,
626
- nextNextChannel: channelOpts >> 4,
627
- };
628
- }
629
-
630
- if (options.payload.commandID === 0xa1) {
631
- // Manufacturer-specific Attribute Reporting
632
- const start = this.position;
633
- const frame = {
634
- manufacturerCode: this.readUInt16(),
635
- clusterID: this.readUInt16(),
636
- attributes: {} as KeyZclValue,
637
- };
638
-
639
- const cluster = Utils.getCluster(frame.clusterID, frame.manufacturerCode, {});
640
-
641
- while (this.position - start < options.payload.payloadSize) {
642
- const attributeID = this.readUInt16();
643
- const type = this.readUInt8();
644
- /* v8 ignore next */
645
- let attribute: string | undefined | number = cluster.getAttribute(attributeID)?.name;
646
-
647
- // number type is only used when going into this if
648
- if (!attribute) {
649
- // this is spammy because of the many manufacturer-specific attributes not currently used
650
- logger.debug(`Unknown attribute ${attributeID} in cluster ${cluster.name}`, NS);
651
-
652
- attribute = attributeID;
653
- }
654
-
655
- frame.attributes[attribute] = this.read(type, options);
656
- }
657
-
658
- this.setPosition(startPosition + options.payload.payloadSize);
659
-
660
- return frame;
661
- }
662
-
663
- // might contain `gppNwkAddr`, `gppGpdLink` & `mic` from ZCL cluster after this, so limit by `payloadSize`
664
- return {raw: this.readBuffer(options.payload.payloadSize)};
665
- }
666
-
667
- private writeStructuredSelector(value: StructuredSelector): void {
668
- if (value != null) {
669
- const indexes = value.indexes || [];
670
- const indicatorType = value.indicatorType || StructuredIndicatorType.Whole;
671
- const indicator = indexes.length + indicatorType;
672
-
673
- this.writeUInt8(indicator);
674
-
675
- for (const index of indexes) {
676
- this.writeUInt16(index);
677
- }
678
- }
679
- }
680
-
681
- private readStructuredSelector(): StructuredSelector {
682
- /** [0-15] range */
683
- const indicator = this.readUInt8();
684
-
685
- if (indicator === 0) {
686
- // no indexes, whole attribute value is to be read
687
- return {indicatorType: StructuredIndicatorType.Whole};
688
- }
689
-
690
- if (indicator < StructuredIndicatorType.WriteAdd) {
691
- const indexes: StructuredSelector["indexes"] = [];
692
-
693
- for (let i = 0; i < indicator; i++) {
694
- const index = this.readUInt16();
695
- indexes.push(index);
696
- }
697
-
698
- return {indexes};
699
- }
700
-
701
- throw new Error("Read structured selector was outside [0-15] range.");
702
- }
703
-
704
- private writeListTuyaDataPointValues(dpValues: TuyaDataPointValue[]): void {
705
- for (const dpValue of dpValues) {
706
- this.writeUInt8(dpValue.dp);
707
- this.writeUInt8(dpValue.datatype);
708
- const dataLen = dpValue.data.length;
709
- // UInt16BE
710
- this.writeUInt8((dataLen >> 8) & 0xff);
711
- this.writeUInt8(dataLen & 0xff);
712
- this.writeBuffer(dpValue.data, dataLen);
713
- }
714
- }
715
-
716
- private readListTuyaDataPointValues(): TuyaDataPointValue[] {
717
- const value: TuyaDataPointValue[] = [];
718
-
719
- // XXX: doesn't work if buffer has more unrelated fields after this one
720
- while (this.isMore()) {
721
- try {
722
- const dp = this.readUInt8();
723
- const datatype = this.readUInt8();
724
- const len_hi = this.readUInt8();
725
- const len_lo = this.readUInt8();
726
- const data = this.readBuffer(len_lo + (len_hi << 8));
727
- value.push({dp, datatype, data});
728
- } catch {
729
- break;
730
- }
731
- }
732
-
733
- return value;
734
- }
735
-
736
- private writeListMiboxerZones(values: MiboxerZone[]): void {
737
- this.writeUInt8(values.length);
738
-
739
- for (const value of values) {
740
- this.writeUInt16(value.groupId);
741
- this.writeUInt8(value.zoneNum);
742
- }
743
- }
744
-
745
- private readListMiboxerZones(): MiboxerZone[] {
746
- const value: MiboxerZone[] = [];
747
- const len = this.readUInt8();
748
-
749
- for (let i = 0; i < len; i++) {
750
- const groupId = this.readUInt16();
751
- const zoneNum = this.readUInt8();
752
-
753
- value.push({groupId, zoneNum});
754
- }
755
-
756
- return value;
757
- }
758
-
759
- private writeBigEndianUInt24(value: number): void {
760
- this.buffer.writeUIntBE(value, this.position, 3);
761
- this.position += 3;
762
- }
763
-
764
- private readBigEndianUInt24(): number {
765
- const value = this.buffer.readUIntBE(this.position, 3);
766
- this.position += 3;
767
- return value;
768
- }
769
-
770
- // NOTE: writeMiStruct is not supported.
771
- private readMiStruct(): Record<number, number | number[]> {
772
- const length = this.readUInt8();
773
- const value: Record<number, number | number[]> = {};
774
-
775
- if (length === 0xff) {
776
- return value;
777
- }
778
-
779
- for (let i = 0; i < length; i++) {
780
- const index = this.readUInt8();
781
- const dataType = this.readUInt8();
782
- value[index] = this.read(dataType, {});
783
-
784
- const remaining = this.buffer.length - this.position;
785
- if (remaining <= 1) {
786
- if (remaining === 1) {
787
- // Some Xiaomi structs have a trailing byte, skip it.
788
- this.position += 1;
789
- }
790
- break;
791
- }
792
- }
793
-
794
- return value;
795
- }
796
- // biome-ignore lint/suspicious/noExplicitAny: API
797
- public write(type: DataType | BuffaloZclDataType, value: any, options: BuffaloZclOptions): void {
798
- switch (type) {
799
- case DataType.NO_DATA:
800
- case DataType.UNKNOWN: {
801
- return; // nothing to write
802
- }
803
- case DataType.BOOLEAN:
804
- case DataType.DATA8:
805
- case DataType.BITMAP8:
806
- case DataType.UINT8:
807
- case DataType.ENUM8: {
808
- this.writeZclUInt8(value);
809
- break;
810
- }
811
- case DataType.DATA16:
812
- case DataType.BITMAP16:
813
- case DataType.UINT16:
814
- case DataType.ENUM16:
815
- case DataType.CLUSTER_ID:
816
- case DataType.ATTR_ID: {
817
- this.writeZclUInt16(value);
818
- break;
819
- }
820
- case DataType.DATA24:
821
- case DataType.BITMAP24:
822
- case DataType.UINT24: {
823
- this.writeZclUInt24(value);
824
- break;
825
- }
826
- case DataType.DATA32:
827
- case DataType.BITMAP32:
828
- case DataType.UINT32:
829
- case DataType.UTC:
830
- case DataType.BAC_OID: {
831
- this.writeZclUInt32(value);
832
- break;
833
- }
834
- case DataType.DATA40:
835
- case DataType.BITMAP40:
836
- case DataType.UINT40: {
837
- this.writeZclUInt40(value);
838
- break;
839
- }
840
- case DataType.DATA48:
841
- case DataType.BITMAP48:
842
- case DataType.UINT48: {
843
- this.writeZclUInt48(value);
844
- break;
845
- }
846
- case DataType.DATA56:
847
- case DataType.BITMAP56:
848
- case DataType.UINT56: {
849
- this.writeZclUInt56(value);
850
- break;
851
- }
852
- case DataType.DATA64:
853
- case DataType.BITMAP64:
854
- case DataType.UINT64: {
855
- this.writeZclUInt64(value);
856
- break;
857
- }
858
- case DataType.INT8: {
859
- this.writeZclInt8(value);
860
- break;
861
- }
862
- case DataType.INT16: {
863
- this.writeZclInt16(value);
864
- break;
865
- }
866
- case DataType.INT24: {
867
- this.writeZclInt24(value);
868
- break;
869
- }
870
- case DataType.INT32: {
871
- this.writeZclInt32(value);
872
- break;
873
- }
874
- case DataType.INT40: {
875
- this.writeZclInt40(value);
876
- break;
877
- }
878
- case DataType.INT48: {
879
- this.writeZclInt48(value);
880
- break;
881
- }
882
- case DataType.INT56: {
883
- this.writeZclInt56(value);
884
- break;
885
- }
886
- case DataType.INT64: {
887
- this.writeZclInt64(value);
888
- break;
889
- }
890
- // case DataType.SEMI_PREC: {
891
- // // https://tc39.es/proposal-float16array/
892
- // // not currently used
893
- // this.writeSemiFloatLE(value);
894
- // break;
895
- // }
896
- case DataType.SINGLE_PREC: {
897
- this.writeFloatLE(value);
898
- break;
899
- }
900
- case DataType.DOUBLE_PREC: {
901
- this.writeDoubleLE(value);
902
- break;
903
- }
904
- case DataType.OCTET_STR: {
905
- this.writeOctetStr(value);
906
- break;
907
- }
908
- case DataType.CHAR_STR: {
909
- this.writeCharStr(value);
910
- break;
911
- }
912
- case DataType.LONG_OCTET_STR: {
913
- this.writeLongOctetStr(value);
914
- break;
915
- }
916
- case DataType.LONG_CHAR_STR: {
917
- this.writeLongCharStr(value);
918
- break;
919
- }
920
- case DataType.ARRAY:
921
- case DataType.SET:
922
- case DataType.BAG: {
923
- this.writeArray(value);
924
- break;
925
- }
926
- case DataType.STRUCT: {
927
- this.writeStruct(value);
928
- break;
929
- }
930
- case DataType.TOD: {
931
- this.writeToD(value);
932
- break;
933
- }
934
- case DataType.DATE: {
935
- this.writeDate(value);
936
- break;
937
- }
938
- case DataType.IEEE_ADDR: {
939
- this.writeIeeeAddr(value);
940
- break;
941
- }
942
- case DataType.SEC_KEY: {
943
- this.writeBuffer(value, SEC_KEY_LENGTH);
944
- break;
945
- }
946
- case BuffaloZclDataType.USE_DATA_TYPE: {
947
- if (options.dataType == null) {
948
- if (Buffer.isBuffer(value) || isNumberArray(value)) {
949
- this.writeBuffer(value, value.length);
950
- break;
951
- }
952
-
953
- throw new Error("Cannot write USE_DATA_TYPE without dataType option specified");
954
- }
955
-
956
- this.write(options.dataType, value, options);
957
- break;
958
- }
959
- case BuffaloZclDataType.LIST_UINT8: {
960
- this.writeListUInt8(value);
961
- break;
962
- }
963
- case BuffaloZclDataType.LIST_UINT16: {
964
- this.writeListUInt16(value);
965
- break;
966
- }
967
- case BuffaloZclDataType.LIST_UINT24: {
968
- this.writeListUInt24(value);
969
- break;
970
- }
971
- case BuffaloZclDataType.LIST_UINT32: {
972
- this.writeListUInt32(value);
973
- break;
974
- }
975
- case BuffaloZclDataType.LIST_ZONEINFO: {
976
- this.writeListZoneInfo(value);
977
- break;
978
- }
979
- case BuffaloZclDataType.EXTENSION_FIELD_SETS: {
980
- this.writeExtensionFieldSets(value);
981
- break;
982
- }
983
- case BuffaloZclDataType.LIST_THERMO_TRANSITIONS: {
984
- this.writeListThermoTransitions(value);
985
- break;
986
- }
987
- case BuffaloZclDataType.BUFFER: {
988
- // XXX: inconsistent with read that allows partial with options.length, here always "whole"
989
- this.writeBuffer(value, value.length);
990
- break;
991
- }
992
- case BuffaloZclDataType.GPD_FRAME: {
993
- this.writeGpdFrame(value);
994
- break;
995
- }
996
- case BuffaloZclDataType.STRUCTURED_SELECTOR: {
997
- this.writeStructuredSelector(value);
998
- break;
999
- }
1000
- case BuffaloZclDataType.LIST_TUYA_DATAPOINT_VALUES: {
1001
- this.writeListTuyaDataPointValues(value);
1002
- break;
1003
- }
1004
- case BuffaloZclDataType.LIST_MIBOXER_ZONES: {
1005
- this.writeListMiboxerZones(value);
1006
- break;
1007
- }
1008
- case BuffaloZclDataType.BIG_ENDIAN_UINT24: {
1009
- this.writeBigEndianUInt24(value);
1010
- break;
1011
- }
1012
- default: {
1013
- // In case the type is undefined, write it as a buffer to easily allow for custom types
1014
- // e.g. for https://github.com/Koenkk/zigbee-herdsman/issues/127
1015
- if (Buffer.isBuffer(value) || isNumberArray(value)) {
1016
- this.writeBuffer(value, value.length);
1017
- break;
1018
- }
1019
-
1020
- throw new Error(`Write for '${type}' not available`);
1021
- }
1022
- }
1023
- }
1024
-
1025
- // biome-ignore lint/suspicious/noExplicitAny: API
1026
- public read(type: DataType | BuffaloZclDataType, options: BuffaloZclOptions): any {
1027
- switch (type) {
1028
- case DataType.NO_DATA:
1029
- case DataType.UNKNOWN: {
1030
- return; // nothing to write
1031
- }
1032
- case DataType.BOOLEAN:
1033
- case DataType.DATA8:
1034
- case DataType.BITMAP8:
1035
- case DataType.UINT8:
1036
- case DataType.ENUM8: {
1037
- return this.readZclUInt8();
1038
- }
1039
- case DataType.DATA16:
1040
- case DataType.BITMAP16:
1041
- case DataType.UINT16:
1042
- case DataType.ENUM16:
1043
- case DataType.CLUSTER_ID:
1044
- case DataType.ATTR_ID: {
1045
- return this.readZclUInt16();
1046
- }
1047
- case DataType.DATA24:
1048
- case DataType.BITMAP24:
1049
- case DataType.UINT24: {
1050
- return this.readZclUInt24();
1051
- }
1052
- case DataType.DATA32:
1053
- case DataType.BITMAP32:
1054
- case DataType.UINT32:
1055
- case DataType.UTC:
1056
- case DataType.BAC_OID: {
1057
- return this.readZclUInt32();
1058
- }
1059
- case DataType.DATA40:
1060
- case DataType.BITMAP40:
1061
- case DataType.UINT40: {
1062
- return this.readZclUInt40();
1063
- }
1064
- case DataType.DATA48:
1065
- case DataType.BITMAP48:
1066
- case DataType.UINT48: {
1067
- return this.readZclUInt48();
1068
- }
1069
- case DataType.DATA56:
1070
- case DataType.BITMAP56:
1071
- case DataType.UINT56: {
1072
- return this.readZclUInt56();
1073
- }
1074
- case DataType.DATA64:
1075
- case DataType.BITMAP64:
1076
- case DataType.UINT64: {
1077
- return this.readZclUInt64();
1078
- }
1079
- case DataType.INT8: {
1080
- return this.readZclInt8();
1081
- }
1082
- case DataType.INT16: {
1083
- return this.readZclInt16();
1084
- }
1085
- case DataType.INT24: {
1086
- return this.readZclInt24();
1087
- }
1088
- case DataType.INT32: {
1089
- return this.readZclInt32();
1090
- }
1091
- case DataType.INT40: {
1092
- return this.readZclInt40();
1093
- }
1094
- case DataType.INT48: {
1095
- return this.readZclInt48();
1096
- }
1097
- case DataType.INT56: {
1098
- return this.readZclInt56();
1099
- }
1100
- case DataType.INT64: {
1101
- return this.readZclInt64();
1102
- }
1103
- // case DataType.SEMI_PREC: {
1104
- // // https://tc39.es/proposal-float16array/
1105
- // // not currently used
1106
- // return this.readSemiFloatLE();
1107
- // }
1108
- case DataType.SINGLE_PREC: {
1109
- return this.readFloatLE();
1110
- }
1111
- case DataType.DOUBLE_PREC: {
1112
- return this.readDoubleLE();
1113
- }
1114
- case DataType.OCTET_STR: {
1115
- return this.readOctetStr();
1116
- }
1117
- case DataType.CHAR_STR: {
1118
- return this.readCharStr();
1119
- }
1120
- case DataType.LONG_OCTET_STR: {
1121
- return this.readLongOctetStr();
1122
- }
1123
- case DataType.LONG_CHAR_STR: {
1124
- return this.readLongCharStr();
1125
- }
1126
- case DataType.ARRAY:
1127
- case DataType.SET:
1128
- case DataType.BAG: {
1129
- return this.readArray();
1130
- }
1131
- case DataType.STRUCT: {
1132
- return this.readStruct();
1133
- }
1134
- case DataType.TOD: {
1135
- return this.readToD();
1136
- }
1137
- case DataType.DATE: {
1138
- return this.readDate();
1139
- }
1140
- case DataType.IEEE_ADDR: {
1141
- return this.readIeeeAddr();
1142
- }
1143
- case DataType.SEC_KEY: {
1144
- return this.readBuffer(SEC_KEY_LENGTH);
1145
- }
1146
- case BuffaloZclDataType.USE_DATA_TYPE: {
1147
- if (options.dataType == null) {
1148
- return this.readBuffer(options.length ?? this.buffer.length);
1149
- }
1150
-
1151
- return this.read(options.dataType, options);
1152
- }
1153
- case BuffaloZclDataType.LIST_UINT8: {
1154
- if (options.length == null) {
1155
- throw new Error("Cannot read LIST_UINT8 without length option specified");
1156
- }
1157
-
1158
- return this.readListUInt8(options.length);
1159
- }
1160
- case BuffaloZclDataType.LIST_UINT16: {
1161
- if (options.length == null) {
1162
- throw new Error("Cannot read LIST_UINT16 without length option specified");
1163
- }
1164
-
1165
- return this.readListUInt16(options.length);
1166
- }
1167
- case BuffaloZclDataType.LIST_UINT24: {
1168
- if (options.length == null) {
1169
- throw new Error("Cannot read LIST_UINT24 without length option specified");
1170
- }
1171
-
1172
- return this.readListUInt24(options.length);
1173
- }
1174
- case BuffaloZclDataType.LIST_UINT32: {
1175
- if (options.length == null) {
1176
- throw new Error("Cannot read LIST_UINT32 without length option specified");
1177
- }
1178
-
1179
- return this.readListUInt32(options.length);
1180
- }
1181
- case BuffaloZclDataType.LIST_ZONEINFO: {
1182
- if (options.length == null) {
1183
- throw new Error("Cannot read LIST_ZONEINFO without length option specified");
1184
- }
1185
-
1186
- return this.readListZoneInfo(options.length);
1187
- }
1188
- case BuffaloZclDataType.EXTENSION_FIELD_SETS: {
1189
- return this.readExtensionFieldSets();
1190
- }
1191
- case BuffaloZclDataType.LIST_THERMO_TRANSITIONS: {
1192
- return this.readListThermoTransitions(options);
1193
- }
1194
- case BuffaloZclDataType.BUFFER: {
1195
- // if length option not specified, read the whole buffer
1196
- return this.readBuffer(options.length ?? this.buffer.length);
1197
- }
1198
- case BuffaloZclDataType.GPD_FRAME: {
1199
- return this.readGpdFrame(options);
1200
- }
1201
- case BuffaloZclDataType.STRUCTURED_SELECTOR: {
1202
- return this.readStructuredSelector();
1203
- }
1204
- case BuffaloZclDataType.LIST_TUYA_DATAPOINT_VALUES: {
1205
- return this.readListTuyaDataPointValues();
1206
- }
1207
- case BuffaloZclDataType.LIST_MIBOXER_ZONES: {
1208
- return this.readListMiboxerZones();
1209
- }
1210
- case BuffaloZclDataType.BIG_ENDIAN_UINT24: {
1211
- return this.readBigEndianUInt24();
1212
- }
1213
- case BuffaloZclDataType.MI_STRUCT: {
1214
- return this.readMiStruct();
1215
- }
1216
- }
1217
-
1218
- throw new Error(`Read for '${type}' not available`);
1219
- }
1220
- }