@willieee802/zigbee-herdsman 0.18.2 → 0.19.2

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 (329) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +67 -0
  3. package/dist/adapter/adapter.d.ts +61 -61
  4. package/dist/adapter/adapter.d.ts.map +1 -1
  5. package/dist/adapter/adapter.js +146 -146
  6. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts +68 -68
  7. package/dist/adapter/deconz/adapter/deconzAdapter.js +1060 -1060
  8. package/dist/adapter/deconz/adapter/index.d.ts +2 -2
  9. package/dist/adapter/deconz/adapter/index.js +10 -10
  10. package/dist/adapter/deconz/driver/constants.d.ts +104 -104
  11. package/dist/adapter/deconz/driver/constants.js +55 -55
  12. package/dist/adapter/deconz/driver/driver.d.ts +81 -81
  13. package/dist/adapter/deconz/driver/driver.js +732 -732
  14. package/dist/adapter/deconz/driver/frame.d.ts +6 -6
  15. package/dist/adapter/deconz/driver/frame.js +13 -13
  16. package/dist/adapter/deconz/driver/frameParser.d.ts +2 -2
  17. package/dist/adapter/deconz/driver/frameParser.js +443 -443
  18. package/dist/adapter/deconz/driver/parser.d.ts +12 -12
  19. package/dist/adapter/deconz/driver/parser.js +61 -61
  20. package/dist/adapter/deconz/driver/writer.d.ts +8 -8
  21. package/dist/adapter/deconz/driver/writer.js +44 -44
  22. package/dist/adapter/events.d.ts +47 -47
  23. package/dist/adapter/events.js +14 -14
  24. package/dist/adapter/ezsp/adapter/backup.d.ts +9 -9
  25. package/dist/adapter/ezsp/adapter/backup.js +53 -53
  26. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts +59 -59
  27. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts.map +1 -1
  28. package/dist/adapter/ezsp/adapter/ezspAdapter.js +603 -585
  29. package/dist/adapter/ezsp/adapter/ezspAdapter.js.map +1 -1
  30. package/dist/adapter/ezsp/adapter/index.d.ts +2 -2
  31. package/dist/adapter/ezsp/adapter/index.js +10 -10
  32. package/dist/adapter/ezsp/driver/commands.d.ts +36 -36
  33. package/dist/adapter/ezsp/driver/commands.js +2359 -2359
  34. package/dist/adapter/ezsp/driver/consts.d.ts +10 -10
  35. package/dist/adapter/ezsp/driver/consts.js +13 -13
  36. package/dist/adapter/ezsp/driver/driver.d.ts +103 -103
  37. package/dist/adapter/ezsp/driver/driver.js +639 -639
  38. package/dist/adapter/ezsp/driver/ezsp.d.ts +96 -96
  39. package/dist/adapter/ezsp/driver/ezsp.js +586 -586
  40. package/dist/adapter/ezsp/driver/index.d.ts +3 -3
  41. package/dist/adapter/ezsp/driver/index.js +8 -8
  42. package/dist/adapter/ezsp/driver/multicast.d.ts +12 -12
  43. package/dist/adapter/ezsp/driver/multicast.js +74 -74
  44. package/dist/adapter/ezsp/driver/parser.d.ts +12 -12
  45. package/dist/adapter/ezsp/driver/parser.js +111 -111
  46. package/dist/adapter/ezsp/driver/types/basic.d.ts +62 -62
  47. package/dist/adapter/ezsp/driver/types/basic.js +208 -208
  48. package/dist/adapter/ezsp/driver/types/basic.js.map +1 -1
  49. package/dist/adapter/ezsp/driver/types/index.d.ts +9 -9
  50. package/dist/adapter/ezsp/driver/types/index.js +133 -133
  51. package/dist/adapter/ezsp/driver/types/named.d.ts +697 -697
  52. package/dist/adapter/ezsp/driver/types/named.js +1726 -1726
  53. package/dist/adapter/ezsp/driver/types/named.js.map +1 -1
  54. package/dist/adapter/ezsp/driver/types/struct.d.ts +251 -251
  55. package/dist/adapter/ezsp/driver/types/struct.js +708 -708
  56. package/dist/adapter/ezsp/driver/types/struct.js.map +1 -1
  57. package/dist/adapter/ezsp/driver/uart.d.ts +44 -44
  58. package/dist/adapter/ezsp/driver/uart.js +368 -368
  59. package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts +2 -2
  60. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js +55 -55
  61. package/dist/adapter/ezsp/driver/utils/index.d.ts +18 -18
  62. package/dist/adapter/ezsp/driver/utils/index.js +67 -67
  63. package/dist/adapter/ezsp/driver/writer.d.ts +13 -13
  64. package/dist/adapter/ezsp/driver/writer.js +88 -88
  65. package/dist/adapter/index.d.ts +4 -4
  66. package/dist/adapter/index.js +35 -35
  67. package/dist/adapter/serialPort.d.ts +8 -8
  68. package/dist/adapter/serialPort.js +22 -22
  69. package/dist/adapter/serialPort.js.map +1 -1
  70. package/dist/adapter/serialPortUtils.d.ts +12 -12
  71. package/dist/adapter/serialPortUtils.js +18 -18
  72. package/dist/adapter/socketPortUtils.d.ts +10 -10
  73. package/dist/adapter/socketPortUtils.js +16 -16
  74. package/dist/adapter/tstype.d.ts +85 -85
  75. package/dist/adapter/tstype.js +2 -2
  76. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts +62 -62
  77. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts.map +1 -1
  78. package/dist/adapter/z-stack/adapter/adapter-backup.js +460 -441
  79. package/dist/adapter/z-stack/adapter/adapter-backup.js.map +1 -1
  80. package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts +150 -150
  81. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js +258 -258
  82. package/dist/adapter/z-stack/adapter/endpoints.d.ts +11 -11
  83. package/dist/adapter/z-stack/adapter/endpoints.js +73 -73
  84. package/dist/adapter/z-stack/adapter/index.d.ts +2 -2
  85. package/dist/adapter/z-stack/adapter/index.js +8 -8
  86. package/dist/adapter/z-stack/adapter/manager.d.ts +86 -86
  87. package/dist/adapter/z-stack/adapter/manager.js +476 -476
  88. package/dist/adapter/z-stack/adapter/tstype.d.ts +6 -6
  89. package/dist/adapter/z-stack/adapter/tstype.js +10 -10
  90. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts +81 -81
  91. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts.map +1 -1
  92. package/dist/adapter/z-stack/adapter/zStackAdapter.js +868 -868
  93. package/dist/adapter/z-stack/adapter/zStackAdapter.js.map +1 -1
  94. package/dist/adapter/z-stack/constants/af.d.ts +23 -23
  95. package/dist/adapter/z-stack/constants/af.js +27 -27
  96. package/dist/adapter/z-stack/constants/common.d.ts +278 -278
  97. package/dist/adapter/z-stack/constants/common.js +289 -289
  98. package/dist/adapter/z-stack/constants/dbg.d.ts +22 -22
  99. package/dist/adapter/z-stack/constants/dbg.js +24 -24
  100. package/dist/adapter/z-stack/constants/index.d.ts +10 -10
  101. package/dist/adapter/z-stack/constants/index.js +47 -47
  102. package/dist/adapter/z-stack/constants/mac.d.ts +127 -127
  103. package/dist/adapter/z-stack/constants/mac.js +129 -129
  104. package/dist/adapter/z-stack/constants/sapi.d.ts +24 -24
  105. package/dist/adapter/z-stack/constants/sapi.js +26 -26
  106. package/dist/adapter/z-stack/constants/sys.d.ts +71 -71
  107. package/dist/adapter/z-stack/constants/sys.js +73 -73
  108. package/dist/adapter/z-stack/constants/util.d.ts +81 -81
  109. package/dist/adapter/z-stack/constants/util.js +83 -83
  110. package/dist/adapter/z-stack/constants/utils.d.ts +4 -4
  111. package/dist/adapter/z-stack/constants/utils.js +14 -14
  112. package/dist/adapter/z-stack/constants/zdo.d.ts +102 -102
  113. package/dist/adapter/z-stack/constants/zdo.js +104 -104
  114. package/dist/adapter/z-stack/models/index.d.ts +1 -1
  115. package/dist/adapter/z-stack/models/index.js +17 -17
  116. package/dist/adapter/z-stack/models/startup-options.d.ts +12 -12
  117. package/dist/adapter/z-stack/models/startup-options.js +2 -2
  118. package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts +23 -23
  119. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js +45 -45
  120. package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts +10 -10
  121. package/dist/adapter/z-stack/structs/entries/address-manager-table.js +22 -22
  122. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts +10 -10
  123. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js +21 -21
  124. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts +10 -10
  125. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js +23 -23
  126. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts +10 -10
  127. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js +24 -24
  128. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts +10 -10
  129. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js +23 -23
  130. package/dist/adapter/z-stack/structs/entries/channel-list.d.ts +8 -8
  131. package/dist/adapter/z-stack/structs/entries/channel-list.js +15 -15
  132. package/dist/adapter/z-stack/structs/entries/has-configured.d.ts +8 -8
  133. package/dist/adapter/z-stack/structs/entries/has-configured.js +16 -16
  134. package/dist/adapter/z-stack/structs/entries/index.d.ts +16 -16
  135. package/dist/adapter/z-stack/structs/entries/index.js +32 -32
  136. package/dist/adapter/z-stack/structs/entries/nib.d.ts +10 -10
  137. package/dist/adapter/z-stack/structs/entries/nib.js +68 -68
  138. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts +10 -10
  139. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js +18 -18
  140. package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts +8 -8
  141. package/dist/adapter/z-stack/structs/entries/nwk-key.js +15 -15
  142. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts +8 -8
  143. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js +15 -15
  144. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts +13 -13
  145. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js +23 -23
  146. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts +10 -10
  147. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js +22 -22
  148. package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts +20 -20
  149. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js +36 -36
  150. package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts +10 -10
  151. package/dist/adapter/z-stack/structs/entries/security-manager-table.js +24 -24
  152. package/dist/adapter/z-stack/structs/index.d.ts +4 -4
  153. package/dist/adapter/z-stack/structs/index.js +20 -20
  154. package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts +13 -13
  155. package/dist/adapter/z-stack/structs/serializable-memory-object.js +2 -2
  156. package/dist/adapter/z-stack/structs/struct.d.ts +99 -99
  157. package/dist/adapter/z-stack/structs/struct.js +295 -295
  158. package/dist/adapter/z-stack/structs/table.d.ts +94 -94
  159. package/dist/adapter/z-stack/structs/table.js +161 -161
  160. package/dist/adapter/z-stack/unpi/constants.d.ts +28 -28
  161. package/dist/adapter/z-stack/unpi/constants.js +41 -41
  162. package/dist/adapter/z-stack/unpi/frame.d.ts +16 -16
  163. package/dist/adapter/z-stack/unpi/frame.js +48 -48
  164. package/dist/adapter/z-stack/unpi/index.d.ts +5 -5
  165. package/dist/adapter/z-stack/unpi/index.js +37 -37
  166. package/dist/adapter/z-stack/unpi/parser.d.ts +10 -10
  167. package/dist/adapter/z-stack/unpi/parser.js +74 -74
  168. package/dist/adapter/z-stack/unpi/writer.d.ts +10 -10
  169. package/dist/adapter/z-stack/unpi/writer.js +44 -44
  170. package/dist/adapter/z-stack/utils/channel-list.d.ts +20 -20
  171. package/dist/adapter/z-stack/utils/channel-list.js +40 -40
  172. package/dist/adapter/z-stack/utils/index.d.ts +2 -2
  173. package/dist/adapter/z-stack/utils/index.js +18 -18
  174. package/dist/adapter/z-stack/utils/network-options.d.ts +8 -8
  175. package/dist/adapter/z-stack/utils/network-options.js +22 -22
  176. package/dist/adapter/z-stack/znp/buffaloZnp.d.ts +11 -11
  177. package/dist/adapter/z-stack/znp/buffaloZnp.js +113 -113
  178. package/dist/adapter/z-stack/znp/definition.d.ts +5 -5
  179. package/dist/adapter/z-stack/znp/definition.js +3050 -3050
  180. package/dist/adapter/z-stack/znp/index.d.ts +3 -3
  181. package/dist/adapter/z-stack/znp/index.js +10 -10
  182. package/dist/adapter/z-stack/znp/parameterType.d.ts +22 -22
  183. package/dist/adapter/z-stack/znp/parameterType.js +25 -25
  184. package/dist/adapter/z-stack/znp/tstype.d.ts +21 -21
  185. package/dist/adapter/z-stack/znp/tstype.js +2 -2
  186. package/dist/adapter/z-stack/znp/znp.d.ts +43 -43
  187. package/dist/adapter/z-stack/znp/znp.js +325 -325
  188. package/dist/adapter/z-stack/znp/zpiObject.d.ts +19 -19
  189. package/dist/adapter/z-stack/znp/zpiObject.js +96 -96
  190. package/dist/adapter/zigate/adapter/index.d.ts +2 -2
  191. package/dist/adapter/zigate/adapter/index.js +10 -10
  192. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts +69 -69
  193. package/dist/adapter/zigate/adapter/zigateAdapter.js +678 -678
  194. package/dist/adapter/zigate/debug.d.ts +7 -7
  195. package/dist/adapter/zigate/debug.js +22 -22
  196. package/dist/adapter/zigate/driver/buffaloZiGate.d.ts +18 -18
  197. package/dist/adapter/zigate/driver/buffaloZiGate.js +139 -139
  198. package/dist/adapter/zigate/driver/commandType.d.ts +41 -41
  199. package/dist/adapter/zigate/driver/commandType.js +385 -385
  200. package/dist/adapter/zigate/driver/constants.d.ts +276 -276
  201. package/dist/adapter/zigate/driver/constants.js +371 -371
  202. package/dist/adapter/zigate/driver/frame.d.ts +26 -26
  203. package/dist/adapter/zigate/driver/frame.js +172 -172
  204. package/dist/adapter/zigate/driver/frame.js.map +1 -1
  205. package/dist/adapter/zigate/driver/messageType.d.ts +11 -11
  206. package/dist/adapter/zigate/driver/messageType.js +278 -278
  207. package/dist/adapter/zigate/driver/parameterType.d.ts +20 -20
  208. package/dist/adapter/zigate/driver/parameterType.js +23 -23
  209. package/dist/adapter/zigate/driver/ziGateObject.d.ts +23 -23
  210. package/dist/adapter/zigate/driver/ziGateObject.js +106 -106
  211. package/dist/adapter/zigate/driver/zigate.d.ts +49 -49
  212. package/dist/adapter/zigate/driver/zigate.js +303 -303
  213. package/dist/buffalo/buffalo.d.ts +50 -50
  214. package/dist/buffalo/buffalo.js +322 -322
  215. package/dist/buffalo/index.d.ts +3 -3
  216. package/dist/buffalo/index.js +33 -33
  217. package/dist/buffalo/tstype.d.ts +8 -8
  218. package/dist/buffalo/tstype.js +2 -2
  219. package/dist/controller/controller.d.ts +113 -110
  220. package/dist/controller/controller.d.ts.map +1 -1
  221. package/dist/controller/controller.js +619 -607
  222. package/dist/controller/controller.js.map +1 -1
  223. package/dist/controller/database.d.ts +18 -18
  224. package/dist/controller/database.js +93 -93
  225. package/dist/controller/events.d.ts +58 -55
  226. package/dist/controller/events.d.ts.map +1 -1
  227. package/dist/controller/events.js +101 -101
  228. package/dist/controller/events.js.map +1 -1
  229. package/dist/controller/greenPower.d.ts +12 -12
  230. package/dist/controller/greenPower.js +220 -220
  231. package/dist/controller/helpers/index.d.ts +2 -2
  232. package/dist/controller/helpers/index.js +28 -28
  233. package/dist/controller/helpers/request.d.ts +22 -22
  234. package/dist/controller/helpers/request.js +71 -71
  235. package/dist/controller/helpers/zclFrameConverter.d.ts +7 -7
  236. package/dist/controller/helpers/zclFrameConverter.js +31 -31
  237. package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts +5 -5
  238. package/dist/controller/helpers/zclTransactionSequenceNumber.js +13 -13
  239. package/dist/controller/index.d.ts +5 -5
  240. package/dist/controller/index.js +8 -8
  241. package/dist/controller/logger-stub.d.ts +6 -6
  242. package/dist/controller/logger-stub.js +2 -2
  243. package/dist/controller/model/device.d.ts +133 -132
  244. package/dist/controller/model/device.d.ts.map +1 -1
  245. package/dist/controller/model/device.js +717 -708
  246. package/dist/controller/model/device.js.map +1 -1
  247. package/dist/controller/model/endpoint.d.ts +131 -131
  248. package/dist/controller/model/endpoint.d.ts.map +1 -1
  249. package/dist/controller/model/endpoint.js +816 -817
  250. package/dist/controller/model/endpoint.js.map +1 -1
  251. package/dist/controller/model/entity.d.ts +14 -14
  252. package/dist/controller/model/entity.js +26 -26
  253. package/dist/controller/model/group.d.ts +38 -38
  254. package/dist/controller/model/group.js +221 -221
  255. package/dist/controller/model/index.d.ts +5 -5
  256. package/dist/controller/model/index.js +14 -14
  257. package/dist/controller/touchlink.d.ts +19 -19
  258. package/dist/controller/touchlink.js +157 -157
  259. package/dist/controller/tstype.d.ts +21 -21
  260. package/dist/controller/tstype.js +9 -9
  261. package/dist/index.d.ts +3 -3
  262. package/dist/index.js +33 -33
  263. package/dist/models/backup-storage-legacy.d.ts +26 -26
  264. package/dist/models/backup-storage-legacy.js +2 -2
  265. package/dist/models/backup-storage-unified.d.ts +49 -49
  266. package/dist/models/backup-storage-unified.js +2 -2
  267. package/dist/models/backup.d.ts +37 -37
  268. package/dist/models/backup.js +2 -2
  269. package/dist/models/index.d.ts +4 -4
  270. package/dist/models/index.js +20 -20
  271. package/dist/models/network-options.d.ts +12 -12
  272. package/dist/models/network-options.js +2 -2
  273. package/dist/utils/assertString.d.ts +2 -2
  274. package/dist/utils/assertString.js +8 -8
  275. package/dist/utils/backup.d.ts +20 -20
  276. package/dist/utils/backup.js +187 -187
  277. package/dist/utils/equalsPartial.d.ts +2 -2
  278. package/dist/utils/equalsPartial.js +11 -11
  279. package/dist/utils/index.d.ts +9 -9
  280. package/dist/utils/index.js +45 -45
  281. package/dist/utils/isNumberArray.d.ts +2 -2
  282. package/dist/utils/isNumberArray.js +6 -6
  283. package/dist/utils/queue.d.ts +11 -11
  284. package/dist/utils/queue.js +50 -50
  285. package/dist/utils/realpathSync.d.ts +2 -2
  286. package/dist/utils/realpathSync.js +12 -12
  287. package/dist/utils/wait.d.ts +2 -2
  288. package/dist/utils/wait.js +8 -8
  289. package/dist/utils/waitress.d.ts +21 -21
  290. package/dist/utils/waitress.js +61 -61
  291. package/dist/zcl/buffaloZcl.d.ts +41 -41
  292. package/dist/zcl/buffaloZcl.js +591 -591
  293. package/dist/zcl/definition/buffaloZclDataType.d.ts +17 -17
  294. package/dist/zcl/definition/buffaloZclDataType.js +20 -20
  295. package/dist/zcl/definition/cluster.d.ts +29 -29
  296. package/dist/zcl/definition/cluster.js +5335 -5335
  297. package/dist/zcl/definition/dataType.d.ts +59 -59
  298. package/dist/zcl/definition/dataType.js +64 -64
  299. package/dist/zcl/definition/direction.d.ts +5 -5
  300. package/dist/zcl/definition/direction.js +8 -8
  301. package/dist/zcl/definition/endpointDeviceType.d.ts +4 -4
  302. package/dist/zcl/definition/endpointDeviceType.js +15 -15
  303. package/dist/zcl/definition/foundation.d.ts +11 -11
  304. package/dist/zcl/definition/foundation.js +167 -167
  305. package/dist/zcl/definition/frameControl.d.ts +10 -10
  306. package/dist/zcl/definition/frameControl.js +2 -2
  307. package/dist/zcl/definition/frameType.d.ts +5 -5
  308. package/dist/zcl/definition/frameType.js +8 -8
  309. package/dist/zcl/definition/index.d.ts +13 -13
  310. package/dist/zcl/definition/index.js +51 -51
  311. package/dist/zcl/definition/manufacturerCode.d.ts +1074 -1074
  312. package/dist/zcl/definition/manufacturerCode.js +1079 -1079
  313. package/dist/zcl/definition/powerSource.d.ts +4 -4
  314. package/dist/zcl/definition/powerSource.js +12 -12
  315. package/dist/zcl/definition/status.d.ts +38 -38
  316. package/dist/zcl/definition/status.js +41 -41
  317. package/dist/zcl/definition/tstype.d.ts +16 -16
  318. package/dist/zcl/definition/tstype.js +2 -2
  319. package/dist/zcl/index.d.ts +15 -15
  320. package/dist/zcl/index.js +55 -55
  321. package/dist/zcl/tstype.d.ts +56 -56
  322. package/dist/zcl/tstype.js +10 -10
  323. package/dist/zcl/utils.d.ts +6 -6
  324. package/dist/zcl/utils.js +165 -165
  325. package/dist/zcl/zclFrame.d.ts +45 -45
  326. package/dist/zcl/zclFrame.js +347 -347
  327. package/dist/zcl/zclStatusError.d.ts +5 -5
  328. package/dist/zcl/zclStatusError.js +13 -13
  329. package/package.json +6 -6
