@willieee802/zigbee-herdsman 0.15.0 → 0.15.1

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 (345) hide show
  1. package/dist/adapter/adapter.d.ts +61 -61
  2. package/dist/adapter/adapter.d.ts.map +1 -1
  3. package/dist/adapter/adapter.js +146 -100
  4. package/dist/adapter/adapter.js.map +1 -1
  5. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts +68 -68
  6. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts.map +1 -1
  7. package/dist/adapter/deconz/adapter/deconzAdapter.js +1060 -1063
  8. package/dist/adapter/deconz/adapter/deconzAdapter.js.map +1 -1
  9. package/dist/adapter/deconz/adapter/index.d.ts +2 -2
  10. package/dist/adapter/deconz/adapter/index.js +10 -10
  11. package/dist/adapter/deconz/driver/constants.d.ts +104 -104
  12. package/dist/adapter/deconz/driver/constants.js +55 -55
  13. package/dist/adapter/deconz/driver/driver.d.ts +81 -81
  14. package/dist/adapter/deconz/driver/driver.js +732 -732
  15. package/dist/adapter/deconz/driver/frame.d.ts +6 -6
  16. package/dist/adapter/deconz/driver/frame.js +13 -13
  17. package/dist/adapter/deconz/driver/frameParser.d.ts +2 -2
  18. package/dist/adapter/deconz/driver/frameParser.js +443 -443
  19. package/dist/adapter/deconz/driver/parser.d.ts +12 -12
  20. package/dist/adapter/deconz/driver/parser.js +61 -61
  21. package/dist/adapter/deconz/driver/writer.d.ts +8 -8
  22. package/dist/adapter/deconz/driver/writer.js +44 -44
  23. package/dist/adapter/events.d.ts +47 -47
  24. package/dist/adapter/events.js +14 -14
  25. package/dist/adapter/ezsp/adapter/backup.d.ts +9 -9
  26. package/dist/adapter/ezsp/adapter/backup.js +53 -53
  27. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts +59 -59
  28. package/dist/adapter/ezsp/adapter/ezspAdapter.js +585 -585
  29. package/dist/adapter/ezsp/adapter/index.d.ts +2 -2
  30. package/dist/adapter/ezsp/adapter/index.js +10 -10
  31. package/dist/adapter/ezsp/driver/commands.d.ts +36 -34
  32. package/dist/adapter/ezsp/driver/commands.d.ts.map +1 -1
  33. package/dist/adapter/ezsp/driver/commands.js +2359 -2357
  34. package/dist/adapter/ezsp/driver/commands.js.map +1 -1
  35. package/dist/adapter/ezsp/driver/consts.d.ts +10 -10
  36. package/dist/adapter/ezsp/driver/consts.js +13 -13
  37. package/dist/adapter/ezsp/driver/driver.d.ts +103 -103
  38. package/dist/adapter/ezsp/driver/driver.js +639 -639
  39. package/dist/adapter/ezsp/driver/driver.js.map +1 -1
  40. package/dist/adapter/ezsp/driver/ezsp.d.ts +96 -96
  41. package/dist/adapter/ezsp/driver/ezsp.d.ts.map +1 -1
  42. package/dist/adapter/ezsp/driver/ezsp.js +586 -577
  43. package/dist/adapter/ezsp/driver/ezsp.js.map +1 -1
  44. package/dist/adapter/ezsp/driver/index.d.ts +3 -3
  45. package/dist/adapter/ezsp/driver/index.js +8 -8
  46. package/dist/adapter/ezsp/driver/multicast.d.ts +12 -12
  47. package/dist/adapter/ezsp/driver/multicast.js +74 -74
  48. package/dist/adapter/ezsp/driver/parser.d.ts +12 -12
  49. package/dist/adapter/ezsp/driver/parser.js +111 -111
  50. package/dist/adapter/ezsp/driver/types/basic.d.ts +62 -62
  51. package/dist/adapter/ezsp/driver/types/basic.js +208 -208
  52. package/dist/adapter/ezsp/driver/types/basic.js.map +1 -1
  53. package/dist/adapter/ezsp/driver/types/index.d.ts +9 -9
  54. package/dist/adapter/ezsp/driver/types/index.js +133 -133
  55. package/dist/adapter/ezsp/driver/types/named.d.ts +697 -697
  56. package/dist/adapter/ezsp/driver/types/named.js +1726 -1726
  57. package/dist/adapter/ezsp/driver/types/named.js.map +1 -1
  58. package/dist/adapter/ezsp/driver/types/struct.d.ts +251 -251
  59. package/dist/adapter/ezsp/driver/types/struct.js +708 -708
  60. package/dist/adapter/ezsp/driver/types/struct.js.map +1 -1
  61. package/dist/adapter/ezsp/driver/uart.d.ts +44 -44
  62. package/dist/adapter/ezsp/driver/uart.d.ts.map +1 -1
  63. package/dist/adapter/ezsp/driver/uart.js +368 -366
  64. package/dist/adapter/ezsp/driver/uart.js.map +1 -1
  65. package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts +2 -2
  66. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js +55 -55
  67. package/dist/adapter/ezsp/driver/utils/index.d.ts +18 -18
  68. package/dist/adapter/ezsp/driver/utils/index.js +67 -67
  69. package/dist/adapter/ezsp/driver/writer.d.ts +13 -13
  70. package/dist/adapter/ezsp/driver/writer.js +88 -88
  71. package/dist/adapter/index.d.ts +4 -4
  72. package/dist/adapter/index.js +35 -35
  73. package/dist/adapter/serialPort.d.ts +8 -8
  74. package/dist/adapter/serialPort.js +22 -22
  75. package/dist/adapter/serialPort.js.map +1 -1
  76. package/dist/adapter/serialPortUtils.d.ts +12 -12
  77. package/dist/adapter/serialPortUtils.js +18 -18
  78. package/dist/adapter/socketPortUtils.d.ts +10 -10
  79. package/dist/adapter/socketPortUtils.js +16 -16
  80. package/dist/adapter/tstype.d.ts +85 -85
  81. package/dist/adapter/tstype.js +2 -2
  82. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts +62 -62
  83. package/dist/adapter/z-stack/adapter/adapter-backup.js +441 -441
  84. package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts +150 -150
  85. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js +258 -258
  86. package/dist/adapter/z-stack/adapter/endpoints.d.ts +11 -11
  87. package/dist/adapter/z-stack/adapter/endpoints.js +73 -73
  88. package/dist/adapter/z-stack/adapter/index.d.ts +2 -2
  89. package/dist/adapter/z-stack/adapter/index.js +8 -8
  90. package/dist/adapter/z-stack/adapter/manager.d.ts +86 -86
  91. package/dist/adapter/z-stack/adapter/manager.js +476 -476
  92. package/dist/adapter/z-stack/adapter/tstype.d.ts +6 -6
  93. package/dist/adapter/z-stack/adapter/tstype.js +10 -10
  94. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts +81 -81
  95. package/dist/adapter/z-stack/adapter/zStackAdapter.js +868 -868
  96. package/dist/adapter/z-stack/constants/af.d.ts +23 -23
  97. package/dist/adapter/z-stack/constants/af.js +27 -27
  98. package/dist/adapter/z-stack/constants/common.d.ts +278 -278
  99. package/dist/adapter/z-stack/constants/common.js +289 -289
  100. package/dist/adapter/z-stack/constants/dbg.d.ts +22 -22
  101. package/dist/adapter/z-stack/constants/dbg.js +24 -24
  102. package/dist/adapter/z-stack/constants/index.d.ts +10 -10
  103. package/dist/adapter/z-stack/constants/index.js +47 -47
  104. package/dist/adapter/z-stack/constants/mac.d.ts +127 -127
  105. package/dist/adapter/z-stack/constants/mac.js +129 -129
  106. package/dist/adapter/z-stack/constants/sapi.d.ts +24 -24
  107. package/dist/adapter/z-stack/constants/sapi.js +26 -26
  108. package/dist/adapter/z-stack/constants/sys.d.ts +71 -71
  109. package/dist/adapter/z-stack/constants/sys.js +73 -73
  110. package/dist/adapter/z-stack/constants/util.d.ts +81 -81
  111. package/dist/adapter/z-stack/constants/util.js +83 -83
  112. package/dist/adapter/z-stack/constants/utils.d.ts +4 -4
  113. package/dist/adapter/z-stack/constants/utils.js +14 -14
  114. package/dist/adapter/z-stack/constants/zdo.d.ts +102 -102
  115. package/dist/adapter/z-stack/constants/zdo.js +104 -104
  116. package/dist/adapter/z-stack/models/index.d.ts +1 -1
  117. package/dist/adapter/z-stack/models/index.js +17 -17
  118. package/dist/adapter/z-stack/models/startup-options.d.ts +12 -12
  119. package/dist/adapter/z-stack/models/startup-options.js +2 -2
  120. package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts +23 -23
  121. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js +45 -45
  122. package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts +10 -10
  123. package/dist/adapter/z-stack/structs/entries/address-manager-table.js +22 -22
  124. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts +10 -10
  125. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js +21 -21
  126. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts +10 -10
  127. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js +23 -23
  128. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts +10 -10
  129. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js +24 -24
  130. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts +10 -10
  131. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js +23 -23
  132. package/dist/adapter/z-stack/structs/entries/channel-list.d.ts +8 -8
  133. package/dist/adapter/z-stack/structs/entries/channel-list.js +15 -15
  134. package/dist/adapter/z-stack/structs/entries/has-configured.d.ts +8 -8
  135. package/dist/adapter/z-stack/structs/entries/has-configured.js +16 -16
  136. package/dist/adapter/z-stack/structs/entries/index.d.ts +16 -16
  137. package/dist/adapter/z-stack/structs/entries/index.js +32 -32
  138. package/dist/adapter/z-stack/structs/entries/nib.d.ts +10 -10
  139. package/dist/adapter/z-stack/structs/entries/nib.js +68 -68
  140. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts +10 -10
  141. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js +18 -18
  142. package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts +8 -8
  143. package/dist/adapter/z-stack/structs/entries/nwk-key.js +15 -15
  144. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts +8 -8
  145. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js +15 -15
  146. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts +13 -13
  147. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js +23 -23
  148. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts +10 -10
  149. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js +22 -22
  150. package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts +20 -20
  151. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js +36 -36
  152. package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts +10 -10
  153. package/dist/adapter/z-stack/structs/entries/security-manager-table.js +24 -24
  154. package/dist/adapter/z-stack/structs/index.d.ts +4 -4
  155. package/dist/adapter/z-stack/structs/index.js +20 -20
  156. package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts +13 -13
  157. package/dist/adapter/z-stack/structs/serializable-memory-object.js +2 -2
  158. package/dist/adapter/z-stack/structs/struct.d.ts +99 -99
  159. package/dist/adapter/z-stack/structs/struct.js +295 -295
  160. package/dist/adapter/z-stack/structs/table.d.ts +94 -94
  161. package/dist/adapter/z-stack/structs/table.js +161 -161
  162. package/dist/adapter/z-stack/unpi/constants.d.ts +28 -28
  163. package/dist/adapter/z-stack/unpi/constants.js +41 -41
  164. package/dist/adapter/z-stack/unpi/frame.d.ts +16 -16
  165. package/dist/adapter/z-stack/unpi/frame.js +48 -48
  166. package/dist/adapter/z-stack/unpi/index.d.ts +5 -5
  167. package/dist/adapter/z-stack/unpi/index.js +37 -37
  168. package/dist/adapter/z-stack/unpi/parser.d.ts +10 -10
  169. package/dist/adapter/z-stack/unpi/parser.js +74 -74
  170. package/dist/adapter/z-stack/unpi/writer.d.ts +10 -10
  171. package/dist/adapter/z-stack/unpi/writer.js +44 -44
  172. package/dist/adapter/z-stack/utils/channel-list.d.ts +20 -20
  173. package/dist/adapter/z-stack/utils/channel-list.js +40 -40
  174. package/dist/adapter/z-stack/utils/index.d.ts +2 -2
  175. package/dist/adapter/z-stack/utils/index.js +18 -18
  176. package/dist/adapter/z-stack/utils/network-options.d.ts +8 -8
  177. package/dist/adapter/z-stack/utils/network-options.js +22 -22
  178. package/dist/adapter/z-stack/znp/buffaloZnp.d.ts +11 -11
  179. package/dist/adapter/z-stack/znp/buffaloZnp.js +113 -113
  180. package/dist/adapter/z-stack/znp/definition.d.ts +5 -5
  181. package/dist/adapter/z-stack/znp/definition.js +3050 -3050
  182. package/dist/adapter/z-stack/znp/index.d.ts +3 -3
  183. package/dist/adapter/z-stack/znp/index.js +10 -10
  184. package/dist/adapter/z-stack/znp/parameterType.d.ts +22 -22
  185. package/dist/adapter/z-stack/znp/parameterType.js +25 -25
  186. package/dist/adapter/z-stack/znp/tstype.d.ts +21 -21
  187. package/dist/adapter/z-stack/znp/tstype.js +2 -2
  188. package/dist/adapter/z-stack/znp/znp.d.ts +43 -43
  189. package/dist/adapter/z-stack/znp/znp.js +325 -325
  190. package/dist/adapter/z-stack/znp/zpiObject.d.ts +19 -19
  191. package/dist/adapter/z-stack/znp/zpiObject.js +96 -96
  192. package/dist/adapter/zigate/adapter/index.d.ts +2 -2
  193. package/dist/adapter/zigate/adapter/index.js +10 -10
  194. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts +69 -69
  195. package/dist/adapter/zigate/adapter/zigateAdapter.js +678 -678
  196. package/dist/adapter/zigate/debug.d.ts +7 -7
  197. package/dist/adapter/zigate/debug.js +22 -22
  198. package/dist/adapter/zigate/driver/buffaloZiGate.d.ts +18 -18
  199. package/dist/adapter/zigate/driver/buffaloZiGate.js +139 -139
  200. package/dist/adapter/zigate/driver/commandType.d.ts +41 -41
  201. package/dist/adapter/zigate/driver/commandType.js +385 -385
  202. package/dist/adapter/zigate/driver/constants.d.ts +276 -276
  203. package/dist/adapter/zigate/driver/constants.js +371 -371
  204. package/dist/adapter/zigate/driver/frame.d.ts +26 -26
  205. package/dist/adapter/zigate/driver/frame.js +172 -172
  206. package/dist/adapter/zigate/driver/frame.js.map +1 -1
  207. package/dist/adapter/zigate/driver/messageType.d.ts +11 -11
  208. package/dist/adapter/zigate/driver/messageType.js +278 -278
  209. package/dist/adapter/zigate/driver/parameterType.d.ts +20 -20
  210. package/dist/adapter/zigate/driver/parameterType.js +23 -23
  211. package/dist/adapter/zigate/driver/ziGateObject.d.ts +23 -23
  212. package/dist/adapter/zigate/driver/ziGateObject.js +106 -106
  213. package/dist/adapter/zigate/driver/zigate.d.ts +49 -49
  214. package/dist/adapter/zigate/driver/zigate.js +303 -303
  215. package/dist/buffalo/buffalo.d.ts +50 -48
  216. package/dist/buffalo/buffalo.d.ts.map +1 -1
  217. package/dist/buffalo/buffalo.js +322 -307
  218. package/dist/buffalo/buffalo.js.map +1 -1
  219. package/dist/buffalo/index.d.ts +3 -3
  220. package/dist/buffalo/index.js +33 -33
  221. package/dist/buffalo/tstype.d.ts +8 -8
  222. package/dist/buffalo/tstype.js +2 -2
  223. package/dist/controller/controller.d.ts +110 -110
  224. package/dist/controller/controller.js +607 -607
  225. package/dist/controller/database.d.ts +18 -18
  226. package/dist/controller/database.js +93 -93
  227. package/dist/controller/events.d.ts +55 -55
  228. package/dist/controller/events.d.ts.map +1 -1
  229. package/dist/controller/events.js +101 -99
  230. package/dist/controller/events.js.map +1 -1
  231. package/dist/controller/greenPower.d.ts +12 -12
  232. package/dist/controller/greenPower.js +220 -220
  233. package/dist/controller/helpers/index.d.ts +2 -2
  234. package/dist/controller/helpers/index.js +28 -28
  235. package/dist/controller/helpers/request.d.ts +23 -0
  236. package/dist/controller/helpers/request.d.ts.map +1 -0
  237. package/dist/controller/helpers/request.js +72 -0
  238. package/dist/controller/helpers/request.js.map +1 -0
  239. package/dist/controller/helpers/zclFrameConverter.d.ts +7 -7
  240. package/dist/controller/helpers/zclFrameConverter.js +31 -31
  241. package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts +5 -5
  242. package/dist/controller/helpers/zclTransactionSequenceNumber.js +13 -13
  243. package/dist/controller/index.d.ts +5 -5
  244. package/dist/controller/index.js +8 -8
  245. package/dist/controller/logger-stub.d.ts +6 -6
  246. package/dist/controller/logger-stub.js +2 -2
  247. package/dist/controller/model/device.d.ts +132 -127
  248. package/dist/controller/model/device.d.ts.map +1 -1
  249. package/dist/controller/model/device.js +708 -681
  250. package/dist/controller/model/device.js.map +1 -1
  251. package/dist/controller/model/endpoint.d.ts +131 -128
  252. package/dist/controller/model/endpoint.d.ts.map +1 -1
  253. package/dist/controller/model/endpoint.js +817 -665
  254. package/dist/controller/model/endpoint.js.map +1 -1
  255. package/dist/controller/model/entity.d.ts +14 -14
  256. package/dist/controller/model/entity.js +26 -26
  257. package/dist/controller/model/group.d.ts +39 -39
  258. package/dist/controller/model/group.js +221 -221
  259. package/dist/controller/model/index.d.ts +5 -5
  260. package/dist/controller/model/index.js +14 -14
  261. package/dist/controller/touchlink.d.ts +19 -19
  262. package/dist/controller/touchlink.js +157 -157
  263. package/dist/controller/tstype.d.ts +21 -20
  264. package/dist/controller/tstype.d.ts.map +1 -1
  265. package/dist/controller/tstype.js +9 -9
  266. package/dist/controller/tstype.js.map +1 -1
  267. package/dist/index.d.ts +3 -3
  268. package/dist/index.js +33 -33
  269. package/dist/models/backup-storage-legacy.d.ts +26 -26
  270. package/dist/models/backup-storage-legacy.js +2 -2
  271. package/dist/models/backup-storage-unified.d.ts +49 -49
  272. package/dist/models/backup-storage-unified.js +2 -2
  273. package/dist/models/backup.d.ts +37 -37
  274. package/dist/models/backup.js +2 -2
  275. package/dist/models/index.d.ts +4 -4
  276. package/dist/models/index.js +20 -20
  277. package/dist/models/network-options.d.ts +12 -12
  278. package/dist/models/network-options.js +2 -2
  279. package/dist/utils/assertString.d.ts +2 -2
  280. package/dist/utils/assertString.js +8 -8
  281. package/dist/utils/backup.d.ts +20 -20
  282. package/dist/utils/backup.js +187 -187
  283. package/dist/utils/equalsPartial.d.ts +2 -2
  284. package/dist/utils/equalsPartial.js +11 -11
  285. package/dist/utils/index.d.ts +9 -9
  286. package/dist/utils/index.js +45 -45
  287. package/dist/utils/isNumberArray.d.ts +2 -2
  288. package/dist/utils/isNumberArray.js +6 -6
  289. package/dist/utils/queue.d.ts +11 -11
  290. package/dist/utils/queue.js +50 -50
  291. package/dist/utils/realpathSync.d.ts +2 -2
  292. package/dist/utils/realpathSync.js +12 -12
  293. package/dist/utils/wait.d.ts +2 -2
  294. package/dist/utils/wait.js +8 -8
  295. package/dist/utils/waitress.d.ts +21 -21
  296. package/dist/utils/waitress.js +61 -61
  297. package/dist/zcl/buffaloZcl.d.ts +41 -41
  298. package/dist/zcl/buffaloZcl.js +591 -591
  299. package/dist/zcl/definition/buffaloZclDataType.d.ts +17 -17
  300. package/dist/zcl/definition/buffaloZclDataType.js +20 -20
  301. package/dist/zcl/definition/cluster.d.ts +29 -29
  302. package/dist/zcl/definition/cluster.d.ts.map +1 -1
  303. package/dist/zcl/definition/cluster.js +5335 -5215
  304. package/dist/zcl/definition/cluster.js.map +1 -1
  305. package/dist/zcl/definition/dataType.d.ts +59 -59
  306. package/dist/zcl/definition/dataType.d.ts.map +1 -1
  307. package/dist/zcl/definition/dataType.js +64 -64
  308. package/dist/zcl/definition/dataType.js.map +1 -1
  309. package/dist/zcl/definition/direction.d.ts +5 -5
  310. package/dist/zcl/definition/direction.js +8 -8
  311. package/dist/zcl/definition/endpointDeviceType.d.ts +4 -4
  312. package/dist/zcl/definition/endpointDeviceType.js +15 -15
  313. package/dist/zcl/definition/foundation.d.ts +11 -11
  314. package/dist/zcl/definition/foundation.js +167 -167
  315. package/dist/zcl/definition/frameControl.d.ts +10 -10
  316. package/dist/zcl/definition/frameControl.js +2 -2
  317. package/dist/zcl/definition/frameType.d.ts +5 -5
  318. package/dist/zcl/definition/frameType.js +8 -8
  319. package/dist/zcl/definition/index.d.ts +13 -13
  320. package/dist/zcl/definition/index.js +51 -51
  321. package/dist/zcl/definition/manufacturerCode.d.ts +1074 -1074
  322. package/dist/zcl/definition/manufacturerCode.js +1079 -1079
  323. package/dist/zcl/definition/powerSource.d.ts +4 -4
  324. package/dist/zcl/definition/powerSource.js +12 -12
  325. package/dist/zcl/definition/status.d.ts +38 -38
  326. package/dist/zcl/definition/status.js +41 -41
  327. package/dist/zcl/definition/tstype.d.ts +16 -16
  328. package/dist/zcl/definition/tstype.js +2 -2
  329. package/dist/zcl/index.d.ts +15 -15
  330. package/dist/zcl/index.js +55 -55
  331. package/dist/zcl/tstype.d.ts +56 -56
  332. package/dist/zcl/tstype.js +10 -10
  333. package/dist/zcl/utils.d.ts +6 -6
  334. package/dist/zcl/utils.js +165 -165
  335. package/dist/zcl/zclFrame.d.ts +45 -45
  336. package/dist/zcl/zclFrame.js +347 -347
  337. package/dist/zcl/zclStatusError.d.ts +5 -5
  338. package/dist/zcl/zclStatusError.js +13 -13
  339. package/package.json +1 -1
  340. package/.github/ISSUE_TEMPLATE/config.yml +0 -5
  341. package/.github/dependabot.yml +0 -6
  342. package/.github/workflows/ci.yml +0 -40
  343. package/.github/workflows/release_please.yml +0 -20
  344. package/.github/workflows/stale.yml +0 -20
  345. package/.github/workflows/update_deps.yml +0 -29
