@willieee802/zigbee-herdsman 0.19.21 → 0.36.0

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