@@ -1,1061 +1,1061 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const debug_1 = __importDefault(require("debug"));
30
- const adapter_1 = __importDefault(require("../../adapter"));
31
- const debug = (0, debug_1.default)("zigbee-herdsman:deconz:adapter");
32
- const driver_1 = __importDefault(require("../driver/driver"));
33
- const zcl_1 = require("../../../zcl");
34
- const Events = __importStar(require("../../events"));
35
- const frameParser_1 = __importDefault(require("../driver/frameParser"));
36
- const utils_1 = require("../../../utils");
37
- const constants_1 = __importDefault(require("../driver/constants"));
38
- var frameParser = require('../driver/frameParser');
39
- ;
40
- class DeconzAdapter extends adapter_1.default {
41
- constructor(networkOptions, serialPortOptions, backupPath, adapterOptions, logger) {
42
- super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);
43
- this.frameParserEvent = frameParser.frameParserEvents;
44
- this.TX_OPTIONS = 0x00; // No APS ACKS
45
- const concurrent = this.adapterOptions && this.adapterOptions.concurrent ?
46
- this.adapterOptions.concurrent : 2;
47
- // TODO: https://github.com/Koenkk/zigbee2mqtt/issues/4884#issuecomment-728903121
48
- const delay = this.adapterOptions && typeof this.adapterOptions.delay === 'number' ?
49
- this.adapterOptions.delay : 0;
50
- this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
51
- this.driver = new driver_1.default(serialPortOptions.path);
52
- this.driver.setDelay(delay);
53
- if (delay >= 200) {
54
- this.TX_OPTIONS = 0x04; // activate APS ACKS
55
- }
56
- this.driver.on('rxFrame', (frame) => { (0, frameParser_1.default)(frame); });
57
- this.queue = new utils_1.Queue(concurrent);
58
- this.transactionID = 0;
59
- this.openRequestsQueue = [];
60
- this.joinPermitted = false;
61
- this.fwVersion = null;
62
- this.frameParserEvent.on('receivedDataPayload', (data) => { this.checkReceivedDataPayload(data); });
63
- this.frameParserEvent.on('receivedGreenPowerIndication', (data) => { this.checkReceivedGreenPowerIndication(data); });
64
- const that = this;
65
- setInterval(() => { that.checkReceivedDataPayload(null); }, 1000);
66
- setTimeout(() => { that.checkCoordinatorSimpleDescriptor(false); }, 3000);
67
- }
68
- static async isValidPath(path) {
69
- return driver_1.default.isValidPath(path);
70
- }
71
- static async autoDetectPath() {
72
- return driver_1.default.autoDetectPath();
73
- }
74
- /**
75
- * Adapter methods
76
- */
77
- async start() {
78
- await this.driver.open();
79
- return "resumed";
80
- }
81
- async stop() {
82
- await this.driver.close();
83
- }
84
- async getCoordinator() {
85
- const ieeeAddr = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.MAC);
86
- const nwkAddr = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.NWK_ADDRESS);
87
- const endpoints = [{
88
- ID: 0x01,
89
- profileID: 0x0104,
90
- deviceID: 0x0005,
91
- inputClusters: [0x0000, 0x000A, 0x0019],
92
- outputClusters: [0x0001, 0x0020, 0x0500]
93
- },
94
- {
95
- ID: 0xF2,
96
- profileID: 0xA1E0,
97
- deviceID: 0x0064,
98
- inputClusters: [],
99
- outputClusters: [0x0021]
100
- }];
101
- return {
102
- networkAddress: nwkAddr,
103
- manufacturerID: 0x1135,
104
- ieeeAddr: ieeeAddr,
105
- endpoints,
106
- };
107
- }
108
- async permitJoin(seconds, networkAddress) {
109
- const transactionID = this.nextTransactionID();
110
- const request = {};
111
- const zdpFrame = [transactionID, seconds, 0]; // tc_significance 1 or 0 ?
112
- request.requestId = transactionID;
113
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
114
- request.destAddr16 = networkAddress || 0xFFFC;
115
- request.destEndpoint = 0;
116
- request.profileId = 0;
117
- request.clusterId = 0x36; // permit join
118
- request.srcEndpoint = 0;
119
- request.asduLength = 3;
120
- request.asduPayload = zdpFrame;
121
- request.txOptions = 0;
122
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
123
- request.timeout = 5;
124
- try {
125
- await this.driver.enqueueSendDataRequest(request);
126
- if (seconds === 0) {
127
- this.joinPermitted = false;
128
- }
129
- else {
130
- this.joinPermitted = true;
131
- }
132
- this.driver.writeParameterRequest(constants_1.default.PARAM.Network.PERMIT_JOIN, seconds);
133
- debug("PERMIT_JOIN - " + seconds + " seconds");
134
- }
135
- catch (error) {
136
- const msg = "PERMIT_JOIN FAILED - " + error;
137
- debug(msg);
138
- // try again
139
- this.permitJoin(seconds, networkAddress);
140
- //return Promise.reject(new Error(msg)); // do not reject
141
- }
142
- }
143
- async getCoordinatorVersion() {
144
- // product: number; transportrev: number; majorrel: number; minorrel: number; maintrel: number; revision: string;
145
- if (this.fwVersion != null) {
146
- return this.fwVersion;
147
- }
148
- else {
149
- try {
150
- const fw = await this.driver.readFirmwareVersionRequest();
151
- const buf = Buffer.from(fw);
152
- let fwString = "0x" + buf.readUInt32LE(0).toString(16);
153
- const type = (fw[1] === 5) ? "ConBee/RaspBee" : "ConBee2/RaspBee2";
154
- const meta = { "transportrev": 0, "product": 0, "majorrel": fw[3], "minorrel": fw[2], "maintrel": 0, "revision": fwString };
155
- this.fwVersion = { type: type, meta: meta };
156
- return { type: type, meta: meta };
157
- }
158
- catch (error) {
159
- debug("Get coordinator version Error: " + error);
160
- }
161
- }
162
- }
163
- async addInstallCode(ieeeAddress, key) {
164
- return Promise.reject(new Error('Add install code is not supported'));
165
- }
166
- async reset(type) {
167
- return Promise.reject(new Error('Reset is not supported'));
168
- }
169
- async lqi(networkAddress) {
170
- const neighbors = [];
171
- const add = (list) => {
172
- for (const entry of list) {
173
- const relationByte = entry.readUInt8(18);
174
- const extAddr = [];
175
- for (let i = 8; i < 16; i++) {
176
- extAddr.push(entry[i]);
177
- }
178
- neighbors.push({
179
- linkquality: entry.readUInt8(21),
180
- networkAddress: entry.readUInt16LE(16),
181
- ieeeAddr: this.driver.macAddrArrayToString(extAddr),
182
- relationship: (relationByte >> 1) & ((1 << 3) - 1),
183
- depth: entry.readUInt8(20)
184
- });
185
- }
186
- };
187
- const request = async (startIndex) => {
188
- const transactionID = this.nextTransactionID();
189
- const req = {};
190
- req.requestId = transactionID;
191
- req.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
192
- req.destAddr16 = networkAddress;
193
- req.destEndpoint = 0;
194
- req.profileId = 0;
195
- req.clusterId = 0x31; // mgmt_lqi_request
196
- req.srcEndpoint = 0;
197
- req.asduLength = 2;
198
- req.asduPayload = [transactionID, startIndex];
199
- req.txOptions = 0;
200
- req.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
201
- this.driver.enqueueSendDataRequest(req)
202
- .then(result => { })
203
- .catch(error => { });
204
- try {
205
- const d = await this.waitForData(networkAddress, 0, 0x8031);
206
- const data = d.asduPayload;
207
- if (data[1] !== 0) { // status
208
- throw new Error(`LQI for '${networkAddress}' failed`);
209
- }
210
- const tableList = [];
211
- const response = {
212
- status: data[1],
213
- tableEntrys: data[2],
214
- startIndex: data[3],
215
- tableListCount: data[4],
216
- tableList: tableList
217
- };
218
- let tableEntry = [];
219
- let counter = 0;
220
- for (let i = 5; i < ((response.tableListCount * 22) + 5); i++) { // one tableentry = 22 bytes
221
- tableEntry.push(data[i]);
222
- counter++;
223
- if (counter === 22) {
224
- response.tableList.push(Buffer.from(tableEntry));
225
- tableEntry = [];
226
- counter = 0;
227
- }
228
- }
229
- debug("LQI RESPONSE - addr: 0x" + networkAddress.toString(16) + " status: " + response.status + " read " + (response.tableListCount + response.startIndex) + "/" + response.tableEntrys + " entrys");
230
- return response;
231
- }
232
- catch (error) {
233
- const msg = "LQI REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
234
- debug(msg);
235
- return Promise.reject(new Error(msg));
236
- }
237
- };
238
- let response = await request(0);
239
- add(response.tableList);
240
- let nextStartIndex = response.tableListCount;
241
- while (neighbors.length < response.tableEntrys) {
242
- response = await request(nextStartIndex);
243
- add(response.tableList);
244
- nextStartIndex += response.tableListCount;
245
- }
246
- return { neighbors };
247
- }
248
- async routingTable(networkAddress) {
249
- const table = [];
250
- const statusLookup = {
251
- 0: 'ACTIVE',
252
- 1: 'DISCOVERY_UNDERWAY',
253
- 2: 'DISCOVERY_FAILED',
254
- 3: 'INACTIVE',
255
- };
256
- const add = (list) => {
257
- for (const entry of list) {
258
- const statusByte = entry.readUInt8(2);
259
- const extAddr = [];
260
- for (let i = 8; i < 16; i++) {
261
- extAddr.push(entry[i]);
262
- }
263
- table.push({
264
- destinationAddress: entry.readUInt16LE(0),
265
- status: statusLookup[(statusByte >> 5) & ((1 << 3) - 1)],
266
- nextHop: entry.readUInt16LE(3)
267
- });
268
- }
269
- };
270
- const request = async (startIndex) => {
271
- const transactionID = this.nextTransactionID();
272
- const req = {};
273
- req.requestId = transactionID;
274
- req.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
275
- req.destAddr16 = networkAddress;
276
- req.destEndpoint = 0;
277
- req.profileId = 0;
278
- req.clusterId = 0x32; // mgmt_rtg_request
279
- req.srcEndpoint = 0;
280
- req.asduLength = 2;
281
- req.asduPayload = [transactionID, startIndex];
282
- req.txOptions = 0;
283
- req.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
284
- req.timeout = 30;
285
- this.driver.enqueueSendDataRequest(req)
286
- .then(result => { })
287
- .catch(error => { });
288
- try {
289
- const d = await this.waitForData(networkAddress, 0, 0x8032);
290
- const data = d.asduPayload;
291
- if (data[1] !== 0) { // status
292
- throw new Error(`Routingtables for '${networkAddress}' failed`);
293
- }
294
- const tableList = [];
295
- const response = {
296
- status: data[1],
297
- tableEntrys: data[2],
298
- startIndex: data[3],
299
- tableListCount: data[4],
300
- tableList: tableList
301
- };
302
- let tableEntry = [];
303
- let counter = 0;
304
- for (let i = 5; i < ((response.tableListCount * 5) + 5); i++) { // one tableentry = 5 bytes
305
- tableEntry.push(data[i]);
306
- counter++;
307
- if (counter === 5) {
308
- response.tableList.push(Buffer.from(tableEntry));
309
- tableEntry = [];
310
- counter = 0;
311
- }
312
- }
313
- debug("ROUTING_TABLE RESPONSE - addr: 0x" + networkAddress.toString(16) + " status: " + response.status + " read " + (response.tableListCount + response.startIndex) + "/" + response.tableEntrys + " entrys");
314
- return response;
315
- }
316
- catch (error) {
317
- const msg = "ROUTING_TABLE REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
318
- debug(msg);
319
- return Promise.reject(new Error(msg));
320
- }
321
- };
322
- let response = await request(0);
323
- add(response.tableList);
324
- let nextStartIndex = response.tableListCount;
325
- while (table.length < response.tableEntrys) {
326
- response = await request(nextStartIndex);
327
- add(response.tableList);
328
- nextStartIndex += response.tableListCount;
329
- }
330
- return { table };
331
- }
332
- async nodeDescriptor(networkAddress) {
333
- const transactionID = this.nextTransactionID();
334
- const nwk1 = networkAddress & 0xff;
335
- const nwk2 = (networkAddress >> 8) & 0xff;
336
- const request = {};
337
- const zdpFrame = [transactionID, nwk1, nwk2];
338
- request.requestId = transactionID;
339
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
340
- request.destAddr16 = networkAddress;
341
- request.destEndpoint = 0;
342
- request.profileId = 0;
343
- request.clusterId = 0x02; // node descriptor
344
- request.srcEndpoint = 0;
345
- request.asduLength = 3;
346
- request.asduPayload = zdpFrame;
347
- request.txOptions = 0;
348
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
349
- request.timeout = 30;
350
- this.driver.enqueueSendDataRequest(request)
351
- .then(result => { })
352
- .catch(error => { });
353
- try {
354
- const d = await this.waitForData(networkAddress, 0, 0x8002);
355
- const data = d.asduPayload;
356
- const buf = Buffer.from(data);
357
- const logicaltype = (data[4] & 7);
358
- const type = (logicaltype === 1) ? 'Router' : (logicaltype === 2) ? 'EndDevice' : (logicaltype === 0) ? 'Coordinator' : 'Unknown';
359
- const manufacturer = buf.readUInt16LE(7);
360
- debug("RECEIVING NODE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16) + " type: " + type + " manufacturer: 0x" + manufacturer.toString(16));
361
- return { manufacturerCode: manufacturer, type };
362
- }
363
- catch (error) {
364
- const msg = "RECEIVING NODE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
365
- debug(msg);
366
- return Promise.reject(new Error(msg));
367
- }
368
- }
369
- async activeEndpoints(networkAddress) {
370
- const transactionID = this.nextTransactionID();
371
- const nwk1 = networkAddress & 0xff;
372
- const nwk2 = (networkAddress >> 8) & 0xff;
373
- const request = {};
374
- const zdpFrame = [transactionID, nwk1, nwk2];
375
- request.requestId = transactionID;
376
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
377
- request.destAddr16 = networkAddress;
378
- request.destEndpoint = 0;
379
- request.profileId = 0;
380
- request.clusterId = 0x05; // active endpoints
381
- request.srcEndpoint = 0;
382
- request.asduLength = 3;
383
- request.asduPayload = zdpFrame;
384
- request.txOptions = 0;
385
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
386
- request.timeout = 30;
387
- this.driver.enqueueSendDataRequest(request)
388
- .then(result => { })
389
- .catch(error => { });
390
- try {
391
- const d = await this.waitForData(networkAddress, 0, 0x8005);
392
- const data = d.asduPayload;
393
- const buf = Buffer.from(data);
394
- const epCount = buf.readUInt8(4);
395
- const epList = [];
396
- for (let i = 5; i < (epCount + 5); i++) {
397
- epList.push(buf.readUInt8(i));
398
- }
399
- debug("ACTIVE_ENDPOINTS - addr: 0x" + networkAddress.toString(16) + " EP list: " + epList);
400
- return { endpoints: epList };
401
- }
402
- catch (error) {
403
- const msg = "READING ACTIVE_ENDPOINTS FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
404
- debug(msg);
405
- return Promise.reject(new Error(msg));
406
- }
407
- }
408
- async simpleDescriptor(networkAddress, endpointID) {
409
- const transactionID = this.nextTransactionID();
410
- const nwk1 = networkAddress & 0xff;
411
- const nwk2 = (networkAddress >> 8) & 0xff;
412
- const request = {};
413
- const zdpFrame = [transactionID, nwk1, nwk2, endpointID];
414
- request.requestId = transactionID;
415
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
416
- request.destAddr16 = networkAddress;
417
- request.destEndpoint = 0;
418
- request.profileId = 0;
419
- request.clusterId = 0x04; // simple descriptor
420
- request.srcEndpoint = 0;
421
- request.asduLength = 4;
422
- request.asduPayload = zdpFrame;
423
- request.txOptions = 0;
424
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
425
- request.timeout = 30;
426
- this.driver.enqueueSendDataRequest(request)
427
- .then(result => { })
428
- .catch(error => { });
429
- try {
430
- const d = await this.waitForData(networkAddress, 0, 0x8004);
431
- const data = d.asduPayload;
432
- const buf = Buffer.from(data);
433
- const inCount = buf.readUInt8(11);
434
- const inClusters = [];
435
- let cIndex = 12;
436
- for (let i = 0; i < inCount; i++) {
437
- inClusters[i] = buf.readUInt16LE(cIndex);
438
- cIndex += 2;
439
- }
440
- const outCount = buf.readUInt8(12 + (inCount * 2));
441
- const outClusters = [];
442
- cIndex = 13 + (inCount * 2);
443
- for (let l = 0; l < outCount; l++) {
444
- outClusters[l] = buf.readUInt16LE(cIndex);
445
- cIndex += 2;
446
- }
447
- const simpleDesc = {
448
- profileID: buf.readUInt16LE(6),
449
- endpointID: buf.readUInt8(5),
450
- deviceID: buf.readUInt16LE(8),
451
- inputClusters: inClusters,
452
- outputClusters: outClusters
453
- };
454
- debug("RECEIVING SIMPLE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16) + " EP:" + simpleDesc.endpointID + " inClusters: " + inClusters + " outClusters: " + outClusters);
455
- return simpleDesc;
456
- }
457
- catch (error) {
458
- const msg = "RECEIVING SIMPLE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
459
- debug(msg);
460
- return Promise.reject(new Error(msg));
461
- }
462
- }
463
- async checkCoordinatorSimpleDescriptor(skip) {
464
- debug("checking coordinator simple descriptor");
465
- var simpleDesc = null;
466
- if (skip === false) {
467
- try {
468
- simpleDesc = await this.simpleDescriptor(0x0, 1);
469
- }
470
- catch (error) {
471
- }
472
- if (simpleDesc === null) {
473
- this.checkCoordinatorSimpleDescriptor(false);
474
- return;
475
- }
476
- debug("EP: " + simpleDesc.endpointID);
477
- debug("profile ID: " + simpleDesc.profileID);
478
- debug("device ID: " + simpleDesc.deviceID);
479
- for (let i = 0; i < simpleDesc.inputClusters.length; i++) {
480
- debug("input cluster: 0x" + simpleDesc.inputClusters[i].toString(16));
481
- }
482
- for (let o = 0; o < simpleDesc.outputClusters.length; o++) {
483
- debug("output cluster: 0x" + simpleDesc.outputClusters[o].toString(16));
484
- }
485
- let ok = true;
486
- if (simpleDesc.endpointID === 0x1) {
487
- if (!simpleDesc.inputClusters.includes(0x0) || !simpleDesc.inputClusters.includes(0x0A) || !simpleDesc.inputClusters.includes(0x19) ||
488
- !simpleDesc.outputClusters.includes(0x01) || !simpleDesc.outputClusters.includes(0x20) || !simpleDesc.outputClusters.includes(0x500)) {
489
- debug("missing cluster");
490
- ok = false;
491
- }
492
- if (ok === true) {
493
- return;
494
- }
495
- }
496
- }
497
- debug("setting new simple descriptor");
498
- try { //[ sd1 ep proId devId vers #inCl iCl1 iCl2 iCl3 #outC oCl1 oCl2 oCl3 ]
499
- const sd = [0x00, 0x01, 0x04, 0x01, 0x05, 0x00, 0x01, 0x03, 0x00, 0x00, 0x0A, 0x00, 0x19, 0x00, 0x03, 0x01, 0x00, 0x20, 0x00, 0x00, 0x05];
500
- const sd1 = sd.reverse();
501
- await this.driver.writeParameterRequest(constants_1.default.PARAM.STK.Endpoint, sd1);
502
- }
503
- catch (error) {
504
- debug("error setting simple descriptor - try again");
505
- this.checkCoordinatorSimpleDescriptor(true);
506
- return;
507
- }
508
- debug("success setting simple descriptor");
509
- }
510
- waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
511
- const payload = {
512
- address: networkAddress, endpoint, clusterID, commandIdentifier, frameType, direction,
513
- transactionSequenceNumber,
514
- };
515
- const waiter = this.waitress.waitFor(payload, timeout);
516
- const cancel = () => this.waitress.remove(waiter.ID);
517
- return { promise: waiter.start().promise, cancel };
518
- }
519
- async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
520
- const transactionID = this.nextTransactionID();
521
- const request = {};
522
- let pay = zclFrame.toBuffer();
523
- //console.log("zclFramte.toBuffer:");
524
- //console.log(pay);
525
- request.requestId = transactionID;
526
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
527
- request.destAddr16 = networkAddress;
528
- request.destEndpoint = endpoint;
529
- request.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xa1e0 : 0x104;
530
- request.clusterId = zclFrame.Cluster.ID;
531
- request.srcEndpoint = sourceEndpoint || 1;
532
- request.asduLength = pay.length;
533
- request.asduPayload = [...pay];
534
- request.txOptions = this.TX_OPTIONS; // 0x00 normal; 0x04 APS ACK
535
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
536
- request.timeout = timeout;
537
- const command = zclFrame.getCommand();
538
- this.driver.enqueueSendDataRequest(request)
539
- .then(result => {
540
- debug(`sendZclFrameToEndpoint - message send with transSeq Nr.: ${zclFrame.Header.transactionSequenceNumber}`);
541
- debug(command.hasOwnProperty('response') + ", " + zclFrame.Header.frameControl.disableDefaultResponse + ", " + disableResponse + ", " + request.timeout);
542
- if (!command.hasOwnProperty('response') || zclFrame.Header.frameControl.disableDefaultResponse || !disableResponse) {
543
- debug(`resolve request (${zclFrame.Header.transactionSequenceNumber})`);
544
- return Promise.resolve();
545
- }
546
- })
547
- .catch(error => {
548
- debug(`sendZclFrameToEndpoint ERROR (${zclFrame.Header.transactionSequenceNumber})`);
549
- debug(error);
550
- //return Promise.reject(new Error("sendZclFrameToEndpoint ERROR " + error));
551
- });
552
- try {
553
- let data = null;
554
- if ((command.hasOwnProperty('response') && !disableResponse) || !zclFrame.Header.frameControl.disableDefaultResponse) {
555
- data = await this.waitForData(networkAddress, 0x104, zclFrame.Cluster.ID, zclFrame.Header.transactionSequenceNumber, request.timeout);
556
- }
557
- if (data !== null) {
558
- const asdu = data.asduPayload;
559
- const buffer = Buffer.from(asdu);
560
- const frame = zcl_1.ZclFrame.fromBuffer(zclFrame.Cluster.ID, buffer);
561
- const response = {
562
- address: (data.srcAddrMode === 0x02) ? data.srcAddr16 : null,
563
- frame: frame,
564
- endpoint: data.srcEndpoint,
565
- linkquality: data.lqi,
566
- groupID: (data.srcAddrMode === 0x01) ? data.srcAddr16 : null,
567
- wasBroadcast: data.srcAddrMode === 0x01 || data.srcAddrMode === 0xF,
568
- destinationEndpoint: data.destEndpoint,
569
- };
570
- debug(`response received (${zclFrame.Header.transactionSequenceNumber})`);
571
- return response;
572
- }
573
- else {
574
- debug(`no response expected (${zclFrame.Header.transactionSequenceNumber})`);
575
- return null;
576
- }
577
- }
578
- catch (error) {
579
- throw new Error(`no response received (${zclFrame.Header.transactionSequenceNumber})`);
580
- }
581
- }
582
- async sendZclFrameToGroup(groupID, zclFrame) {
583
- const transactionID = this.nextTransactionID();
584
- const request = {};
585
- let pay = zclFrame.toBuffer();
586
- debug("zclFrame to group - zclFrame.payload:");
587
- debug(zclFrame.Payload);
588
- //console.log("zclFramte.toBuffer:");
589
- //console.log(pay);
590
- request.requestId = transactionID;
591
- request.destAddrMode = constants_1.default.PARAM.addressMode.GROUP_ADDR;
592
- request.destAddr16 = groupID;
593
- request.profileId = 0x104;
594
- request.clusterId = zclFrame.Cluster.ID;
595
- request.srcEndpoint = 1;
596
- request.asduLength = pay.length;
597
- request.asduPayload = [...pay];
598
- request.txOptions = 0;
599
- request.radius = constants_1.default.PARAM.txRadius.UNLIMITED;
600
- try {
601
- debug(`sendZclFrameToGroup - message send`);
602
- return this.driver.enqueueSendDataRequest(request);
603
- }
604
- catch (error) {
605
- //debug(`sendZclFrameToGroup ERROR: ${error}`);
606
- throw new Error(error);
607
- }
608
- }
609
- async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
610
- const transactionID = this.nextTransactionID();
611
- const request = {};
612
- let pay = zclFrame.toBuffer();
613
- debug("zclFrame to all - zclFrame.payload:");
614
- debug(zclFrame.Payload);
615
- request.requestId = transactionID;
616
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
617
- request.destAddr16 = 0xFFFD;
618
- request.destEndpoint = endpoint;
619
- request.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xa1e0 : 0x104;
620
- request.clusterId = zclFrame.Cluster.ID;
621
- request.srcEndpoint = sourceEndpoint;
622
- request.asduLength = pay.length;
623
- request.asduPayload = [...pay];
624
- request.txOptions = 0;
625
- request.radius = constants_1.default.PARAM.txRadius.UNLIMITED;
626
- try {
627
- debug(`sendZclFrameToAll - message send`);
628
- return this.driver.enqueueSendDataRequest(request);
629
- }
630
- catch (error) {
631
- //debug(`sendZclFrameToAll ERROR: ${error}`);
632
- throw new Error(error);
633
- }
634
- }
635
- async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
636
- const transactionID = this.nextTransactionID();
637
- const clid1 = clusterID & 0xff;
638
- const clid2 = (clusterID >> 8) & 0xff;
639
- const destAddrMode = (type === 'group') ? constants_1.default.PARAM.addressMode.GROUP_ADDR : constants_1.default.PARAM.addressMode.IEEE_ADDR;
640
- let destArray;
641
- if (type === 'endpoint') {
642
- destArray = this.driver.macAddrStringToArray(destinationAddressOrGroup);
643
- destArray = destArray.concat([destinationEndpoint]);
644
- }
645
- else {
646
- destArray = [destinationAddressOrGroup, (destinationAddressOrGroup >> 8) & 0xff];
647
- }
648
- const request = {};
649
- const zdpFrame = [transactionID].concat(this.driver.macAddrStringToArray(sourceIeeeAddress)).concat([sourceEndpoint, clid1, clid2, destAddrMode]).concat(destArray);
650
- request.requestId = transactionID;
651
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
652
- request.destAddr16 = destinationNetworkAddress;
653
- request.destEndpoint = 0;
654
- request.profileId = 0;
655
- request.clusterId = 0x21; // bind_request
656
- request.srcEndpoint = 0;
657
- request.asduLength = zdpFrame.length;
658
- request.asduPayload = zdpFrame;
659
- request.txOptions = 0x04; // 0x04 use APS ACKS
660
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
661
- request.timeout = 30;
662
- this.driver.enqueueSendDataRequest(request)
663
- .then(result => { })
664
- .catch(error => { });
665
- try {
666
- const d = await this.waitForData(destinationNetworkAddress, 0, 0x8021);
667
- const data = d.asduPayload;
668
- debug("BIND RESPONSE - addr: 0x" + destinationNetworkAddress.toString(16) + " status: " + data[1]);
669
- if (data[1] !== 0) {
670
- throw new Error("status: " + data[1]);
671
- }
672
- }
673
- catch (error) {
674
- debug("BIND FAILED - addr: 0x" + destinationNetworkAddress.toString(16) + " " + error);
675
- throw new Error(error);
676
- }
677
- }
678
- async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
679
- const transactionID = this.nextTransactionID();
680
- const clid1 = clusterID & 0xff;
681
- const clid2 = (clusterID >> 8) & 0xff;
682
- const destAddrMode = (type === 'group') ? constants_1.default.PARAM.addressMode.GROUP_ADDR : constants_1.default.PARAM.addressMode.IEEE_ADDR;
683
- let destArray;
684
- if (type === 'endpoint') {
685
- destArray = this.driver.macAddrStringToArray(destinationAddressOrGroup);
686
- destArray = destArray.concat([destinationEndpoint]);
687
- }
688
- else {
689
- destArray = [destinationAddressOrGroup, (destinationAddressOrGroup >> 8) & 0xff];
690
- }
691
- const request = {};
692
- const zdpFrame = [transactionID].concat(this.driver.macAddrStringToArray(sourceIeeeAddress)).concat([sourceEndpoint, clid1, clid2, destAddrMode]).concat(destArray);
693
- request.requestId = transactionID;
694
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
695
- request.destAddr16 = destinationNetworkAddress;
696
- request.destEndpoint = 0;
697
- request.profileId = 0;
698
- request.clusterId = 0x22; // unbind_request
699
- request.srcEndpoint = 0;
700
- request.asduLength = zdpFrame.length;
701
- request.asduPayload = zdpFrame;
702
- request.txOptions = 0x04; // 0x04 use APS ACKS
703
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
704
- request.timeout = 30;
705
- this.driver.enqueueSendDataRequest(request)
706
- .then(result => { })
707
- .catch(error => { });
708
- try {
709
- const d = await this.waitForData(destinationNetworkAddress, 0, 0x8022);
710
- const data = d.asduPayload;
711
- debug("UNBIND RESPONSE - addr: 0x" + destinationNetworkAddress.toString(16) + " status: " + data[1]);
712
- if (data[1] !== 0) {
713
- throw new Error("status: " + data[1]);
714
- }
715
- }
716
- catch (error) {
717
- debug("UNBIND FAILED - addr: 0x" + destinationNetworkAddress.toString(16) + " " + error);
718
- throw new Error(error);
719
- }
720
- }
721
- async removeDevice(networkAddress, ieeeAddr) {
722
- const transactionID = this.nextTransactionID();
723
- const nwk1 = networkAddress & 0xff;
724
- const nwk2 = (networkAddress >> 8) & 0xff;
725
- const request = {};
726
- //const zdpFrame = [transactionID].concat(this.driver.macAddrStringToArray(ieeeAddr)).concat([0]);
727
- const zdpFrame = [transactionID].concat([0, 0, 0, 0, 0, 0, 0, 0]).concat([0]);
728
- request.requestId = transactionID;
729
- request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
730
- request.destAddr16 = networkAddress;
731
- request.destEndpoint = 0;
732
- request.profileId = 0;
733
- request.clusterId = 0x34; // mgmt_leave_request
734
- request.srcEndpoint = 0;
735
- request.asduLength = 10;
736
- request.asduPayload = zdpFrame;
737
- request.txOptions = 0;
738
- request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
739
- this.driver.enqueueSendDataRequest(request)
740
- .then(result => { })
741
- .catch(error => { });
742
- try {
743
- const d = await this.waitForData(networkAddress, 0, 0x8034);
744
- const data = d.asduPayload;
745
- debug("REMOVE_DEVICE - addr: 0x" + networkAddress.toString(16) + " status: " + data[1]);
746
- const payload = {
747
- networkAddress: networkAddress,
748
- ieeeAddr: ieeeAddr,
749
- };
750
- if (data[1] !== 0) {
751
- throw new Error("status: " + data[1]);
752
- }
753
- this.emit(Events.Events.deviceLeave, payload);
754
- }
755
- catch (error) {
756
- debug("REMOVE_DEVICE FAILED - addr: 0x" + networkAddress.toString(16) + " " + error);
757
- throw new Error(error);
758
- }
759
- }
760
- async supportsBackup() {
761
- return false;
762
- }
763
- async backup() {
764
- throw new Error("This adapter does not support backup");
765
- }
766
- async getNetworkParameters() {
767
- try {
768
- let panid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.PAN_ID);
769
- let expanid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.APS_EXT_PAN_ID);
770
- let channel = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.CHANNEL);
771
- let networkKey = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.NETWORK_KEY);
772
- // check current channel against configuration.yaml
773
- if (this.networkOptions.channelList[0] !== channel) {
774
- debug("Channel in configuration.yaml (" + this.networkOptions.channelList[0] + ") differs from current channel (" + channel + "). Changing channel.");
775
- let setChannelMask = 0;
776
- switch (this.networkOptions.channelList[0]) {
777
- case 11:
778
- setChannelMask = 0x800;
779
- break;
780
- case 12:
781
- setChannelMask = 0x1000;
782
- break;
783
- case 13:
784
- setChannelMask = 0x2000;
785
- break;
786
- case 14:
787
- setChannelMask = 0x4000;
788
- break;
789
- case 15:
790
- setChannelMask = 0x8000;
791
- break;
792
- case 16:
793
- setChannelMask = 0x10000;
794
- break;
795
- case 17:
796
- setChannelMask = 0x20000;
797
- break;
798
- case 18:
799
- setChannelMask = 0x40000;
800
- break;
801
- case 19:
802
- setChannelMask = 0x80000;
803
- break;
804
- case 20:
805
- setChannelMask = 0x100000;
806
- break;
807
- case 21:
808
- setChannelMask = 0x200000;
809
- break;
810
- case 22:
811
- setChannelMask = 0x400000;
812
- break;
813
- case 23:
814
- setChannelMask = 0x800000;
815
- break;
816
- case 24:
817
- setChannelMask = 0x1000000;
818
- break;
819
- case 25:
820
- setChannelMask = 0x2000000;
821
- break;
822
- case 26:
823
- setChannelMask = 0x4000000;
824
- break;
825
- default:
826
- break;
827
- }
828
- try {
829
- await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.CHANNEL_MASK, setChannelMask);
830
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
831
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
832
- await this.sleep(3000);
833
- channel = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.CHANNEL);
834
- }
835
- catch (error) {
836
- debug("Could not set channel: " + error);
837
- }
838
- }
839
- // check current panid against configuration.yaml
840
- if (this.networkOptions.panID !== panid) {
841
- debug("panid in configuration.yaml (" + this.networkOptions.panID + ") differs from current panid (" + panid + "). Changing panid.");
842
- try {
843
- await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.PAN_ID, this.networkOptions.panID);
844
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
845
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
846
- await this.sleep(3000);
847
- panid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.PAN_ID);
848
- }
849
- catch (error) {
850
- debug("Could not set panid: " + error);
851
- }
852
- }
853
- // check current extended_panid against configuration.yaml
854
- if (this.driver.generalArrayToString(this.networkOptions.extendedPanID, 8) !== expanid) {
855
- debug("extended panid in configuration.yaml (" + this.driver.macAddrArrayToString(this.networkOptions.extendedPanID) + ") differs from current extended panid (" + expanid + "). Changing extended panid.");
856
- try {
857
- //await this.driver.writeParameterRequest(PARAM.PARAM.Network.USE_APS_EXT_PAN_ID, 1);
858
- await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.APS_EXT_PAN_ID, this.networkOptions.extendedPanID);
859
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
860
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
861
- await this.sleep(3000);
862
- expanid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.APS_EXT_PAN_ID);
863
- }
864
- catch (error) {
865
- debug("Could not set extended panid: " + error);
866
- }
867
- }
868
- // check current network key against configuration.yaml
869
- if (this.driver.generalArrayToString(this.networkOptions.networkKey, 16) !== networkKey) {
870
- debug("network key in configuration.yaml (hidden) differs from current network key (" + networkKey + "). Changing network key.");
871
- try {
872
- await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.NETWORK_KEY, this.networkOptions.networkKey);
873
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
874
- await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
875
- await this.sleep(3000);
876
- }
877
- catch (error) {
878
- debug("Could not set network key: " + error);
879
- }
880
- }
881
- return {
882
- panID: panid,
883
- extendedPanID: expanid,
884
- channel: channel
885
- };
886
- }
887
- catch (error) {
888
- const msg = "get network parameters Error:" + error;
889
- debug(msg);
890
- return Promise.reject(new Error(msg));
891
- }
892
- }
893
- async restoreChannelInterPAN() {
894
- throw new Error("not supported");
895
- }
896
- async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddr) {
897
- throw new Error("not supported");
898
- }
899
- async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
900
- throw new Error("not supported");
901
- }
902
- async sendZclFrameInterPANBroadcastWithResponse(zclFrame, timeout) {
903
- throw new Error("not supported");
904
- }
905
- async setChannelInterPAN(channel) {
906
- throw new Error("not supported");
907
- }
908
- async setTransmitPower(value) {
909
- throw new Error("not supported");
910
- }
911
- async sendZclFrameInterPANIeeeAddr(zclFrame, ieeeAddr) {
912
- throw new Error("not supported");
913
- }
914
- /**
915
- * Private methods
916
- */
917
- sleep(ms) {
918
- return new Promise(resolve => setTimeout(resolve, ms));
919
- }
920
- waitForData(addr, profileId, clusterId, transactionSequenceNumber, timeout) {
921
- return new Promise((resolve, reject) => {
922
- const ts = Date.now();
923
- const commandId = constants_1.default.PARAM.APS.DATA_INDICATION;
924
- const req = { addr, profileId, clusterId, transactionSequenceNumber, resolve, reject, ts, timeout };
925
- this.openRequestsQueue.push(req);
926
- });
927
- }
928
- checkReceivedGreenPowerIndication(ind) {
929
- ind.clusterId = 0x21;
930
- let gpFrame = [ind.rspId, ind.seqNr, ind.id,
931
- 0, 0,
932
- // ind.options & 0xff, (ind.options >> 8) & 0xff,
933
- ind.srcId & 0xff, (ind.srcId >> 8) & 0xff, (ind.srcId >> 16) & 0xff, (ind.srcId >> 24) & 0xff,
934
- ind.frameCounter & 0xff, (ind.frameCounter >> 8) & 0xff, (ind.frameCounter >> 16) & 0xff, (ind.frameCounter >> 24) & 0xff,
935
- ind.commandId, ind.commandFrameSize].concat(ind.commandFrame);
936
- const payBuf = Buffer.from(gpFrame);
937
- const payload = {
938
- frame: zcl_1.ZclFrame.fromBuffer(ind.clusterId, payBuf),
939
- address: ind.srcId,
940
- endpoint: 242,
941
- linkquality: 127,
942
- groupID: 0x0b84,
943
- wasBroadcast: false,
944
- destinationEndpoint: 1,
945
- };
946
- this.waitress.resolve(payload);
947
- this.emit(Events.Events.zclData, payload);
948
- }
949
- checkReceivedDataPayload(resp) {
950
- var _a;
951
- let srcAddr = null;
952
- let frame = null;
953
- if (resp != null) {
954
- srcAddr = (resp.srcAddr16 != null) ? resp.srcAddr16 : resp.srcAddr64;
955
- if (resp.profileId != 0x00) {
956
- try {
957
- frame = zcl_1.ZclFrame.fromBuffer(resp.clusterId, Buffer.from(resp.asduPayload));
958
- }
959
- catch (error) {
960
- debug("could not parse zclFrame: " + error);
961
- }
962
- }
963
- }
964
- let i = this.openRequestsQueue.length;
965
- while (i--) {
966
- const req = this.openRequestsQueue[i];
967
- if (srcAddr != null && req.addr === srcAddr && req.clusterId === resp.clusterId &&
968
- req.profileId === resp.profileId) {
969
- if (frame !== null && req.transactionSequenceNumber !== null && req.transactionSequenceNumber !== undefined) {
970
- if (req.transactionSequenceNumber === frame.Header.transactionSequenceNumber) {
971
- debug("resolve data request with transSeq Nr.: " + req.transactionSequenceNumber);
972
- this.openRequestsQueue.splice(i, 1);
973
- req.resolve(resp);
974
- }
975
- }
976
- else {
977
- debug("resolve data request without a transSeq Nr.");
978
- this.openRequestsQueue.splice(i, 1);
979
- req.resolve(resp);
980
- }
981
- }
982
- const now = Date.now();
983
- // Default timeout: 60 seconds.
984
- // Comparison is negated to prevent orphans when invalid timeout is entered (resulting in NaN).
985
- if (!((now - req.ts) <= ((_a = req.timeout) !== null && _a !== void 0 ? _a : 60000))) {
986
- //debug("Timeout for request in openRequestsQueue addr: " + req.addr.toString(16) + " clusterId: " + req.clusterId.toString(16) + " profileId: " + req.profileId.toString(16));
987
- //remove from busyQueue
988
- this.openRequestsQueue.splice(i, 1);
989
- req.reject("waiting for response TIMEOUT");
990
- }
991
- }
992
- // check unattended incomming messages
993
- if (resp != null && resp.profileId === 0x00 && resp.clusterId === 0x13) {
994
- // device Annce
995
- const payBuf = Buffer.from(resp.asduPayload);
996
- const payload = {
997
- networkAddress: payBuf.readUInt16LE(1),
998
- ieeeAddr: this.driver.macAddrArrayToString(resp.asduPayload.slice(3, 11)),
999
- };
1000
- if (this.joinPermitted === true) {
1001
- this.emit(Events.Events.deviceJoined, payload);
1002
- }
1003
- else {
1004
- this.emit(Events.Events.deviceAnnounce, payload);
1005
- }
1006
- }
1007
- if (resp != null && resp.profileId != 0x00) {
1008
- const payBuf = Buffer.from(resp.asduPayload);
1009
- try {
1010
- const payload = {
1011
- frame: zcl_1.ZclFrame.fromBuffer(resp.clusterId, payBuf),
1012
- address: (resp.destAddrMode === 0x03) ? resp.srcAddr64 : resp.srcAddr16,
1013
- endpoint: resp.srcEndpoint,
1014
- linkquality: resp.lqi,
1015
- groupID: (resp.destAddrMode === 0x01) ? resp.destAddr16 : null,
1016
- wasBroadcast: resp.destAddrMode === 0x01 || resp.destAddrMode === 0xF,
1017
- destinationEndpoint: resp.destEndpoint,
1018
- };
1019
- this.waitress.resolve(payload);
1020
- this.emit(Events.Events.zclData, payload);
1021
- }
1022
- catch (error) {
1023
- const payload = {
1024
- clusterID: resp.clusterId,
1025
- data: payBuf,
1026
- address: (resp.destAddrMode === 0x03) ? resp.srcAddr64 : resp.srcAddr16,
1027
- endpoint: resp.srcEndpoint,
1028
- linkquality: resp.lqi,
1029
- groupID: (resp.destAddrMode === 0x01) ? resp.destAddr16 : null,
1030
- wasBroadcast: resp.destAddrMode === 0x01 || resp.destAddrMode === 0xF,
1031
- destinationEndpoint: resp.destEndpoint,
1032
- };
1033
- this.emit(Events.Events.rawData, payload);
1034
- }
1035
- }
1036
- }
1037
- nextTransactionID() {
1038
- this.transactionID++;
1039
- if (this.transactionID > 255) {
1040
- this.transactionID = 1;
1041
- }
1042
- return this.transactionID;
1043
- }
1044
- waitressTimeoutFormatter(matcher, timeout) {
1045
- return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
1046
- ` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
1047
- ` - ${matcher.commandIdentifier} after ${timeout}ms`;
1048
- }
1049
- waitressValidator(payload, matcher) {
1050
- const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
1051
- return (!matcher.address || payload.address === matcher.address) &&
1052
- payload.endpoint === matcher.endpoint &&
1053
- (!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
1054
- payload.frame.Cluster.ID === matcher.clusterID &&
1055
- matcher.frameType === payload.frame.Header.frameControl.frameType &&
1056
- matcher.commandIdentifier === payload.frame.Header.commandIdentifier &&
1057
- matcher.direction === payload.frame.Header.frameControl.direction;
1058
- }
1059
- }
1060
- exports.default = DeconzAdapter;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const debug_1 = __importDefault(require("debug"));
30
+ const adapter_1 = __importDefault(require("../../adapter"));
31
+ const debug = (0, debug_1.default)("zigbee-herdsman:deconz:adapter");
32
+ const driver_1 = __importDefault(require("../driver/driver"));
33
+ const zcl_1 = require("../../../zcl");
34
+ const Events = __importStar(require("../../events"));
35
+ const frameParser_1 = __importDefault(require("../driver/frameParser"));
36
+ const utils_1 = require("../../../utils");
37
+ const constants_1 = __importDefault(require("../driver/constants"));
38
+ var frameParser = require('../driver/frameParser');
39
+ ;
40
+ class DeconzAdapter extends adapter_1.default {
41
+ constructor(networkOptions, serialPortOptions, backupPath, adapterOptions, logger) {
42
+ super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);
43
+ this.frameParserEvent = frameParser.frameParserEvents;
44
+ this.TX_OPTIONS = 0x00; // No APS ACKS
45
+ const concurrent = this.adapterOptions && this.adapterOptions.concurrent ?
46
+ this.adapterOptions.concurrent : 2;
47
+ // TODO: https://github.com/Koenkk/zigbee2mqtt/issues/4884#issuecomment-728903121
48
+ const delay = this.adapterOptions && typeof this.adapterOptions.delay === 'number' ?
49
+ this.adapterOptions.delay : 0;
50
+ this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
51
+ this.driver = new driver_1.default(serialPortOptions.path);
52
+ this.driver.setDelay(delay);
53
+ if (delay >= 200) {
54
+ this.TX_OPTIONS = 0x04; // activate APS ACKS
55
+ }
56
+ this.driver.on('rxFrame', (frame) => { (0, frameParser_1.default)(frame); });
57
+ this.queue = new utils_1.Queue(concurrent);
58
+ this.transactionID = 0;
59
+ this.openRequestsQueue = [];
60
+ this.joinPermitted = false;
61
+ this.fwVersion = null;
62
+ this.frameParserEvent.on('receivedDataPayload', (data) => { this.checkReceivedDataPayload(data); });
63
+ this.frameParserEvent.on('receivedGreenPowerIndication', (data) => { this.checkReceivedGreenPowerIndication(data); });
64
+ const that = this;
65
+ setInterval(() => { that.checkReceivedDataPayload(null); }, 1000);
66
+ setTimeout(() => { that.checkCoordinatorSimpleDescriptor(false); }, 3000);
67
+ }
68
+ static async isValidPath(path) {
69
+ return driver_1.default.isValidPath(path);
70
+ }
71
+ static async autoDetectPath() {
72
+ return driver_1.default.autoDetectPath();
73
+ }
74
+ /**
75
+ * Adapter methods
76
+ */
77
+ async start() {
78
+ await this.driver.open();
79
+ return "resumed";
80
+ }
81
+ async stop() {
82
+ await this.driver.close();
83
+ }
84
+ async getCoordinator() {
85
+ const ieeeAddr = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.MAC);
86
+ const nwkAddr = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.NWK_ADDRESS);
87
+ const endpoints = [{
88
+ ID: 0x01,
89
+ profileID: 0x0104,
90
+ deviceID: 0x0005,
91
+ inputClusters: [0x0000, 0x000A, 0x0019],
92
+ outputClusters: [0x0001, 0x0020, 0x0500]
93
+ },
94
+ {
95
+ ID: 0xF2,
96
+ profileID: 0xA1E0,
97
+ deviceID: 0x0064,
98
+ inputClusters: [],
99
+ outputClusters: [0x0021]
100
+ }];
101
+ return {
102
+ networkAddress: nwkAddr,
103
+ manufacturerID: 0x1135,
104
+ ieeeAddr: ieeeAddr,
105
+ endpoints,
106
+ };
107
+ }
108
+ async permitJoin(seconds, networkAddress) {
109
+ const transactionID = this.nextTransactionID();
110
+ const request = {};
111
+ const zdpFrame = [transactionID, seconds, 0]; // tc_significance 1 or 0 ?
112
+ request.requestId = transactionID;
113
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
114
+ request.destAddr16 = networkAddress || 0xFFFC;
115
+ request.destEndpoint = 0;
116
+ request.profileId = 0;
117
+ request.clusterId = 0x36; // permit join
118
+ request.srcEndpoint = 0;
119
+ request.asduLength = 3;
120
+ request.asduPayload = zdpFrame;
121
+ request.txOptions = 0;
122
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
123
+ request.timeout = 5;
124
+ try {
125
+ await this.driver.enqueueSendDataRequest(request);
126
+ if (seconds === 0) {
127
+ this.joinPermitted = false;
128
+ }
129
+ else {
130
+ this.joinPermitted = true;
131
+ }
132
+ this.driver.writeParameterRequest(constants_1.default.PARAM.Network.PERMIT_JOIN, seconds);
133
+ debug("PERMIT_JOIN - " + seconds + " seconds");
134
+ }
135
+ catch (error) {
136
+ const msg = "PERMIT_JOIN FAILED - " + error;
137
+ debug(msg);
138
+ // try again
139
+ this.permitJoin(seconds, networkAddress);
140
+ //return Promise.reject(new Error(msg)); // do not reject
141
+ }
142
+ }
143
+ async getCoordinatorVersion() {
144
+ // product: number; transportrev: number; majorrel: number; minorrel: number; maintrel: number; revision: string;
145
+ if (this.fwVersion != null) {
146
+ return this.fwVersion;
147
+ }
148
+ else {
149
+ try {
150
+ const fw = await this.driver.readFirmwareVersionRequest();
151
+ const buf = Buffer.from(fw);
152
+ let fwString = "0x" + buf.readUInt32LE(0).toString(16);
153
+ const type = (fw[1] === 5) ? "ConBee/RaspBee" : "ConBee2/RaspBee2";
154
+ const meta = { "transportrev": 0, "product": 0, "majorrel": fw[3], "minorrel": fw[2], "maintrel": 0, "revision": fwString };
155
+ this.fwVersion = { type: type, meta: meta };
156
+ return { type: type, meta: meta };
157
+ }
158
+ catch (error) {
159
+ debug("Get coordinator version Error: " + error);
160
+ }
161
+ }
162
+ }
163
+ async addInstallCode(ieeeAddress, key) {
164
+ return Promise.reject(new Error('Add install code is not supported'));
165
+ }
166
+ async reset(type) {
167
+ return Promise.reject(new Error('Reset is not supported'));
168
+ }
169
+ async lqi(networkAddress) {
170
+ const neighbors = [];
171
+ const add = (list) => {
172
+ for (const entry of list) {
173
+ const relationByte = entry.readUInt8(18);
174
+ const extAddr = [];
175
+ for (let i = 8; i < 16; i++) {
176
+ extAddr.push(entry[i]);
177
+ }
178
+ neighbors.push({
179
+ linkquality: entry.readUInt8(21),
180
+ networkAddress: entry.readUInt16LE(16),
181
+ ieeeAddr: this.driver.macAddrArrayToString(extAddr),
182
+ relationship: (relationByte >> 1) & ((1 << 3) - 1),
183
+ depth: entry.readUInt8(20)
184
+ });
185
+ }
186
+ };
187
+ const request = async (startIndex) => {
188
+ const transactionID = this.nextTransactionID();
189
+ const req = {};
190
+ req.requestId = transactionID;
191
+ req.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
192
+ req.destAddr16 = networkAddress;
193
+ req.destEndpoint = 0;
194
+ req.profileId = 0;
195
+ req.clusterId = 0x31; // mgmt_lqi_request
196
+ req.srcEndpoint = 0;
197
+ req.asduLength = 2;
198
+ req.asduPayload = [transactionID, startIndex];
199
+ req.txOptions = 0;
200
+ req.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
201
+ this.driver.enqueueSendDataRequest(req)
202
+ .then(result => { })
203
+ .catch(error => { });
204
+ try {
205
+ const d = await this.waitForData(networkAddress, 0, 0x8031);
206
+ const data = d.asduPayload;
207
+ if (data[1] !== 0) { // status
208
+ throw new Error(`LQI for '${networkAddress}' failed`);
209
+ }
210
+ const tableList = [];
211
+ const response = {
212
+ status: data[1],
213
+ tableEntrys: data[2],
214
+ startIndex: data[3],
215
+ tableListCount: data[4],
216
+ tableList: tableList
217
+ };
218
+ let tableEntry = [];
219
+ let counter = 0;
220
+ for (let i = 5; i < ((response.tableListCount * 22) + 5); i++) { // one tableentry = 22 bytes
221
+ tableEntry.push(data[i]);
222
+ counter++;
223
+ if (counter === 22) {
224
+ response.tableList.push(Buffer.from(tableEntry));
225
+ tableEntry = [];
226
+ counter = 0;
227
+ }
228
+ }
229
+ debug("LQI RESPONSE - addr: 0x" + networkAddress.toString(16) + " status: " + response.status + " read " + (response.tableListCount + response.startIndex) + "/" + response.tableEntrys + " entrys");
230
+ return response;
231
+ }
232
+ catch (error) {
233
+ const msg = "LQI REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
234
+ debug(msg);
235
+ return Promise.reject(new Error(msg));
236
+ }
237
+ };
238
+ let response = await request(0);
239
+ add(response.tableList);
240
+ let nextStartIndex = response.tableListCount;
241
+ while (neighbors.length < response.tableEntrys) {
242
+ response = await request(nextStartIndex);
243
+ add(response.tableList);
244
+ nextStartIndex += response.tableListCount;
245
+ }
246
+ return { neighbors };
247
+ }
248
+ async routingTable(networkAddress) {
249
+ const table = [];
250
+ const statusLookup = {
251
+ 0: 'ACTIVE',
252
+ 1: 'DISCOVERY_UNDERWAY',
253
+ 2: 'DISCOVERY_FAILED',
254
+ 3: 'INACTIVE',
255
+ };
256
+ const add = (list) => {
257
+ for (const entry of list) {
258
+ const statusByte = entry.readUInt8(2);
259
+ const extAddr = [];
260
+ for (let i = 8; i < 16; i++) {
261
+ extAddr.push(entry[i]);
262
+ }
263
+ table.push({
264
+ destinationAddress: entry.readUInt16LE(0),
265
+ status: statusLookup[(statusByte >> 5) & ((1 << 3) - 1)],
266
+ nextHop: entry.readUInt16LE(3)
267
+ });
268
+ }
269
+ };
270
+ const request = async (startIndex) => {
271
+ const transactionID = this.nextTransactionID();
272
+ const req = {};
273
+ req.requestId = transactionID;
274
+ req.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
275
+ req.destAddr16 = networkAddress;
276
+ req.destEndpoint = 0;
277
+ req.profileId = 0;
278
+ req.clusterId = 0x32; // mgmt_rtg_request
279
+ req.srcEndpoint = 0;
280
+ req.asduLength = 2;
281
+ req.asduPayload = [transactionID, startIndex];
282
+ req.txOptions = 0;
283
+ req.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
284
+ req.timeout = 30;
285
+ this.driver.enqueueSendDataRequest(req)
286
+ .then(result => { })
287
+ .catch(error => { });
288
+ try {
289
+ const d = await this.waitForData(networkAddress, 0, 0x8032);
290
+ const data = d.asduPayload;
291
+ if (data[1] !== 0) { // status
292
+ throw new Error(`Routingtables for '${networkAddress}' failed`);
293
+ }
294
+ const tableList = [];
295
+ const response = {
296
+ status: data[1],
297
+ tableEntrys: data[2],
298
+ startIndex: data[3],
299
+ tableListCount: data[4],
300
+ tableList: tableList
301
+ };
302
+ let tableEntry = [];
303
+ let counter = 0;
304
+ for (let i = 5; i < ((response.tableListCount * 5) + 5); i++) { // one tableentry = 5 bytes
305
+ tableEntry.push(data[i]);
306
+ counter++;
307
+ if (counter === 5) {
308
+ response.tableList.push(Buffer.from(tableEntry));
309
+ tableEntry = [];
310
+ counter = 0;
311
+ }
312
+ }
313
+ debug("ROUTING_TABLE RESPONSE - addr: 0x" + networkAddress.toString(16) + " status: " + response.status + " read " + (response.tableListCount + response.startIndex) + "/" + response.tableEntrys + " entrys");
314
+ return response;
315
+ }
316
+ catch (error) {
317
+ const msg = "ROUTING_TABLE REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
318
+ debug(msg);
319
+ return Promise.reject(new Error(msg));
320
+ }
321
+ };
322
+ let response = await request(0);
323
+ add(response.tableList);
324
+ let nextStartIndex = response.tableListCount;
325
+ while (table.length < response.tableEntrys) {
326
+ response = await request(nextStartIndex);
327
+ add(response.tableList);
328
+ nextStartIndex += response.tableListCount;
329
+ }
330
+ return { table };
331
+ }
332
+ async nodeDescriptor(networkAddress) {
333
+ const transactionID = this.nextTransactionID();
334
+ const nwk1 = networkAddress & 0xff;
335
+ const nwk2 = (networkAddress >> 8) & 0xff;
336
+ const request = {};
337
+ const zdpFrame = [transactionID, nwk1, nwk2];
338
+ request.requestId = transactionID;
339
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
340
+ request.destAddr16 = networkAddress;
341
+ request.destEndpoint = 0;
342
+ request.profileId = 0;
343
+ request.clusterId = 0x02; // node descriptor
344
+ request.srcEndpoint = 0;
345
+ request.asduLength = 3;
346
+ request.asduPayload = zdpFrame;
347
+ request.txOptions = 0;
348
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
349
+ request.timeout = 30;
350
+ this.driver.enqueueSendDataRequest(request)
351
+ .then(result => { })
352
+ .catch(error => { });
353
+ try {
354
+ const d = await this.waitForData(networkAddress, 0, 0x8002);
355
+ const data = d.asduPayload;
356
+ const buf = Buffer.from(data);
357
+ const logicaltype = (data[4] & 7);
358
+ const type = (logicaltype === 1) ? 'Router' : (logicaltype === 2) ? 'EndDevice' : (logicaltype === 0) ? 'Coordinator' : 'Unknown';
359
+ const manufacturer = buf.readUInt16LE(7);
360
+ debug("RECEIVING NODE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16) + " type: " + type + " manufacturer: 0x" + manufacturer.toString(16));
361
+ return { manufacturerCode: manufacturer, type };
362
+ }
363
+ catch (error) {
364
+ const msg = "RECEIVING NODE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
365
+ debug(msg);
366
+ return Promise.reject(new Error(msg));
367
+ }
368
+ }
369
+ async activeEndpoints(networkAddress) {
370
+ const transactionID = this.nextTransactionID();
371
+ const nwk1 = networkAddress & 0xff;
372
+ const nwk2 = (networkAddress >> 8) & 0xff;
373
+ const request = {};
374
+ const zdpFrame = [transactionID, nwk1, nwk2];
375
+ request.requestId = transactionID;
376
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
377
+ request.destAddr16 = networkAddress;
378
+ request.destEndpoint = 0;
379
+ request.profileId = 0;
380
+ request.clusterId = 0x05; // active endpoints
381
+ request.srcEndpoint = 0;
382
+ request.asduLength = 3;
383
+ request.asduPayload = zdpFrame;
384
+ request.txOptions = 0;
385
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
386
+ request.timeout = 30;
387
+ this.driver.enqueueSendDataRequest(request)
388
+ .then(result => { })
389
+ .catch(error => { });
390
+ try {
391
+ const d = await this.waitForData(networkAddress, 0, 0x8005);
392
+ const data = d.asduPayload;
393
+ const buf = Buffer.from(data);
394
+ const epCount = buf.readUInt8(4);
395
+ const epList = [];
396
+ for (let i = 5; i < (epCount + 5); i++) {
397
+ epList.push(buf.readUInt8(i));
398
+ }
399
+ debug("ACTIVE_ENDPOINTS - addr: 0x" + networkAddress.toString(16) + " EP list: " + epList);
400
+ return { endpoints: epList };
401
+ }
402
+ catch (error) {
403
+ const msg = "READING ACTIVE_ENDPOINTS FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
404
+ debug(msg);
405
+ return Promise.reject(new Error(msg));
406
+ }
407
+ }
408
+ async simpleDescriptor(networkAddress, endpointID) {
409
+ const transactionID = this.nextTransactionID();
410
+ const nwk1 = networkAddress & 0xff;
411
+ const nwk2 = (networkAddress >> 8) & 0xff;
412
+ const request = {};
413
+ const zdpFrame = [transactionID, nwk1, nwk2, endpointID];
414
+ request.requestId = transactionID;
415
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
416
+ request.destAddr16 = networkAddress;
417
+ request.destEndpoint = 0;
418
+ request.profileId = 0;
419
+ request.clusterId = 0x04; // simple descriptor
420
+ request.srcEndpoint = 0;
421
+ request.asduLength = 4;
422
+ request.asduPayload = zdpFrame;
423
+ request.txOptions = 0;
424
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
425
+ request.timeout = 30;
426
+ this.driver.enqueueSendDataRequest(request)
427
+ .then(result => { })
428
+ .catch(error => { });
429
+ try {
430
+ const d = await this.waitForData(networkAddress, 0, 0x8004);
431
+ const data = d.asduPayload;
432
+ const buf = Buffer.from(data);
433
+ const inCount = buf.readUInt8(11);
434
+ const inClusters = [];
435
+ let cIndex = 12;
436
+ for (let i = 0; i < inCount; i++) {
437
+ inClusters[i] = buf.readUInt16LE(cIndex);
438
+ cIndex += 2;
439
+ }
440
+ const outCount = buf.readUInt8(12 + (inCount * 2));
441
+ const outClusters = [];
442
+ cIndex = 13 + (inCount * 2);
443
+ for (let l = 0; l < outCount; l++) {
444
+ outClusters[l] = buf.readUInt16LE(cIndex);
445
+ cIndex += 2;
446
+ }
447
+ const simpleDesc = {
448
+ profileID: buf.readUInt16LE(6),
449
+ endpointID: buf.readUInt8(5),
450
+ deviceID: buf.readUInt16LE(8),
451
+ inputClusters: inClusters,
452
+ outputClusters: outClusters
453
+ };
454
+ debug("RECEIVING SIMPLE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16) + " EP:" + simpleDesc.endpointID + " inClusters: " + inClusters + " outClusters: " + outClusters);
455
+ return simpleDesc;
456
+ }
457
+ catch (error) {
458
+ const msg = "RECEIVING SIMPLE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
459
+ debug(msg);
460
+ return Promise.reject(new Error(msg));
461
+ }
462
+ }
463
+ async checkCoordinatorSimpleDescriptor(skip) {
464
+ debug("checking coordinator simple descriptor");
465
+ var simpleDesc = null;
466
+ if (skip === false) {
467
+ try {
468
+ simpleDesc = await this.simpleDescriptor(0x0, 1);
469
+ }
470
+ catch (error) {
471
+ }
472
+ if (simpleDesc === null) {
473
+ this.checkCoordinatorSimpleDescriptor(false);
474
+ return;
475
+ }
476
+ debug("EP: " + simpleDesc.endpointID);
477
+ debug("profile ID: " + simpleDesc.profileID);
478
+ debug("device ID: " + simpleDesc.deviceID);
479
+ for (let i = 0; i < simpleDesc.inputClusters.length; i++) {
480
+ debug("input cluster: 0x" + simpleDesc.inputClusters[i].toString(16));
481
+ }
482
+ for (let o = 0; o < simpleDesc.outputClusters.length; o++) {
483
+ debug("output cluster: 0x" + simpleDesc.outputClusters[o].toString(16));
484
+ }
485
+ let ok = true;
486
+ if (simpleDesc.endpointID === 0x1) {
487
+ if (!simpleDesc.inputClusters.includes(0x0) || !simpleDesc.inputClusters.includes(0x0A) || !simpleDesc.inputClusters.includes(0x19) ||
488
+ !simpleDesc.outputClusters.includes(0x01) || !simpleDesc.outputClusters.includes(0x20) || !simpleDesc.outputClusters.includes(0x500)) {
489
+ debug("missing cluster");
490
+ ok = false;
491
+ }
492
+ if (ok === true) {
493
+ return;
494
+ }
495
+ }
496
+ }
497
+ debug("setting new simple descriptor");
498
+ try { //[ sd1 ep proId devId vers #inCl iCl1 iCl2 iCl3 #outC oCl1 oCl2 oCl3 ]
499
+ const sd = [0x00, 0x01, 0x04, 0x01, 0x05, 0x00, 0x01, 0x03, 0x00, 0x00, 0x0A, 0x00, 0x19, 0x00, 0x03, 0x01, 0x00, 0x20, 0x00, 0x00, 0x05];
500
+ const sd1 = sd.reverse();
501
+ await this.driver.writeParameterRequest(constants_1.default.PARAM.STK.Endpoint, sd1);
502
+ }
503
+ catch (error) {
504
+ debug("error setting simple descriptor - try again");
505
+ this.checkCoordinatorSimpleDescriptor(true);
506
+ return;
507
+ }
508
+ debug("success setting simple descriptor");
509
+ }
510
+ waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
511
+ const payload = {
512
+ address: networkAddress, endpoint, clusterID, commandIdentifier, frameType, direction,
513
+ transactionSequenceNumber,
514
+ };
515
+ const waiter = this.waitress.waitFor(payload, timeout);
516
+ const cancel = () => this.waitress.remove(waiter.ID);
517
+ return { promise: waiter.start().promise, cancel };
518
+ }
519
+ async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
520
+ const transactionID = this.nextTransactionID();
521
+ const request = {};
522
+ let pay = zclFrame.toBuffer();
523
+ //console.log("zclFramte.toBuffer:");
524
+ //console.log(pay);
525
+ request.requestId = transactionID;
526
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
527
+ request.destAddr16 = networkAddress;
528
+ request.destEndpoint = endpoint;
529
+ request.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xa1e0 : 0x104;
530
+ request.clusterId = zclFrame.Cluster.ID;
531
+ request.srcEndpoint = sourceEndpoint || 1;
532
+ request.asduLength = pay.length;
533
+ request.asduPayload = [...pay];
534
+ request.txOptions = this.TX_OPTIONS; // 0x00 normal; 0x04 APS ACK
535
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
536
+ request.timeout = timeout;
537
+ const command = zclFrame.getCommand();
538
+ this.driver.enqueueSendDataRequest(request)
539
+ .then(result => {
540
+ debug(`sendZclFrameToEndpoint - message send with transSeq Nr.: ${zclFrame.Header.transactionSequenceNumber}`);
541
+ debug(command.hasOwnProperty('response') + ", " + zclFrame.Header.frameControl.disableDefaultResponse + ", " + disableResponse + ", " + request.timeout);
542
+ if (!command.hasOwnProperty('response') || zclFrame.Header.frameControl.disableDefaultResponse || !disableResponse) {
543
+ debug(`resolve request (${zclFrame.Header.transactionSequenceNumber})`);
544
+ return Promise.resolve();
545
+ }
546
+ })
547
+ .catch(error => {
548
+ debug(`sendZclFrameToEndpoint ERROR (${zclFrame.Header.transactionSequenceNumber})`);
549
+ debug(error);
550
+ //return Promise.reject(new Error("sendZclFrameToEndpoint ERROR " + error));
551
+ });
552
+ try {
553
+ let data = null;
554
+ if ((command.hasOwnProperty('response') && !disableResponse) || !zclFrame.Header.frameControl.disableDefaultResponse) {
555
+ data = await this.waitForData(networkAddress, 0x104, zclFrame.Cluster.ID, zclFrame.Header.transactionSequenceNumber, request.timeout);
556
+ }
557
+ if (data !== null) {
558
+ const asdu = data.asduPayload;
559
+ const buffer = Buffer.from(asdu);
560
+ const frame = zcl_1.ZclFrame.fromBuffer(zclFrame.Cluster.ID, buffer);
561
+ const response = {
562
+ address: (data.srcAddrMode === 0x02) ? data.srcAddr16 : null,
563
+ frame: frame,
564
+ endpoint: data.srcEndpoint,
565
+ linkquality: data.lqi,
566
+ groupID: (data.srcAddrMode === 0x01) ? data.srcAddr16 : null,
567
+ wasBroadcast: data.srcAddrMode === 0x01 || data.srcAddrMode === 0xF,
568
+ destinationEndpoint: data.destEndpoint,
569
+ };
570
+ debug(`response received (${zclFrame.Header.transactionSequenceNumber})`);
571
+ return response;
572
+ }
573
+ else {
574
+ debug(`no response expected (${zclFrame.Header.transactionSequenceNumber})`);
575
+ return null;
576
+ }
577
+ }
578
+ catch (error) {
579
+ throw new Error(`no response received (${zclFrame.Header.transactionSequenceNumber})`);
580
+ }
581
+ }
582
+ async sendZclFrameToGroup(groupID, zclFrame) {
583
+ const transactionID = this.nextTransactionID();
584
+ const request = {};
585
+ let pay = zclFrame.toBuffer();
586
+ debug("zclFrame to group - zclFrame.payload:");
587
+ debug(zclFrame.Payload);
588
+ //console.log("zclFramte.toBuffer:");
589
+ //console.log(pay);
590
+ request.requestId = transactionID;
591
+ request.destAddrMode = constants_1.default.PARAM.addressMode.GROUP_ADDR;
592
+ request.destAddr16 = groupID;
593
+ request.profileId = 0x104;
594
+ request.clusterId = zclFrame.Cluster.ID;
595
+ request.srcEndpoint = 1;
596
+ request.asduLength = pay.length;
597
+ request.asduPayload = [...pay];
598
+ request.txOptions = 0;
599
+ request.radius = constants_1.default.PARAM.txRadius.UNLIMITED;
600
+ try {
601
+ debug(`sendZclFrameToGroup - message send`);
602
+ return this.driver.enqueueSendDataRequest(request);
603
+ }
604
+ catch (error) {
605
+ //debug(`sendZclFrameToGroup ERROR: ${error}`);
606
+ throw new Error(error);
607
+ }
608
+ }
609
+ async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
610
+ const transactionID = this.nextTransactionID();
611
+ const request = {};
612
+ let pay = zclFrame.toBuffer();
613
+ debug("zclFrame to all - zclFrame.payload:");
614
+ debug(zclFrame.Payload);
615
+ request.requestId = transactionID;
616
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
617
+ request.destAddr16 = 0xFFFD;
618
+ request.destEndpoint = endpoint;
619
+ request.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xa1e0 : 0x104;
620
+ request.clusterId = zclFrame.Cluster.ID;
621
+ request.srcEndpoint = sourceEndpoint;
622
+ request.asduLength = pay.length;
623
+ request.asduPayload = [...pay];
624
+ request.txOptions = 0;
625
+ request.radius = constants_1.default.PARAM.txRadius.UNLIMITED;
626
+ try {
627
+ debug(`sendZclFrameToAll - message send`);
628
+ return this.driver.enqueueSendDataRequest(request);
629
+ }
630
+ catch (error) {
631
+ //debug(`sendZclFrameToAll ERROR: ${error}`);
632
+ throw new Error(error);
633
+ }
634
+ }
635
+ async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
636
+ const transactionID = this.nextTransactionID();
637
+ const clid1 = clusterID & 0xff;
638
+ const clid2 = (clusterID >> 8) & 0xff;
639
+ const destAddrMode = (type === 'group') ? constants_1.default.PARAM.addressMode.GROUP_ADDR : constants_1.default.PARAM.addressMode.IEEE_ADDR;
640
+ let destArray;
641
+ if (type === 'endpoint') {
642
+ destArray = this.driver.macAddrStringToArray(destinationAddressOrGroup);
643
+ destArray = destArray.concat([destinationEndpoint]);
644
+ }
645
+ else {
646
+ destArray = [destinationAddressOrGroup, (destinationAddressOrGroup >> 8) & 0xff];
647
+ }
648
+ const request = {};
649
+ const zdpFrame = [transactionID].concat(this.driver.macAddrStringToArray(sourceIeeeAddress)).concat([sourceEndpoint, clid1, clid2, destAddrMode]).concat(destArray);
650
+ request.requestId = transactionID;
651
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
652
+ request.destAddr16 = destinationNetworkAddress;
653
+ request.destEndpoint = 0;
654
+ request.profileId = 0;
655
+ request.clusterId = 0x21; // bind_request
656
+ request.srcEndpoint = 0;
657
+ request.asduLength = zdpFrame.length;
658
+ request.asduPayload = zdpFrame;
659
+ request.txOptions = 0x04; // 0x04 use APS ACKS
660
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
661
+ request.timeout = 30;
662
+ this.driver.enqueueSendDataRequest(request)
663
+ .then(result => { })
664
+ .catch(error => { });
665
+ try {
666
+ const d = await this.waitForData(destinationNetworkAddress, 0, 0x8021);
667
+ const data = d.asduPayload;
668
+ debug("BIND RESPONSE - addr: 0x" + destinationNetworkAddress.toString(16) + " status: " + data[1]);
669
+ if (data[1] !== 0) {
670
+ throw new Error("status: " + data[1]);
671
+ }
672
+ }
673
+ catch (error) {
674
+ debug("BIND FAILED - addr: 0x" + destinationNetworkAddress.toString(16) + " " + error);
675
+ throw new Error(error);
676
+ }
677
+ }
678
+ async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
679
+ const transactionID = this.nextTransactionID();
680
+ const clid1 = clusterID & 0xff;
681
+ const clid2 = (clusterID >> 8) & 0xff;
682
+ const destAddrMode = (type === 'group') ? constants_1.default.PARAM.addressMode.GROUP_ADDR : constants_1.default.PARAM.addressMode.IEEE_ADDR;
683
+ let destArray;
684
+ if (type === 'endpoint') {
685
+ destArray = this.driver.macAddrStringToArray(destinationAddressOrGroup);
686
+ destArray = destArray.concat([destinationEndpoint]);
687
+ }
688
+ else {
689
+ destArray = [destinationAddressOrGroup, (destinationAddressOrGroup >> 8) & 0xff];
690
+ }
691
+ const request = {};
692
+ const zdpFrame = [transactionID].concat(this.driver.macAddrStringToArray(sourceIeeeAddress)).concat([sourceEndpoint, clid1, clid2, destAddrMode]).concat(destArray);
693
+ request.requestId = transactionID;
694
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
695
+ request.destAddr16 = destinationNetworkAddress;
696
+ request.destEndpoint = 0;
697
+ request.profileId = 0;
698
+ request.clusterId = 0x22; // unbind_request
699
+ request.srcEndpoint = 0;
700
+ request.asduLength = zdpFrame.length;
701
+ request.asduPayload = zdpFrame;
702
+ request.txOptions = 0x04; // 0x04 use APS ACKS
703
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
704
+ request.timeout = 30;
705
+ this.driver.enqueueSendDataRequest(request)
706
+ .then(result => { })
707
+ .catch(error => { });
708
+ try {
709
+ const d = await this.waitForData(destinationNetworkAddress, 0, 0x8022);
710
+ const data = d.asduPayload;
711
+ debug("UNBIND RESPONSE - addr: 0x" + destinationNetworkAddress.toString(16) + " status: " + data[1]);
712
+ if (data[1] !== 0) {
713
+ throw new Error("status: " + data[1]);
714
+ }
715
+ }
716
+ catch (error) {
717
+ debug("UNBIND FAILED - addr: 0x" + destinationNetworkAddress.toString(16) + " " + error);
718
+ throw new Error(error);
719
+ }
720
+ }
721
+ async removeDevice(networkAddress, ieeeAddr) {
722
+ const transactionID = this.nextTransactionID();
723
+ const nwk1 = networkAddress & 0xff;
724
+ const nwk2 = (networkAddress >> 8) & 0xff;
725
+ const request = {};
726
+ //const zdpFrame = [transactionID].concat(this.driver.macAddrStringToArray(ieeeAddr)).concat([0]);
727
+ const zdpFrame = [transactionID].concat([0, 0, 0, 0, 0, 0, 0, 0]).concat([0]);
728
+ request.requestId = transactionID;
729
+ request.destAddrMode = constants_1.default.PARAM.addressMode.NWK_ADDR;
730
+ request.destAddr16 = networkAddress;
731
+ request.destEndpoint = 0;
732
+ request.profileId = 0;
733
+ request.clusterId = 0x34; // mgmt_leave_request
734
+ request.srcEndpoint = 0;
735
+ request.asduLength = 10;
736
+ request.asduPayload = zdpFrame;
737
+ request.txOptions = 0;
738
+ request.radius = constants_1.default.PARAM.txRadius.DEFAULT_RADIUS;
739
+ this.driver.enqueueSendDataRequest(request)
740
+ .then(result => { })
741
+ .catch(error => { });
742
+ try {
743
+ const d = await this.waitForData(networkAddress, 0, 0x8034);
744
+ const data = d.asduPayload;
745
+ debug("REMOVE_DEVICE - addr: 0x" + networkAddress.toString(16) + " status: " + data[1]);
746
+ const payload = {
747
+ networkAddress: networkAddress,
748
+ ieeeAddr: ieeeAddr,
749
+ };
750
+ if (data[1] !== 0) {
751
+ throw new Error("status: " + data[1]);
752
+ }
753
+ this.emit(Events.Events.deviceLeave, payload);
754
+ }
755
+ catch (error) {
756
+ debug("REMOVE_DEVICE FAILED - addr: 0x" + networkAddress.toString(16) + " " + error);
757
+ throw new Error(error);
758
+ }
759
+ }
760
+ async supportsBackup() {
761
+ return false;
762
+ }
763
+ async backup() {
764
+ throw new Error("This adapter does not support backup");
765
+ }
766
+ async getNetworkParameters() {
767
+ try {
768
+ let panid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.PAN_ID);
769
+ let expanid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.APS_EXT_PAN_ID);
770
+ let channel = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.CHANNEL);
771
+ let networkKey = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.NETWORK_KEY);
772
+ // check current channel against configuration.yaml
773
+ if (this.networkOptions.channelList[0] !== channel) {
774
+ debug("Channel in configuration.yaml (" + this.networkOptions.channelList[0] + ") differs from current channel (" + channel + "). Changing channel.");
775
+ let setChannelMask = 0;
776
+ switch (this.networkOptions.channelList[0]) {
777
+ case 11:
778
+ setChannelMask = 0x800;
779
+ break;
780
+ case 12:
781
+ setChannelMask = 0x1000;
782
+ break;
783
+ case 13:
784
+ setChannelMask = 0x2000;
785
+ break;
786
+ case 14:
787
+ setChannelMask = 0x4000;
788
+ break;
789
+ case 15:
790
+ setChannelMask = 0x8000;
791
+ break;
792
+ case 16:
793
+ setChannelMask = 0x10000;
794
+ break;
795
+ case 17:
796
+ setChannelMask = 0x20000;
797
+ break;
798
+ case 18:
799
+ setChannelMask = 0x40000;
800
+ break;
801
+ case 19:
802
+ setChannelMask = 0x80000;
803
+ break;
804
+ case 20:
805
+ setChannelMask = 0x100000;
806
+ break;
807
+ case 21:
808
+ setChannelMask = 0x200000;
809
+ break;
810
+ case 22:
811
+ setChannelMask = 0x400000;
812
+ break;
813
+ case 23:
814
+ setChannelMask = 0x800000;
815
+ break;
816
+ case 24:
817
+ setChannelMask = 0x1000000;
818
+ break;
819
+ case 25:
820
+ setChannelMask = 0x2000000;
821
+ break;
822
+ case 26:
823
+ setChannelMask = 0x4000000;
824
+ break;
825
+ default:
826
+ break;
827
+ }
828
+ try {
829
+ await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.CHANNEL_MASK, setChannelMask);
830
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
831
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
832
+ await this.sleep(3000);
833
+ channel = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.CHANNEL);
834
+ }
835
+ catch (error) {
836
+ debug("Could not set channel: " + error);
837
+ }
838
+ }
839
+ // check current panid against configuration.yaml
840
+ if (this.networkOptions.panID !== panid) {
841
+ debug("panid in configuration.yaml (" + this.networkOptions.panID + ") differs from current panid (" + panid + "). Changing panid.");
842
+ try {
843
+ await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.PAN_ID, this.networkOptions.panID);
844
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
845
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
846
+ await this.sleep(3000);
847
+ panid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.PAN_ID);
848
+ }
849
+ catch (error) {
850
+ debug("Could not set panid: " + error);
851
+ }
852
+ }
853
+ // check current extended_panid against configuration.yaml
854
+ if (this.driver.generalArrayToString(this.networkOptions.extendedPanID, 8) !== expanid) {
855
+ debug("extended panid in configuration.yaml (" + this.driver.macAddrArrayToString(this.networkOptions.extendedPanID) + ") differs from current extended panid (" + expanid + "). Changing extended panid.");
856
+ try {
857
+ //await this.driver.writeParameterRequest(PARAM.PARAM.Network.USE_APS_EXT_PAN_ID, 1);
858
+ await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.APS_EXT_PAN_ID, this.networkOptions.extendedPanID);
859
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
860
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
861
+ await this.sleep(3000);
862
+ expanid = await this.driver.readParameterRequest(constants_1.default.PARAM.Network.APS_EXT_PAN_ID);
863
+ }
864
+ catch (error) {
865
+ debug("Could not set extended panid: " + error);
866
+ }
867
+ }
868
+ // check current network key against configuration.yaml
869
+ if (this.driver.generalArrayToString(this.networkOptions.networkKey, 16) !== networkKey) {
870
+ debug("network key in configuration.yaml (hidden) differs from current network key (" + networkKey + "). Changing network key.");
871
+ try {
872
+ await this.driver.writeParameterRequest(constants_1.default.PARAM.Network.NETWORK_KEY, this.networkOptions.networkKey);
873
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_OFFLINE);
874
+ await this.driver.changeNetworkStateRequest(constants_1.default.PARAM.Network.NET_CONNECTED);
875
+ await this.sleep(3000);
876
+ }
877
+ catch (error) {
878
+ debug("Could not set network key: " + error);
879
+ }
880
+ }
881
+ return {
882
+ panID: panid,
883
+ extendedPanID: expanid,
884
+ channel: channel
885
+ };
886
+ }
887
+ catch (error) {
888
+ const msg = "get network parameters Error:" + error;
889
+ debug(msg);
890
+ return Promise.reject(new Error(msg));
891
+ }
892
+ }
893
+ async restoreChannelInterPAN() {
894
+ throw new Error("not supported");
895
+ }
896
+ async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddr) {
897
+ throw new Error("not supported");
898
+ }
899
+ async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
900
+ throw new Error("not supported");
901
+ }
902
+ async sendZclFrameInterPANBroadcastWithResponse(zclFrame, timeout) {
903
+ throw new Error("not supported");
904
+ }
905
+ async setChannelInterPAN(channel) {
906
+ throw new Error("not supported");
907
+ }
908
+ async setTransmitPower(value) {
909
+ throw new Error("not supported");
910
+ }
911
+ async sendZclFrameInterPANIeeeAddr(zclFrame, ieeeAddr) {
912
+ throw new Error("not supported");
913
+ }
914
+ /**
915
+ * Private methods
916
+ */
917
+ sleep(ms) {
918
+ return new Promise(resolve => setTimeout(resolve, ms));
919
+ }
920
+ waitForData(addr, profileId, clusterId, transactionSequenceNumber, timeout) {
921
+ return new Promise((resolve, reject) => {
922
+ const ts = Date.now();
923
+ const commandId = constants_1.default.PARAM.APS.DATA_INDICATION;
924
+ const req = { addr, profileId, clusterId, transactionSequenceNumber, resolve, reject, ts, timeout };
925
+ this.openRequestsQueue.push(req);
926
+ });
927
+ }
928
+ checkReceivedGreenPowerIndication(ind) {
929
+ ind.clusterId = 0x21;
930
+ let gpFrame = [ind.rspId, ind.seqNr, ind.id,
931
+ 0, 0,
932
+ // ind.options & 0xff, (ind.options >> 8) & 0xff,
933
+ ind.srcId & 0xff, (ind.srcId >> 8) & 0xff, (ind.srcId >> 16) & 0xff, (ind.srcId >> 24) & 0xff,
934
+ ind.frameCounter & 0xff, (ind.frameCounter >> 8) & 0xff, (ind.frameCounter >> 16) & 0xff, (ind.frameCounter >> 24) & 0xff,
935
+ ind.commandId, ind.commandFrameSize].concat(ind.commandFrame);
936
+ const payBuf = Buffer.from(gpFrame);
937
+ const payload = {
938
+ frame: zcl_1.ZclFrame.fromBuffer(ind.clusterId, payBuf),
939
+ address: ind.srcId,
940
+ endpoint: 242,
941
+ linkquality: 127,
942
+ groupID: 0x0b84,
943
+ wasBroadcast: false,
944
+ destinationEndpoint: 1,
945
+ };
946
+ this.waitress.resolve(payload);
947
+ this.emit(Events.Events.zclData, payload);
948
+ }
949
+ checkReceivedDataPayload(resp) {
950
+ var _a;
951
+ let srcAddr = null;
952
+ let frame = null;
953
+ if (resp != null) {
954
+ srcAddr = (resp.srcAddr16 != null) ? resp.srcAddr16 : resp.srcAddr64;
955
+ if (resp.profileId != 0x00) {
956
+ try {
957
+ frame = zcl_1.ZclFrame.fromBuffer(resp.clusterId, Buffer.from(resp.asduPayload));
958
+ }
959
+ catch (error) {
960
+ debug("could not parse zclFrame: " + error);
961
+ }
962
+ }
963
+ }
964
+ let i = this.openRequestsQueue.length;
965
+ while (i--) {
966
+ const req = this.openRequestsQueue[i];
967
+ if (srcAddr != null && req.addr === srcAddr && req.clusterId === resp.clusterId &&
968
+ req.profileId === resp.profileId) {
969
+ if (frame !== null && req.transactionSequenceNumber !== null && req.transactionSequenceNumber !== undefined) {
970
+ if (req.transactionSequenceNumber === frame.Header.transactionSequenceNumber) {
971
+ debug("resolve data request with transSeq Nr.: " + req.transactionSequenceNumber);
972
+ this.openRequestsQueue.splice(i, 1);
973
+ req.resolve(resp);
974
+ }
975
+ }
976
+ else {
977
+ debug("resolve data request without a transSeq Nr.");
978
+ this.openRequestsQueue.splice(i, 1);
979
+ req.resolve(resp);
980
+ }
981
+ }
982
+ const now = Date.now();
983
+ // Default timeout: 60 seconds.
984
+ // Comparison is negated to prevent orphans when invalid timeout is entered (resulting in NaN).
985
+ if (!((now - req.ts) <= ((_a = req.timeout) !== null && _a !== void 0 ? _a : 60000))) {
986
+ //debug("Timeout for request in openRequestsQueue addr: " + req.addr.toString(16) + " clusterId: " + req.clusterId.toString(16) + " profileId: " + req.profileId.toString(16));
987
+ //remove from busyQueue
988
+ this.openRequestsQueue.splice(i, 1);
989
+ req.reject("waiting for response TIMEOUT");
990
+ }
991
+ }
992
+ // check unattended incomming messages
993
+ if (resp != null && resp.profileId === 0x00 && resp.clusterId === 0x13) {
994
+ // device Annce
995
+ const payBuf = Buffer.from(resp.asduPayload);
996
+ const payload = {
997
+ networkAddress: payBuf.readUInt16LE(1),
998
+ ieeeAddr: this.driver.macAddrArrayToString(resp.asduPayload.slice(3, 11)),
999
+ };
1000
+ if (this.joinPermitted === true) {
1001
+ this.emit(Events.Events.deviceJoined, payload);
1002
+ }
1003
+ else {
1004
+ this.emit(Events.Events.deviceAnnounce, payload);
1005
+ }
1006
+ }
1007
+ if (resp != null && resp.profileId != 0x00) {
1008
+ const payBuf = Buffer.from(resp.asduPayload);
1009
+ try {
1010
+ const payload = {
1011
+ frame: zcl_1.ZclFrame.fromBuffer(resp.clusterId, payBuf),
1012
+ address: (resp.destAddrMode === 0x03) ? resp.srcAddr64 : resp.srcAddr16,
1013
+ endpoint: resp.srcEndpoint,
1014
+ linkquality: resp.lqi,
1015
+ groupID: (resp.destAddrMode === 0x01) ? resp.destAddr16 : null,
1016
+ wasBroadcast: resp.destAddrMode === 0x01 || resp.destAddrMode === 0xF,
1017
+ destinationEndpoint: resp.destEndpoint,
1018
+ };
1019
+ this.waitress.resolve(payload);
1020
+ this.emit(Events.Events.zclData, payload);
1021
+ }
1022
+ catch (error) {
1023
+ const payload = {
1024
+ clusterID: resp.clusterId,
1025
+ data: payBuf,
1026
+ address: (resp.destAddrMode === 0x03) ? resp.srcAddr64 : resp.srcAddr16,
1027
+ endpoint: resp.srcEndpoint,
1028
+ linkquality: resp.lqi,
1029
+ groupID: (resp.destAddrMode === 0x01) ? resp.destAddr16 : null,
1030
+ wasBroadcast: resp.destAddrMode === 0x01 || resp.destAddrMode === 0xF,
1031
+ destinationEndpoint: resp.destEndpoint,
1032
+ };
1033
+ this.emit(Events.Events.rawData, payload);
1034
+ }
1035
+ }
1036
+ }
1037
+ nextTransactionID() {
1038
+ this.transactionID++;
1039
+ if (this.transactionID > 255) {
1040
+ this.transactionID = 1;
1041
+ }
1042
+ return this.transactionID;
1043
+ }
1044
+ waitressTimeoutFormatter(matcher, timeout) {
1045
+ return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
1046
+ ` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
1047
+ ` - ${matcher.commandIdentifier} after ${timeout}ms`;
1048
+ }
1049
+ waitressValidator(payload, matcher) {
1050
+ const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
1051
+ return (!matcher.address || payload.address === matcher.address) &&
1052
+ payload.endpoint === matcher.endpoint &&
1053
+ (!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
1054
+ payload.frame.Cluster.ID === matcher.clusterID &&
1055
+ matcher.frameType === payload.frame.Header.frameControl.frameType &&
1056
+ matcher.commandIdentifier === payload.frame.Header.commandIdentifier &&
1057
+ matcher.direction === payload.frame.Header.frameControl.direction;
1058
+ }
1059
+ }
1060
+ exports.default = DeconzAdapter;
1061
1061
  //# sourceMappingURL=deconzAdapter.js.map