@@ -1,679 +1,679 @@
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 Events = __importStar(require("../../events"));
30
- const adapter_1 = __importDefault(require("../../adapter"));
31
- const zcl_1 = require("../../../zcl");
32
- const utils_1 = require("../../../utils");
33
- const zigate_1 = __importDefault(require("../driver/zigate"));
34
- const debug_1 = require("../debug");
35
- const constants_1 = require("../driver/constants");
36
- const buffalo_1 = require("../../../buffalo");
37
- const debug = (0, debug_1.Debug)('adapter');
38
- const default_bind_group = 901; // https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/lib/constants.js#L3
39
- const channelsToMask = (channels) => channels.map((x) => 2 ** x).reduce((acc, x) => acc + x, 0);
40
- class ZiGateAdapter extends adapter_1.default {
41
- constructor(networkOptions, serialPortOptions, backupPath, adapterOptions, logger) {
42
- super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);
43
- this.joinPermitted = false;
44
- this.driver = new zigate_1.default(serialPortOptions.path, serialPortOptions);
45
- this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
46
- this.driver.on('received', this.zclDataListener.bind(this));
47
- this.driver.on('receivedRaw', this.rawDataListener.bind(this));
48
- this.driver.on('LeaveIndication', this.leaveIndicationListener.bind(this));
49
- this.driver.on('DeviceAnnounce', this.deviceAnnounceListener.bind(this));
50
- }
51
- /**
52
- * Adapter methods
53
- */
54
- async start() {
55
- let startResult = 'resumed';
56
- try {
57
- await this.driver.open();
58
- debug.log("Connected to ZiGate adapter successfully.");
59
- const resetResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
60
- if (resetResponse.code === constants_1.ZiGateMessageCode.RestartNonFactoryNew) {
61
- startResult = 'resumed';
62
- }
63
- else if (resetResponse.code === constants_1.ZiGateMessageCode.RestartFactoryNew) {
64
- startResult = 'reset';
65
- }
66
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawMode, { enabled: 0x01 });
67
- // @todo check
68
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetDeviceType, {
69
- deviceType: constants_1.DEVICE_TYPE.coordinator
70
- });
71
- await this.initNetwork();
72
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.AddGroup, {
73
- addressMode: constants_1.ADDRESS_MODE.short,
74
- shortAddress: 0x0000,
75
- sourceEndpoint: 0x01,
76
- destinationEndpoint: 0x01,
77
- groupAddress: default_bind_group
78
- });
79
- }
80
- catch (error) {
81
- throw new Error("failed to connect to zigate adapter " + error.message);
82
- }
83
- const concurrent = this.adapterOptions && this.adapterOptions.concurrent ?
84
- this.adapterOptions.concurrent : 2;
85
- debug.log(`Adapter concurrent: ${concurrent}`);
86
- this.queue = new utils_1.Queue(concurrent);
87
- return startResult; // 'resumed' | 'reset' | 'restored'
88
- }
89
- async stop() {
90
- this.closing = true;
91
- await this.driver.close();
92
- }
93
- async getCoordinator() {
94
- debug.log('getCoordinator');
95
- const networkResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState);
96
- // @TODO deal hardcoded endpoints, made by analogy with deconz
97
- // polling the coordinator on some firmware went into a memory leak, so we don't ask this info
98
- const response = {
99
- networkAddress: 0,
100
- manufacturerID: 0,
101
- ieeeAddr: networkResponse.payload.extendedAddress,
102
- endpoints: constants_1.coordinatorEndpoints
103
- };
104
- debug.log('getCoordinator %o', response);
105
- return response;
106
- }
107
- ;
108
- async getCoordinatorVersion() {
109
- debug.log('getCoordinatorVersion');
110
- return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetVersion, {})
111
- .then((result) => {
112
- const meta = {
113
- "transportrev": 0,
114
- "product": 0,
115
- "majorrel": parseInt(result.payload.major).toString(16),
116
- "minorrel": parseInt(result.payload.minor).toString(16),
117
- "maintrel": parseInt(result.payload.revision).toString(16),
118
- "revision": parseInt(result.payload.revision).toString(16),
119
- };
120
- const version = {
121
- type: 'zigate',
122
- meta: meta,
123
- };
124
- return Promise.resolve(version);
125
- })
126
- .catch((e) => {
127
- debug.error(e);
128
- return Promise.reject(new Error("" + e));
129
- });
130
- }
131
- ;
132
- async permitJoin(seconds, networkAddress) {
133
- const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.PermitJoin, {
134
- targetShortAddress: networkAddress || 0xFFFC,
135
- interval: seconds,
136
- TCsignificance: 0
137
- });
138
- // const result = await this.driver.sendCommand(ZiGateCommandCode.PermitJoinStatus, {});
139
- // Suitable only for the coordinator, not the entire network or point-to-point for routers
140
- this.joinPermitted = result.payload.status === 0;
141
- }
142
- ;
143
- async addInstallCode(ieeeAddress, key) {
144
- return Promise.reject(new Error('Add install code is not supported'));
145
- }
146
- async reset(type) {
147
- debug.log('reset %s', type);
148
- if (type === 'soft') {
149
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
150
- }
151
- else if (type === 'hard') {
152
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.ErasePersistentData, {}, 5000);
153
- }
154
- return Promise.resolve();
155
- }
156
- ;
157
- async getNetworkParameters() {
158
- debug.log('getNetworkParameters');
159
- return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState, {}, 10000)
160
- .then((NetworkStateResponse) => {
161
- const resultPayload = {
162
- panID: NetworkStateResponse.payload.PANID,
163
- extendedPanID: NetworkStateResponse.payload.ExtPANID,
164
- channel: NetworkStateResponse.payload.Channel
165
- };
166
- return Promise.resolve(resultPayload);
167
- }).catch(() => Promise.reject(new Error("Get network parameters failed")));
168
- }
169
- ;
170
- /**
171
- * https://zigate.fr/documentation/deplacer-le-pdm-de-la-zigate/
172
- * pdm from host
173
- */
174
- async supportsBackup() {
175
- return false;
176
- }
177
- ;
178
- async backup() {
179
- throw new Error("This adapter does not support backup");
180
- }
181
- ;
182
- async setTransmitPower(value) {
183
- debug.log('setTransmitPower, %o', arguments);
184
- return this.driver.sendCommand(constants_1.ZiGateCommandCode.SetTXpower, { value: value })
185
- .then(() => Promise.resolve()).catch(() => Promise.reject(new Error("Set transmitpower failed")));
186
- }
187
- ;
188
- async lqi(networkAddress) {
189
- return this.queue.execute(async () => {
190
- debug.log('lqi, %o', arguments);
191
- const neighbors = [];
192
- const add = (list) => {
193
- for (const entry of list) {
194
- const relationByte = entry.readUInt8(18);
195
- const extAddr = entry.slice(8, 16);
196
- neighbors.push({
197
- linkquality: entry.readUInt8(21),
198
- networkAddress: entry.readUInt16LE(16),
199
- ieeeAddr: new buffalo_1.Buffalo(extAddr).readIeeeAddr(),
200
- relationship: (relationByte >> 1) & ((1 << 3) - 1),
201
- depth: entry.readUInt8(20)
202
- });
203
- }
204
- };
205
- const request = async (startIndex) => {
206
- try {
207
- const resultPayload = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLQI, { targetAddress: networkAddress, startIndex: startIndex });
208
- const data = resultPayload.payload.payload;
209
- if (data[1] !== 0) { // status
210
- throw new Error(`LQI for '${networkAddress}' failed`);
211
- }
212
- const tableList = [];
213
- const response = {
214
- status: data[1],
215
- tableEntrys: data[2],
216
- startIndex: data[3],
217
- tableListCount: data[4],
218
- tableList: tableList
219
- };
220
- let tableEntry = [];
221
- let counter = 0;
222
- for (let i = 5; i < ((response.tableListCount * 22) + 5); i++) { // one tableentry = 22 bytes
223
- tableEntry.push(data[i]);
224
- counter++;
225
- if (counter === 22) {
226
- response.tableList.push(Buffer.from(tableEntry));
227
- tableEntry = [];
228
- counter = 0;
229
- }
230
- }
231
- debug.log("LQI RESPONSE - addr: " + networkAddress.toString(16) + " status: "
232
- + response.status + " read " + (response.tableListCount + response.startIndex)
233
- + "/" + response.tableEntrys + " entrys");
234
- return response;
235
- }
236
- catch (error) {
237
- const msg = "LQI REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
238
- debug.log(msg);
239
- return Promise.reject(new Error(msg));
240
- }
241
- };
242
- let response = await request(0);
243
- add(response.tableList);
244
- let nextStartIndex = response.tableListCount;
245
- while (neighbors.length < response.tableEntrys) {
246
- response = await request(nextStartIndex);
247
- add(response.tableList);
248
- nextStartIndex += response.tableListCount;
249
- }
250
- return { neighbors };
251
- }, networkAddress);
252
- }
253
- ;
254
- // @TODO
255
- routingTable(networkAddress) {
256
- debug.log('RoutingTable, %o', arguments);
257
- return;
258
- }
259
- ;
260
- async nodeDescriptor(networkAddress) {
261
- return this.queue.execute(async () => {
262
- debug.log('nodeDescriptor, \n %o', arguments);
263
- try {
264
- const nodeDescriptorResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.NodeDescriptor, {
265
- targetShortAddress: networkAddress
266
- });
267
- const data = nodeDescriptorResponse.payload.payload;
268
- const buf = data;
269
- const logicaltype = (data[4] & 7);
270
- let type = 'Unknown';
271
- switch (logicaltype) {
272
- case 1:
273
- type = 'Router';
274
- break;
275
- case 2:
276
- type = 'EndDevice';
277
- break;
278
- case 0:
279
- type = 'Coordinator';
280
- break;
281
- }
282
- const manufacturer = buf.readUInt16LE(7);
283
- debug.log("RECEIVING NODE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16)
284
- + " type: " + type + " manufacturer: 0x" + manufacturer.toString(16));
285
- return { manufacturerCode: manufacturer, type };
286
- }
287
- catch (error) {
288
- const msg = "RECEIVING NODE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
289
- debug.error(msg);
290
- return Promise.reject(new Error(msg));
291
- }
292
- }, networkAddress);
293
- }
294
- ;
295
- async activeEndpoints(networkAddress) {
296
- return this.queue.execute(async () => {
297
- debug.log('ActiveEndpoints request');
298
- const payload = {
299
- targetShortAddress: networkAddress
300
- };
301
- try {
302
- const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ActiveEndpoint, payload);
303
- const buf = Buffer.from(result.payload.payload);
304
- const epCount = buf.readUInt8(4);
305
- const epList = [];
306
- for (let i = 5; i < (epCount + 5); i++) {
307
- epList.push(buf.readUInt8(i));
308
- }
309
- const payloadAE = {
310
- endpoints: epList
311
- };
312
- debug.log('ActiveEndpoints response: %o', payloadAE);
313
- return payloadAE;
314
- }
315
- catch (error) {
316
- debug.error("RECEIVING ActiveEndpoints FAILED, %o", error);
317
- return Promise.reject(new Error("RECEIVING ActiveEndpoints FAILED " + error));
318
- }
319
- }, networkAddress);
320
- }
321
- ;
322
- async simpleDescriptor(networkAddress, endpointID) {
323
- return this.queue.execute(async () => {
324
- debug.log('SimpleDescriptor request: %o', arguments);
325
- try {
326
- const payload = {
327
- targetShortAddress: networkAddress,
328
- endpoint: endpointID
329
- };
330
- const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.SimpleDescriptor, payload);
331
- const buf = result.payload.payload;
332
- if (buf.length > 11) {
333
- const inCount = buf.readUInt8(11);
334
- const inClusters = [];
335
- let cIndex = 12;
336
- for (let i = 0; i < inCount; i++) {
337
- inClusters[i] = buf.readUInt16LE(cIndex);
338
- cIndex += 2;
339
- }
340
- const outCount = buf.readUInt8(12 + (inCount * 2));
341
- const outClusters = [];
342
- cIndex = 13 + (inCount * 2);
343
- for (let l = 0; l < outCount; l++) {
344
- outClusters[l] = buf.readUInt16LE(cIndex);
345
- cIndex += 2;
346
- }
347
- const resultPayload = {
348
- profileID: buf.readUInt16LE(6),
349
- endpointID: buf.readUInt8(5),
350
- deviceID: buf.readUInt16LE(8),
351
- inputClusters: inClusters,
352
- outputClusters: outClusters
353
- };
354
- return resultPayload;
355
- }
356
- }
357
- catch (error) {
358
- const msg = "RECEIVING SIMPLE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16)
359
- + " EP:" + endpointID + " " + error;
360
- debug.error(msg);
361
- return Promise.reject(new Error(msg));
362
- }
363
- }, networkAddress);
364
- }
365
- ;
366
- async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
367
- return this.queue.execute(async () => {
368
- debug.log('bind %o', arguments);
369
- let payload = {
370
- targetExtendedAddress: sourceIeeeAddress,
371
- targetEndpoint: sourceEndpoint,
372
- clusterID: clusterID,
373
- destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
374
- destinationAddress: destinationAddressOrGroup,
375
- };
376
- if (typeof destinationEndpoint !== undefined) {
377
- // @ts-ignore
378
- payload['destinationEndpoint'] = destinationEndpoint;
379
- }
380
- const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Bind, payload, null, { destinationNetworkAddress });
381
- let data = result.payload.payload;
382
- if (data[1] === 0) {
383
- debug.log('Bind %s success', sourceIeeeAddress);
384
- return Promise.resolve();
385
- }
386
- else {
387
- const msg = `Bind ${sourceIeeeAddress} failed`;
388
- debug.error(msg);
389
- return Promise.reject(new Error(msg));
390
- }
391
- }, destinationNetworkAddress);
392
- }
393
- ;
394
- async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
395
- return this.queue.execute(async () => {
396
- debug.log('unbind %o', arguments);
397
- let payload = {
398
- targetExtendedAddress: sourceIeeeAddress,
399
- targetEndpoint: sourceEndpoint,
400
- clusterID: clusterID,
401
- destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
402
- destinationAddress: destinationAddressOrGroup,
403
- };
404
- if (typeof destinationEndpoint !== undefined) {
405
- // @ts-ignore
406
- payload['destinationEndpoint'] = destinationEndpoint;
407
- }
408
- const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.UnBind, payload, null, { destinationNetworkAddress });
409
- let data = result.payload.payload;
410
- if (data[1] === 0) {
411
- debug.log('Unbind %s success', sourceIeeeAddress);
412
- return Promise.resolve();
413
- }
414
- else {
415
- const msg = `Unbind ${sourceIeeeAddress} failed`;
416
- debug.error(msg);
417
- return Promise.reject(new Error(msg));
418
- }
419
- }, destinationNetworkAddress);
420
- }
421
- ;
422
- async removeDevice(networkAddress, ieeeAddr) {
423
- return this.queue.execute(async () => {
424
- const payload = {
425
- shortAddress: networkAddress,
426
- extendedAddress: ieeeAddr,
427
- rejoin: 0,
428
- removeChildren: 0
429
- };
430
- return this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLeaveRequest, payload)
431
- .then((Response) => {
432
- return Promise.resolve();
433
- }).catch(() => Promise.reject(new Error("ManagementLeaveRequest failed")));
434
- }, networkAddress);
435
- }
436
- ;
437
- async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
438
- return this.queue.execute(async () => {
439
- return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint || 1, zclFrame, timeout, disableResponse, disableRecovery, 0, 0, false, false);
440
- }, networkAddress);
441
- }
442
- ;
443
- async sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt, dataRequestAttempt, checkedNetworkAddress, discoveredRoute) {
444
- debug.info('sendZclFrameToEndpointInternal %s:%i/%i (%i,%i,%i)', ieeeAddr, networkAddress, endpoint, responseAttempt, dataRequestAttempt, this.queue.count());
445
- let response = null;
446
- const data = zclFrame.toBuffer();
447
- const command = zclFrame.getCommand();
448
- const payload = {
449
- addressMode: constants_1.ADDRESS_MODE.short,
450
- targetShortAddress: networkAddress,
451
- sourceEndpoint: sourceEndpoint || 0x01,
452
- destinationEndpoint: endpoint,
453
- profileID: 0x0104,
454
- clusterID: zclFrame.Cluster.ID,
455
- securityMode: 0x02,
456
- radius: 30,
457
- dataLength: data.length,
458
- data: data,
459
- };
460
- if (command.hasOwnProperty('response') && disableResponse === false) {
461
- response = this.waitFor(networkAddress, endpoint, zclFrame.Header.frameControl.frameType, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, command.response, timeout);
462
- }
463
- else if (!zclFrame.Header.frameControl.disableDefaultResponse) {
464
- response = this.waitFor(networkAddress, endpoint, zcl_1.FrameType.GLOBAL, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, zcl_1.Foundation.defaultRsp.ID, timeout);
465
- }
466
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, disableResponse).catch((e) => {
467
- if (responseAttempt < 1 && !disableRecovery) {
468
- // @todo discover route
469
- return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
470
- }
471
- });
472
- // @TODO add dataConfirmResult
473
- // @TODO if error codes route / no_resourses wait and resend
474
- if (response !== null) {
475
- try {
476
- // @ts-ignore
477
- return await response.promise;
478
- // @todo discover route
479
- }
480
- catch (error) {
481
- debug.error('Response error %s (%s:%d,%d)', error.toString(), ieeeAddr, networkAddress, responseAttempt);
482
- if (responseAttempt < 1 && !disableRecovery) {
483
- return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
484
- }
485
- else {
486
- throw error;
487
- }
488
- }
489
- }
490
- else {
491
- return null;
492
- }
493
- }
494
- async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
495
- return this.queue.execute(async () => {
496
- if (sourceEndpoint !== 0x01 /*&& sourceEndpoint !== 242*/) { // @todo on zigate firmware without gp causes hang
497
- debug.error('source endpoint %d, not supported', sourceEndpoint);
498
- return;
499
- }
500
- const data = zclFrame.toBuffer();
501
- const payload = {
502
- addressMode: constants_1.ADDRESS_MODE.short,
503
- targetShortAddress: 0xFFFD,
504
- sourceEndpoint: sourceEndpoint,
505
- destinationEndpoint: endpoint,
506
- profileID: /*sourceEndpoint === 242 ? 0xa1e0 :*/ 0x0104,
507
- clusterID: zclFrame.Cluster.ID,
508
- securityMode: 0x02,
509
- radius: 30,
510
- dataLength: data.length,
511
- data: data,
512
- };
513
- debug.log('sendZclFrameToAll %o', payload);
514
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
515
- await (0, utils_1.Wait)(200);
516
- });
517
- }
518
- ;
519
- async sendZclFrameToGroup(groupID, zclFrame, sourceEndpoint) {
520
- return this.queue.execute(async () => {
521
- debug.log('sendZclFrameToGroup %o', arguments);
522
- const data = zclFrame.toBuffer();
523
- const payload = {
524
- addressMode: constants_1.ADDRESS_MODE.group,
525
- targetShortAddress: groupID,
526
- sourceEndpoint: sourceEndpoint || 0x01,
527
- destinationEndpoint: 0xFF,
528
- profileID: 0x0104,
529
- clusterID: zclFrame.Cluster.ID,
530
- securityMode: 0x02,
531
- radius: 30,
532
- dataLength: data.length,
533
- data: data,
534
- };
535
- debug.log('sendZclFrameToGroup: \n %o', payload);
536
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
537
- await (0, utils_1.Wait)(200);
538
- });
539
- }
540
- ;
541
- /**
542
- * Supplementary functions
543
- */
544
- async initNetwork() {
545
- debug.log(`Set channel mask ${this.networkOptions.channelList} key`);
546
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetChannelMask, { channelMask: channelsToMask(this.networkOptions.channelList) });
547
- debug.log(`Set security key`);
548
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetSecurityStateKey, {
549
- keyType: this.networkOptions.networkKeyDistribute ?
550
- constants_1.ZPSNwkKeyState.ZPS_ZDO_DISTRIBUTED_LINK_KEY :
551
- constants_1.ZPSNwkKeyState.ZPS_ZDO_PRECONFIGURED_LINK_KEY,
552
- key: this.networkOptions.networkKey,
553
- });
554
- try {
555
- // The block is wrapped in trapping because if the network is already created, the firmware does not accept the new key.
556
- debug.log('Set EPanID %h', this.networkOptions.extendedPanID);
557
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetExtendedPANID, {
558
- panId: this.networkOptions.extendedPanID,
559
- });
560
- await this.driver.sendCommand(constants_1.ZiGateCommandCode.StartNetwork, {});
561
- }
562
- catch (e) {
563
- // @TODO Depending on the type of error, output clear text to the user
564
- debug.error("%o", e);
565
- }
566
- return Promise.resolve();
567
- }
568
- waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
569
- debug.log('waitForInternal %o', arguments);
570
- const payload = {
571
- address: networkAddress,
572
- endpoint,
573
- clusterID,
574
- commandIdentifier,
575
- frameType,
576
- direction,
577
- transactionSequenceNumber,
578
- };
579
- const waiter = this.waitress.waitFor(payload, timeout);
580
- const cancel = () => this.waitress.remove(waiter.ID);
581
- return { promise: waiter.start().promise, cancel };
582
- }
583
- ;
584
- static async isValidPath(path) {
585
- return zigate_1.default.isValidPath(path);
586
- }
587
- static async autoDetectPath() {
588
- return zigate_1.default.autoDetectPath();
589
- }
590
- /**
591
- * InterPAN !!! not implemented
592
- */
593
- async setChannelInterPAN(channel) {
594
- debug.log('setChannelInterPAN', arguments);
595
- return Promise.reject("Not supported");
596
- }
597
- ;
598
- async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddress) {
599
- debug.log('sendZclFrameInterPANToIeeeAddr', arguments);
600
- return Promise.reject("Not supported");
601
- }
602
- ;
603
- async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
604
- debug.log('sendZclFrameInterPANBroadcast', arguments);
605
- return Promise.reject("Not supported");
606
- }
607
- ;
608
- restoreChannelInterPAN() {
609
- debug.log('restoreChannelInterPAN', arguments);
610
- return Promise.reject("Not supported");
611
- }
612
- ;
613
- deviceAnnounceListener(networkAddress, ieeeAddr) {
614
- // @todo debounce
615
- const payload = { networkAddress, ieeeAddr };
616
- if (this.joinPermitted === true) {
617
- this.emit(Events.Events.deviceJoined, payload);
618
- }
619
- else {
620
- this.emit(Events.Events.deviceAnnounce, payload);
621
- }
622
- }
623
- zclDataListener(data) {
624
- if (data.zclFrame instanceof zcl_1.ZclFrame) {
625
- const payload = {
626
- address: data.ziGateObject.payload.sourceAddress,
627
- frame: data.zclFrame,
628
- endpoint: data.ziGateObject.payload.sourceEndpoint,
629
- linkquality: data.ziGateObject.frame.readRSSI(),
630
- groupID: null,
631
- wasBroadcast: false,
632
- destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
633
- };
634
- this.waitress.resolve(payload);
635
- this.emit(Events.Events.zclData, payload);
636
- }
637
- else {
638
- debug.error('msg not zclFrame', data.zclFrame);
639
- }
640
- }
641
- rawDataListener(data) {
642
- const payload = {
643
- clusterID: data.ziGateObject.payload.clusterID,
644
- data: data.ziGateObject.payload.payload,
645
- address: data.ziGateObject.payload.sourceAddress,
646
- endpoint: data.ziGateObject.payload.sourceEndpoint,
647
- linkquality: data.ziGateObject.frame.readRSSI(),
648
- groupID: null,
649
- wasBroadcast: false,
650
- destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
651
- };
652
- this.emit(Events.Events.rawData, payload);
653
- }
654
- leaveIndicationListener(data) {
655
- debug.log('LeaveIndication %o', data);
656
- const payload = {
657
- networkAddress: data.ziGateObject.payload.extendedAddress,
658
- ieeeAddr: data.ziGateObject.payload.extendedAddress
659
- };
660
- this.emit(Events.Events.deviceLeave, payload);
661
- }
662
- waitressTimeoutFormatter(matcher, timeout) {
663
- return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
664
- ` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
665
- ` - ${matcher.commandIdentifier} after ${timeout}ms`;
666
- }
667
- waitressValidator(payload, matcher) {
668
- const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
669
- return (!matcher.address || payload.address === matcher.address) &&
670
- matcher.endpoint === payload.endpoint &&
671
- (!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
672
- matcher.clusterID === payload.frame.Cluster.ID &&
673
- matcher.frameType === payload.frame.Header.frameControl.frameType &&
674
- matcher.commandIdentifier === payload.frame.Header.commandIdentifier &&
675
- matcher.direction === payload.frame.Header.frameControl.direction;
676
- }
677
- }
678
- exports.default = ZiGateAdapter;
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 Events = __importStar(require("../../events"));
30
+ const adapter_1 = __importDefault(require("../../adapter"));
31
+ const zcl_1 = require("../../../zcl");
32
+ const utils_1 = require("../../../utils");
33
+ const zigate_1 = __importDefault(require("../driver/zigate"));
34
+ const debug_1 = require("../debug");
35
+ const constants_1 = require("../driver/constants");
36
+ const buffalo_1 = require("../../../buffalo");
37
+ const debug = (0, debug_1.Debug)('adapter');
38
+ const default_bind_group = 901; // https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/lib/constants.js#L3
39
+ const channelsToMask = (channels) => channels.map((x) => 2 ** x).reduce((acc, x) => acc + x, 0);
40
+ class ZiGateAdapter extends adapter_1.default {
41
+ constructor(networkOptions, serialPortOptions, backupPath, adapterOptions, logger) {
42
+ super(networkOptions, serialPortOptions, backupPath, adapterOptions, logger);
43
+ this.joinPermitted = false;
44
+ this.driver = new zigate_1.default(serialPortOptions.path, serialPortOptions);
45
+ this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
46
+ this.driver.on('received', this.zclDataListener.bind(this));
47
+ this.driver.on('receivedRaw', this.rawDataListener.bind(this));
48
+ this.driver.on('LeaveIndication', this.leaveIndicationListener.bind(this));
49
+ this.driver.on('DeviceAnnounce', this.deviceAnnounceListener.bind(this));
50
+ }
51
+ /**
52
+ * Adapter methods
53
+ */
54
+ async start() {
55
+ let startResult = 'resumed';
56
+ try {
57
+ await this.driver.open();
58
+ debug.log("Connected to ZiGate adapter successfully.");
59
+ const resetResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
60
+ if (resetResponse.code === constants_1.ZiGateMessageCode.RestartNonFactoryNew) {
61
+ startResult = 'resumed';
62
+ }
63
+ else if (resetResponse.code === constants_1.ZiGateMessageCode.RestartFactoryNew) {
64
+ startResult = 'reset';
65
+ }
66
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawMode, { enabled: 0x01 });
67
+ // @todo check
68
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetDeviceType, {
69
+ deviceType: constants_1.DEVICE_TYPE.coordinator
70
+ });
71
+ await this.initNetwork();
72
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.AddGroup, {
73
+ addressMode: constants_1.ADDRESS_MODE.short,
74
+ shortAddress: 0x0000,
75
+ sourceEndpoint: 0x01,
76
+ destinationEndpoint: 0x01,
77
+ groupAddress: default_bind_group
78
+ });
79
+ }
80
+ catch (error) {
81
+ throw new Error("failed to connect to zigate adapter " + error.message);
82
+ }
83
+ const concurrent = this.adapterOptions && this.adapterOptions.concurrent ?
84
+ this.adapterOptions.concurrent : 2;
85
+ debug.log(`Adapter concurrent: ${concurrent}`);
86
+ this.queue = new utils_1.Queue(concurrent);
87
+ return startResult; // 'resumed' | 'reset' | 'restored'
88
+ }
89
+ async stop() {
90
+ this.closing = true;
91
+ await this.driver.close();
92
+ }
93
+ async getCoordinator() {
94
+ debug.log('getCoordinator');
95
+ const networkResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState);
96
+ // @TODO deal hardcoded endpoints, made by analogy with deconz
97
+ // polling the coordinator on some firmware went into a memory leak, so we don't ask this info
98
+ const response = {
99
+ networkAddress: 0,
100
+ manufacturerID: 0,
101
+ ieeeAddr: networkResponse.payload.extendedAddress,
102
+ endpoints: constants_1.coordinatorEndpoints
103
+ };
104
+ debug.log('getCoordinator %o', response);
105
+ return response;
106
+ }
107
+ ;
108
+ async getCoordinatorVersion() {
109
+ debug.log('getCoordinatorVersion');
110
+ return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetVersion, {})
111
+ .then((result) => {
112
+ const meta = {
113
+ "transportrev": 0,
114
+ "product": 0,
115
+ "majorrel": parseInt(result.payload.major).toString(16),
116
+ "minorrel": parseInt(result.payload.minor).toString(16),
117
+ "maintrel": parseInt(result.payload.revision).toString(16),
118
+ "revision": parseInt(result.payload.revision).toString(16),
119
+ };
120
+ const version = {
121
+ type: 'zigate',
122
+ meta: meta,
123
+ };
124
+ return Promise.resolve(version);
125
+ })
126
+ .catch((e) => {
127
+ debug.error(e);
128
+ return Promise.reject(new Error("" + e));
129
+ });
130
+ }
131
+ ;
132
+ async permitJoin(seconds, networkAddress) {
133
+ const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.PermitJoin, {
134
+ targetShortAddress: networkAddress || 0xFFFC,
135
+ interval: seconds,
136
+ TCsignificance: 0
137
+ });
138
+ // const result = await this.driver.sendCommand(ZiGateCommandCode.PermitJoinStatus, {});
139
+ // Suitable only for the coordinator, not the entire network or point-to-point for routers
140
+ this.joinPermitted = result.payload.status === 0;
141
+ }
142
+ ;
143
+ async addInstallCode(ieeeAddress, key) {
144
+ return Promise.reject(new Error('Add install code is not supported'));
145
+ }
146
+ async reset(type) {
147
+ debug.log('reset %s', type);
148
+ if (type === 'soft') {
149
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.Reset, {}, 5000);
150
+ }
151
+ else if (type === 'hard') {
152
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.ErasePersistentData, {}, 5000);
153
+ }
154
+ return Promise.resolve();
155
+ }
156
+ ;
157
+ async getNetworkParameters() {
158
+ debug.log('getNetworkParameters');
159
+ return this.driver.sendCommand(constants_1.ZiGateCommandCode.GetNetworkState, {}, 10000)
160
+ .then((NetworkStateResponse) => {
161
+ const resultPayload = {
162
+ panID: NetworkStateResponse.payload.PANID,
163
+ extendedPanID: NetworkStateResponse.payload.ExtPANID,
164
+ channel: NetworkStateResponse.payload.Channel
165
+ };
166
+ return Promise.resolve(resultPayload);
167
+ }).catch(() => Promise.reject(new Error("Get network parameters failed")));
168
+ }
169
+ ;
170
+ /**
171
+ * https://zigate.fr/documentation/deplacer-le-pdm-de-la-zigate/
172
+ * pdm from host
173
+ */
174
+ async supportsBackup() {
175
+ return false;
176
+ }
177
+ ;
178
+ async backup() {
179
+ throw new Error("This adapter does not support backup");
180
+ }
181
+ ;
182
+ async setTransmitPower(value) {
183
+ debug.log('setTransmitPower, %o', arguments);
184
+ return this.driver.sendCommand(constants_1.ZiGateCommandCode.SetTXpower, { value: value })
185
+ .then(() => Promise.resolve()).catch(() => Promise.reject(new Error("Set transmitpower failed")));
186
+ }
187
+ ;
188
+ async lqi(networkAddress) {
189
+ return this.queue.execute(async () => {
190
+ debug.log('lqi, %o', arguments);
191
+ const neighbors = [];
192
+ const add = (list) => {
193
+ for (const entry of list) {
194
+ const relationByte = entry.readUInt8(18);
195
+ const extAddr = entry.slice(8, 16);
196
+ neighbors.push({
197
+ linkquality: entry.readUInt8(21),
198
+ networkAddress: entry.readUInt16LE(16),
199
+ ieeeAddr: new buffalo_1.Buffalo(extAddr).readIeeeAddr(),
200
+ relationship: (relationByte >> 1) & ((1 << 3) - 1),
201
+ depth: entry.readUInt8(20)
202
+ });
203
+ }
204
+ };
205
+ const request = async (startIndex) => {
206
+ try {
207
+ const resultPayload = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLQI, { targetAddress: networkAddress, startIndex: startIndex });
208
+ const data = resultPayload.payload.payload;
209
+ if (data[1] !== 0) { // status
210
+ throw new Error(`LQI for '${networkAddress}' failed`);
211
+ }
212
+ const tableList = [];
213
+ const response = {
214
+ status: data[1],
215
+ tableEntrys: data[2],
216
+ startIndex: data[3],
217
+ tableListCount: data[4],
218
+ tableList: tableList
219
+ };
220
+ let tableEntry = [];
221
+ let counter = 0;
222
+ for (let i = 5; i < ((response.tableListCount * 22) + 5); i++) { // one tableentry = 22 bytes
223
+ tableEntry.push(data[i]);
224
+ counter++;
225
+ if (counter === 22) {
226
+ response.tableList.push(Buffer.from(tableEntry));
227
+ tableEntry = [];
228
+ counter = 0;
229
+ }
230
+ }
231
+ debug.log("LQI RESPONSE - addr: " + networkAddress.toString(16) + " status: "
232
+ + response.status + " read " + (response.tableListCount + response.startIndex)
233
+ + "/" + response.tableEntrys + " entrys");
234
+ return response;
235
+ }
236
+ catch (error) {
237
+ const msg = "LQI REQUEST FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
238
+ debug.log(msg);
239
+ return Promise.reject(new Error(msg));
240
+ }
241
+ };
242
+ let response = await request(0);
243
+ add(response.tableList);
244
+ let nextStartIndex = response.tableListCount;
245
+ while (neighbors.length < response.tableEntrys) {
246
+ response = await request(nextStartIndex);
247
+ add(response.tableList);
248
+ nextStartIndex += response.tableListCount;
249
+ }
250
+ return { neighbors };
251
+ }, networkAddress);
252
+ }
253
+ ;
254
+ // @TODO
255
+ routingTable(networkAddress) {
256
+ debug.log('RoutingTable, %o', arguments);
257
+ return;
258
+ }
259
+ ;
260
+ async nodeDescriptor(networkAddress) {
261
+ return this.queue.execute(async () => {
262
+ debug.log('nodeDescriptor, \n %o', arguments);
263
+ try {
264
+ const nodeDescriptorResponse = await this.driver.sendCommand(constants_1.ZiGateCommandCode.NodeDescriptor, {
265
+ targetShortAddress: networkAddress
266
+ });
267
+ const data = nodeDescriptorResponse.payload.payload;
268
+ const buf = data;
269
+ const logicaltype = (data[4] & 7);
270
+ let type = 'Unknown';
271
+ switch (logicaltype) {
272
+ case 1:
273
+ type = 'Router';
274
+ break;
275
+ case 2:
276
+ type = 'EndDevice';
277
+ break;
278
+ case 0:
279
+ type = 'Coordinator';
280
+ break;
281
+ }
282
+ const manufacturer = buf.readUInt16LE(7);
283
+ debug.log("RECEIVING NODE_DESCRIPTOR - addr: 0x" + networkAddress.toString(16)
284
+ + " type: " + type + " manufacturer: 0x" + manufacturer.toString(16));
285
+ return { manufacturerCode: manufacturer, type };
286
+ }
287
+ catch (error) {
288
+ const msg = "RECEIVING NODE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16) + " " + error;
289
+ debug.error(msg);
290
+ return Promise.reject(new Error(msg));
291
+ }
292
+ }, networkAddress);
293
+ }
294
+ ;
295
+ async activeEndpoints(networkAddress) {
296
+ return this.queue.execute(async () => {
297
+ debug.log('ActiveEndpoints request');
298
+ const payload = {
299
+ targetShortAddress: networkAddress
300
+ };
301
+ try {
302
+ const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.ActiveEndpoint, payload);
303
+ const buf = Buffer.from(result.payload.payload);
304
+ const epCount = buf.readUInt8(4);
305
+ const epList = [];
306
+ for (let i = 5; i < (epCount + 5); i++) {
307
+ epList.push(buf.readUInt8(i));
308
+ }
309
+ const payloadAE = {
310
+ endpoints: epList
311
+ };
312
+ debug.log('ActiveEndpoints response: %o', payloadAE);
313
+ return payloadAE;
314
+ }
315
+ catch (error) {
316
+ debug.error("RECEIVING ActiveEndpoints FAILED, %o", error);
317
+ return Promise.reject(new Error("RECEIVING ActiveEndpoints FAILED " + error));
318
+ }
319
+ }, networkAddress);
320
+ }
321
+ ;
322
+ async simpleDescriptor(networkAddress, endpointID) {
323
+ return this.queue.execute(async () => {
324
+ debug.log('SimpleDescriptor request: %o', arguments);
325
+ try {
326
+ const payload = {
327
+ targetShortAddress: networkAddress,
328
+ endpoint: endpointID
329
+ };
330
+ const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.SimpleDescriptor, payload);
331
+ const buf = result.payload.payload;
332
+ if (buf.length > 11) {
333
+ const inCount = buf.readUInt8(11);
334
+ const inClusters = [];
335
+ let cIndex = 12;
336
+ for (let i = 0; i < inCount; i++) {
337
+ inClusters[i] = buf.readUInt16LE(cIndex);
338
+ cIndex += 2;
339
+ }
340
+ const outCount = buf.readUInt8(12 + (inCount * 2));
341
+ const outClusters = [];
342
+ cIndex = 13 + (inCount * 2);
343
+ for (let l = 0; l < outCount; l++) {
344
+ outClusters[l] = buf.readUInt16LE(cIndex);
345
+ cIndex += 2;
346
+ }
347
+ const resultPayload = {
348
+ profileID: buf.readUInt16LE(6),
349
+ endpointID: buf.readUInt8(5),
350
+ deviceID: buf.readUInt16LE(8),
351
+ inputClusters: inClusters,
352
+ outputClusters: outClusters
353
+ };
354
+ return resultPayload;
355
+ }
356
+ }
357
+ catch (error) {
358
+ const msg = "RECEIVING SIMPLE_DESCRIPTOR FAILED - addr: 0x" + networkAddress.toString(16)
359
+ + " EP:" + endpointID + " " + error;
360
+ debug.error(msg);
361
+ return Promise.reject(new Error(msg));
362
+ }
363
+ }, networkAddress);
364
+ }
365
+ ;
366
+ async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
367
+ return this.queue.execute(async () => {
368
+ debug.log('bind %o', arguments);
369
+ let payload = {
370
+ targetExtendedAddress: sourceIeeeAddress,
371
+ targetEndpoint: sourceEndpoint,
372
+ clusterID: clusterID,
373
+ destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
374
+ destinationAddress: destinationAddressOrGroup,
375
+ };
376
+ if (typeof destinationEndpoint !== undefined) {
377
+ // @ts-ignore
378
+ payload['destinationEndpoint'] = destinationEndpoint;
379
+ }
380
+ const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.Bind, payload, null, { destinationNetworkAddress });
381
+ let data = result.payload.payload;
382
+ if (data[1] === 0) {
383
+ debug.log('Bind %s success', sourceIeeeAddress);
384
+ return Promise.resolve();
385
+ }
386
+ else {
387
+ const msg = `Bind ${sourceIeeeAddress} failed`;
388
+ debug.error(msg);
389
+ return Promise.reject(new Error(msg));
390
+ }
391
+ }, destinationNetworkAddress);
392
+ }
393
+ ;
394
+ async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
395
+ return this.queue.execute(async () => {
396
+ debug.log('unbind %o', arguments);
397
+ let payload = {
398
+ targetExtendedAddress: sourceIeeeAddress,
399
+ targetEndpoint: sourceEndpoint,
400
+ clusterID: clusterID,
401
+ destinationAddressMode: (type === 'group') ? constants_1.ADDRESS_MODE.group : constants_1.ADDRESS_MODE.ieee,
402
+ destinationAddress: destinationAddressOrGroup,
403
+ };
404
+ if (typeof destinationEndpoint !== undefined) {
405
+ // @ts-ignore
406
+ payload['destinationEndpoint'] = destinationEndpoint;
407
+ }
408
+ const result = await this.driver.sendCommand(constants_1.ZiGateCommandCode.UnBind, payload, null, { destinationNetworkAddress });
409
+ let data = result.payload.payload;
410
+ if (data[1] === 0) {
411
+ debug.log('Unbind %s success', sourceIeeeAddress);
412
+ return Promise.resolve();
413
+ }
414
+ else {
415
+ const msg = `Unbind ${sourceIeeeAddress} failed`;
416
+ debug.error(msg);
417
+ return Promise.reject(new Error(msg));
418
+ }
419
+ }, destinationNetworkAddress);
420
+ }
421
+ ;
422
+ async removeDevice(networkAddress, ieeeAddr) {
423
+ return this.queue.execute(async () => {
424
+ const payload = {
425
+ shortAddress: networkAddress,
426
+ extendedAddress: ieeeAddr,
427
+ rejoin: 0,
428
+ removeChildren: 0
429
+ };
430
+ return this.driver.sendCommand(constants_1.ZiGateCommandCode.ManagementLeaveRequest, payload)
431
+ .then((Response) => {
432
+ return Promise.resolve();
433
+ }).catch(() => Promise.reject(new Error("ManagementLeaveRequest failed")));
434
+ }, networkAddress);
435
+ }
436
+ ;
437
+ async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
438
+ return this.queue.execute(async () => {
439
+ return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint || 1, zclFrame, timeout, disableResponse, disableRecovery, 0, 0, false, false);
440
+ }, networkAddress);
441
+ }
442
+ ;
443
+ async sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt, dataRequestAttempt, checkedNetworkAddress, discoveredRoute) {
444
+ debug.info('sendZclFrameToEndpointInternal %s:%i/%i (%i,%i,%i)', ieeeAddr, networkAddress, endpoint, responseAttempt, dataRequestAttempt, this.queue.count());
445
+ let response = null;
446
+ const data = zclFrame.toBuffer();
447
+ const command = zclFrame.getCommand();
448
+ const payload = {
449
+ addressMode: constants_1.ADDRESS_MODE.short,
450
+ targetShortAddress: networkAddress,
451
+ sourceEndpoint: sourceEndpoint || 0x01,
452
+ destinationEndpoint: endpoint,
453
+ profileID: 0x0104,
454
+ clusterID: zclFrame.Cluster.ID,
455
+ securityMode: 0x02,
456
+ radius: 30,
457
+ dataLength: data.length,
458
+ data: data,
459
+ };
460
+ if (command.hasOwnProperty('response') && disableResponse === false) {
461
+ response = this.waitFor(networkAddress, endpoint, zclFrame.Header.frameControl.frameType, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, command.response, timeout);
462
+ }
463
+ else if (!zclFrame.Header.frameControl.disableDefaultResponse) {
464
+ response = this.waitFor(networkAddress, endpoint, zcl_1.FrameType.GLOBAL, zcl_1.Direction.SERVER_TO_CLIENT, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, zcl_1.Foundation.defaultRsp.ID, timeout);
465
+ }
466
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, disableResponse).catch((e) => {
467
+ if (responseAttempt < 1 && !disableRecovery) {
468
+ // @todo discover route
469
+ return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
470
+ }
471
+ });
472
+ // @TODO add dataConfirmResult
473
+ // @TODO if error codes route / no_resourses wait and resend
474
+ if (response !== null) {
475
+ try {
476
+ // @ts-ignore
477
+ return await response.promise;
478
+ // @todo discover route
479
+ }
480
+ catch (error) {
481
+ debug.error('Response error %s (%s:%d,%d)', error.toString(), ieeeAddr, networkAddress, responseAttempt);
482
+ if (responseAttempt < 1 && !disableRecovery) {
483
+ return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute);
484
+ }
485
+ else {
486
+ throw error;
487
+ }
488
+ }
489
+ }
490
+ else {
491
+ return null;
492
+ }
493
+ }
494
+ async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
495
+ return this.queue.execute(async () => {
496
+ if (sourceEndpoint !== 0x01 /*&& sourceEndpoint !== 242*/) { // @todo on zigate firmware without gp causes hang
497
+ debug.error('source endpoint %d, not supported', sourceEndpoint);
498
+ return;
499
+ }
500
+ const data = zclFrame.toBuffer();
501
+ const payload = {
502
+ addressMode: constants_1.ADDRESS_MODE.short,
503
+ targetShortAddress: 0xFFFD,
504
+ sourceEndpoint: sourceEndpoint,
505
+ destinationEndpoint: endpoint,
506
+ profileID: /*sourceEndpoint === 242 ? 0xa1e0 :*/ 0x0104,
507
+ clusterID: zclFrame.Cluster.ID,
508
+ securityMode: 0x02,
509
+ radius: 30,
510
+ dataLength: data.length,
511
+ data: data,
512
+ };
513
+ debug.log('sendZclFrameToAll %o', payload);
514
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
515
+ await (0, utils_1.Wait)(200);
516
+ });
517
+ }
518
+ ;
519
+ async sendZclFrameToGroup(groupID, zclFrame, sourceEndpoint) {
520
+ return this.queue.execute(async () => {
521
+ debug.log('sendZclFrameToGroup %o', arguments);
522
+ const data = zclFrame.toBuffer();
523
+ const payload = {
524
+ addressMode: constants_1.ADDRESS_MODE.group,
525
+ targetShortAddress: groupID,
526
+ sourceEndpoint: sourceEndpoint || 0x01,
527
+ destinationEndpoint: 0xFF,
528
+ profileID: 0x0104,
529
+ clusterID: zclFrame.Cluster.ID,
530
+ securityMode: 0x02,
531
+ radius: 30,
532
+ dataLength: data.length,
533
+ data: data,
534
+ };
535
+ debug.log('sendZclFrameToGroup: \n %o', payload);
536
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.RawAPSDataRequest, payload, undefined, {}, true);
537
+ await (0, utils_1.Wait)(200);
538
+ });
539
+ }
540
+ ;
541
+ /**
542
+ * Supplementary functions
543
+ */
544
+ async initNetwork() {
545
+ debug.log(`Set channel mask ${this.networkOptions.channelList} key`);
546
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetChannelMask, { channelMask: channelsToMask(this.networkOptions.channelList) });
547
+ debug.log(`Set security key`);
548
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetSecurityStateKey, {
549
+ keyType: this.networkOptions.networkKeyDistribute ?
550
+ constants_1.ZPSNwkKeyState.ZPS_ZDO_DISTRIBUTED_LINK_KEY :
551
+ constants_1.ZPSNwkKeyState.ZPS_ZDO_PRECONFIGURED_LINK_KEY,
552
+ key: this.networkOptions.networkKey,
553
+ });
554
+ try {
555
+ // The block is wrapped in trapping because if the network is already created, the firmware does not accept the new key.
556
+ debug.log('Set EPanID %h', this.networkOptions.extendedPanID);
557
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.SetExtendedPANID, {
558
+ panId: this.networkOptions.extendedPanID,
559
+ });
560
+ await this.driver.sendCommand(constants_1.ZiGateCommandCode.StartNetwork, {});
561
+ }
562
+ catch (e) {
563
+ // @TODO Depending on the type of error, output clear text to the user
564
+ debug.error("%o", e);
565
+ }
566
+ return Promise.resolve();
567
+ }
568
+ waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
569
+ debug.log('waitForInternal %o', arguments);
570
+ const payload = {
571
+ address: networkAddress,
572
+ endpoint,
573
+ clusterID,
574
+ commandIdentifier,
575
+ frameType,
576
+ direction,
577
+ transactionSequenceNumber,
578
+ };
579
+ const waiter = this.waitress.waitFor(payload, timeout);
580
+ const cancel = () => this.waitress.remove(waiter.ID);
581
+ return { promise: waiter.start().promise, cancel };
582
+ }
583
+ ;
584
+ static async isValidPath(path) {
585
+ return zigate_1.default.isValidPath(path);
586
+ }
587
+ static async autoDetectPath() {
588
+ return zigate_1.default.autoDetectPath();
589
+ }
590
+ /**
591
+ * InterPAN !!! not implemented
592
+ */
593
+ async setChannelInterPAN(channel) {
594
+ debug.log('setChannelInterPAN', arguments);
595
+ return Promise.reject("Not supported");
596
+ }
597
+ ;
598
+ async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddress) {
599
+ debug.log('sendZclFrameInterPANToIeeeAddr', arguments);
600
+ return Promise.reject("Not supported");
601
+ }
602
+ ;
603
+ async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
604
+ debug.log('sendZclFrameInterPANBroadcast', arguments);
605
+ return Promise.reject("Not supported");
606
+ }
607
+ ;
608
+ restoreChannelInterPAN() {
609
+ debug.log('restoreChannelInterPAN', arguments);
610
+ return Promise.reject("Not supported");
611
+ }
612
+ ;
613
+ deviceAnnounceListener(networkAddress, ieeeAddr) {
614
+ // @todo debounce
615
+ const payload = { networkAddress, ieeeAddr };
616
+ if (this.joinPermitted === true) {
617
+ this.emit(Events.Events.deviceJoined, payload);
618
+ }
619
+ else {
620
+ this.emit(Events.Events.deviceAnnounce, payload);
621
+ }
622
+ }
623
+ zclDataListener(data) {
624
+ if (data.zclFrame instanceof zcl_1.ZclFrame) {
625
+ const payload = {
626
+ address: data.ziGateObject.payload.sourceAddress,
627
+ frame: data.zclFrame,
628
+ endpoint: data.ziGateObject.payload.sourceEndpoint,
629
+ linkquality: data.ziGateObject.frame.readRSSI(),
630
+ groupID: null,
631
+ wasBroadcast: false,
632
+ destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
633
+ };
634
+ this.waitress.resolve(payload);
635
+ this.emit(Events.Events.zclData, payload);
636
+ }
637
+ else {
638
+ debug.error('msg not zclFrame', data.zclFrame);
639
+ }
640
+ }
641
+ rawDataListener(data) {
642
+ const payload = {
643
+ clusterID: data.ziGateObject.payload.clusterID,
644
+ data: data.ziGateObject.payload.payload,
645
+ address: data.ziGateObject.payload.sourceAddress,
646
+ endpoint: data.ziGateObject.payload.sourceEndpoint,
647
+ linkquality: data.ziGateObject.frame.readRSSI(),
648
+ groupID: null,
649
+ wasBroadcast: false,
650
+ destinationEndpoint: data.ziGateObject.payload.destinationEndpoint,
651
+ };
652
+ this.emit(Events.Events.rawData, payload);
653
+ }
654
+ leaveIndicationListener(data) {
655
+ debug.log('LeaveIndication %o', data);
656
+ const payload = {
657
+ networkAddress: data.ziGateObject.payload.extendedAddress,
658
+ ieeeAddr: data.ziGateObject.payload.extendedAddress
659
+ };
660
+ this.emit(Events.Events.deviceLeave, payload);
661
+ }
662
+ waitressTimeoutFormatter(matcher, timeout) {
663
+ return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
664
+ ` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
665
+ ` - ${matcher.commandIdentifier} after ${timeout}ms`;
666
+ }
667
+ waitressValidator(payload, matcher) {
668
+ const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
669
+ return (!matcher.address || payload.address === matcher.address) &&
670
+ matcher.endpoint === payload.endpoint &&
671
+ (!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
672
+ matcher.clusterID === payload.frame.Cluster.ID &&
673
+ matcher.frameType === payload.frame.Header.frameControl.frameType &&
674
+ matcher.commandIdentifier === payload.frame.Header.commandIdentifier &&
675
+ matcher.direction === payload.frame.Header.frameControl.direction;
676
+ }
677
+ }
678
+ exports.default = ZiGateAdapter;
679
679
  //# sourceMappingURL=zigateAdapter.js.map