@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,586 +1,586 @@
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:adapter:ezsp:debg");
32
- const driver_1 = require("../driver");
33
- const types_1 = require("../driver/types");
34
- const zcl_1 = require("../../../zcl");
35
- const Events = __importStar(require("../../events"));
36
- const utils_1 = require("../../../utils");
37
- const serialPortUtils_1 = __importDefault(require("../../serialPortUtils"));
38
- const socketPortUtils_1 = __importDefault(require("../../socketPortUtils"));
39
- const backup_1 = require("./backup");
40
- const autoDetectDefinitions = [
41
- { manufacturer: 'ITEAD', vendorId: '1a86', productId: '55d4' },
42
- { manufacturer: 'Nabu Casa', vendorId: '10c4', productId: 'ea60' }, // Home Assistant SkyConnect
43
- ];
44
- class EZSPAdapter extends adapter_1.default {
45
- constructor(networkOptions, serialPortOptions, backupPath, adapterOptions) {
46
- super(networkOptions, serialPortOptions, backupPath, adapterOptions);
47
- this.port = serialPortOptions;
48
- this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
49
- this.interpanLock = false;
50
- this.driver = new driver_1.Driver();
51
- this.driver.on('deviceJoined', this.handleDeviceJoin.bind(this));
52
- this.driver.on('deviceLeft', this.handleDeviceLeft.bind(this));
53
- this.driver.on('incomingMessage', this.processMessage.bind(this));
54
- this.backupMan = new backup_1.EZSPAdapterBackup(this.driver, backupPath);
55
- }
56
- async processMessage(frame) {
57
- debug(`processMessage: ${JSON.stringify(frame)}`);
58
- if (frame.apsFrame.profileId == 0) {
59
- if (frame.apsFrame.clusterId == types_1.EmberZDOCmd.Device_annce &&
60
- frame.apsFrame.destinationEndpoint == 0) {
61
- let nwk, rst, ieee;
62
- [nwk, rst] = types_1.uint16_t.deserialize(types_1.uint16_t, frame.message.subarray(1));
63
- [ieee, rst] = types_1.EmberEUI64.deserialize(types_1.EmberEUI64, rst);
64
- ieee = new types_1.EmberEUI64(ieee);
65
- debug("ZDO Device announce: %s, %s", nwk, ieee.toString());
66
- this.driver.handleNodeJoined(nwk, ieee);
67
- }
68
- }
69
- else if (frame.apsFrame.profileId == 260 || frame.apsFrame.profileId == 0xFFFF) {
70
- try {
71
- const payload = {
72
- frame: zcl_1.ZclFrame.fromBuffer(frame.apsFrame.clusterId, frame.message),
73
- address: frame.sender,
74
- endpoint: frame.apsFrame.sourceEndpoint,
75
- linkquality: frame.lqi,
76
- groupID: frame.apsFrame.groupId,
77
- wasBroadcast: false,
78
- destinationEndpoint: frame.apsFrame.destinationEndpoint,
79
- };
80
- this.waitress.resolve(payload);
81
- this.emit(Events.Events.zclData, payload);
82
- }
83
- catch (error) {
84
- const payload = {
85
- clusterID: frame.apsFrame.clusterId,
86
- data: frame.message,
87
- address: frame.sender,
88
- endpoint: frame.apsFrame.sourceEndpoint,
89
- linkquality: frame.lqi,
90
- groupID: frame.apsFrame.groupId,
91
- wasBroadcast: false,
92
- destinationEndpoint: frame.apsFrame.destinationEndpoint,
93
- };
94
- this.emit(Events.Events.rawData, payload);
95
- }
96
- }
97
- else if (frame.apsFrame.profileId == 0xc05e && frame.senderEui64) { // ZLL Frame
98
- const payload = {
99
- frame: zcl_1.ZclFrame.fromBuffer(frame.apsFrame.clusterId, frame.message),
100
- address: `0x${frame.senderEui64.toString()}`,
101
- endpoint: 0xFE,
102
- linkquality: frame.lqi,
103
- groupID: null,
104
- wasBroadcast: false,
105
- destinationEndpoint: null,
106
- };
107
- this.waitress.resolve(payload);
108
- this.emit(Events.Events.zclData, payload);
109
- }
110
- else if (frame.apsFrame.profileId == 0xA1E0) { // GP Frame
111
- const zclFrame = zcl_1.ZclFrame.create(zcl_1.FrameType.SPECIFIC, zcl_1.Direction.CLIENT_TO_SERVER, true, null, frame.apsFrame.sequence, (frame.messageType == 0xE0) ? 'commisioningNotification' : 'notification', frame.apsFrame.clusterId, frame.message);
112
- const payload = {
113
- frame: zclFrame,
114
- address: frame.sender,
115
- endpoint: frame.apsFrame.sourceEndpoint,
116
- linkquality: frame.lqi,
117
- groupID: null,
118
- wasBroadcast: true,
119
- destinationEndpoint: frame.apsFrame.sourceEndpoint,
120
- };
121
- this.waitress.resolve(payload);
122
- this.emit(Events.Events.zclData, payload);
123
- }
124
- this.emit('event', frame);
125
- }
126
- async handleDeviceJoin(arr) {
127
- let [nwk, ieee] = arr;
128
- debug('Device join request received: %s %s', nwk, ieee.toString('hex'));
129
- const payload = {
130
- networkAddress: nwk,
131
- ieeeAddr: `0x${ieee.toString('hex')}`,
132
- };
133
- if (nwk == 0) {
134
- const nd = await this.nodeDescriptor(nwk);
135
- }
136
- else {
137
- this.emit(Events.Events.deviceJoined, payload);
138
- }
139
- }
140
- handleDeviceLeft(arr) {
141
- let [nwk, ieee] = arr;
142
- debug('Device left network request received: %s %s', nwk, ieee);
143
- const payload = {
144
- networkAddress: nwk,
145
- ieeeAddr: `0x${ieee.toString('hex')}`,
146
- };
147
- this.emit(Events.Events.deviceLeave, payload);
148
- }
149
- /**
150
- * Adapter methods
151
- */
152
- async start() {
153
- return await this.driver.startup(this.port.path, {
154
- baudRate: this.port.baudRate || 115200,
155
- rtscts: this.port.rtscts,
156
- parity: 'none',
157
- stopBits: 1,
158
- xon: true,
159
- xoff: true
160
- }, this.networkOptions, this.greenPowerGroup);
161
- }
162
- async stop() {
163
- await this.driver.stop();
164
- }
165
- static async isValidPath(path) {
166
- // For TCP paths we cannot get device information, therefore we cannot validate it.
167
- if (socketPortUtils_1.default.isTcpPath(path)) {
168
- return false;
169
- }
170
- try {
171
- return serialPortUtils_1.default.is((0, utils_1.RealpathSync)(path), autoDetectDefinitions);
172
- }
173
- catch (error) {
174
- debug(`Failed to determine if path is valid: '${error}'`);
175
- return false;
176
- }
177
- }
178
- static async autoDetectPath() {
179
- const paths = await serialPortUtils_1.default.find(autoDetectDefinitions);
180
- paths.sort((a, b) => (a < b) ? -1 : 1);
181
- return paths.length > 0 ? paths[0] : null;
182
- }
183
- async getCoordinator() {
184
- return this.driver.queue.execute(async () => {
185
- this.checkInterpanLock();
186
- const networkAddress = 0x0000;
187
- const message = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Active_EP_req, types_1.EmberZDOCmd.Active_EP_rsp, { dstaddr: networkAddress });
188
- const activeEndpoints = message.activeeplist;
189
- const endpoints = [];
190
- for (const endpoint of activeEndpoints) {
191
- const descriptor = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Simple_Desc_req, types_1.EmberZDOCmd.Simple_Desc_rsp, { dstaddr: networkAddress, targetEp: endpoint });
192
- endpoints.push({
193
- profileID: descriptor.descriptor.profileid,
194
- ID: descriptor.descriptor.endpoint,
195
- deviceID: descriptor.descriptor.deviceid,
196
- inputClusters: descriptor.descriptor.inclusterlist,
197
- outputClusters: descriptor.descriptor.outclusterlist,
198
- });
199
- }
200
- return {
201
- networkAddress: networkAddress,
202
- manufacturerID: 0,
203
- ieeeAddr: `0x${this.driver.ieee.toString()}`,
204
- endpoints,
205
- };
206
- });
207
- }
208
- async permitJoin(seconds, networkAddress) {
209
- return this.driver.queue.execute(async () => {
210
- this.checkInterpanLock();
211
- if (seconds) {
212
- this.driver.preJoining();
213
- }
214
- if (networkAddress) {
215
- const result = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Permit_Joining_req, types_1.EmberZDOCmd.Mgmt_Permit_Joining_rsp, { duration: seconds, tcSignificant: false });
216
- if (result.status !== types_1.EmberStatus.SUCCESS) {
217
- throw new Error(`permitJoin for '${networkAddress}' failed`);
218
- }
219
- }
220
- else {
221
- await this.driver.permitJoining(seconds);
222
- }
223
- });
224
- }
225
- async getCoordinatorVersion() {
226
- return { type: `EZSP v${this.driver.version.product}`, meta: this.driver.version };
227
- }
228
- async addInstallCode(ieeeAddress, key) {
229
- if ([8, 10, 14, 18].indexOf(key.length) === -1) {
230
- throw new Error('Wrong install code length');
231
- }
232
- await this.driver.addInstallCode(ieeeAddress, key);
233
- }
234
- async reset(type) {
235
- return Promise.reject(new Error("Not supported"));
236
- }
237
- async lqi(networkAddress) {
238
- return this.driver.queue.execute(async () => {
239
- this.checkInterpanLock();
240
- const neighbors = [];
241
- const request = async (startIndex) => {
242
- const result = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Lqi_req, types_1.EmberZDOCmd.Mgmt_Lqi_rsp, { startindex: startIndex });
243
- if (result.status !== types_1.EmberStatus.SUCCESS) {
244
- throw new Error(`LQI for '${networkAddress}' failed with with status code ${result.status}`);
245
- }
246
- return result;
247
- };
248
- // eslint-disable-next-line
249
- const add = (list) => {
250
- for (const entry of list) {
251
- this.driver.setNode(entry.nodeid, entry.ieee);
252
- neighbors.push({
253
- linkquality: entry.lqi,
254
- networkAddress: entry.nodeid,
255
- ieeeAddr: `0x${new types_1.EmberEUI64(entry.ieee).toString()}`,
256
- relationship: (entry.packed >> 4) & 0x7,
257
- depth: entry.depth,
258
- });
259
- }
260
- };
261
- let response = await request(0);
262
- add(response.neighborlqilist.neighbors);
263
- const size = response.neighborlqilist.entries;
264
- let nextStartIndex = response.neighborlqilist.neighbors.length;
265
- while (neighbors.length < size) {
266
- response = await request(nextStartIndex);
267
- add(response.neighborlqilist.neighbors);
268
- nextStartIndex += response.neighborlqilist.neighbors.length;
269
- }
270
- return { neighbors };
271
- }, networkAddress);
272
- }
273
- async routingTable(networkAddress) {
274
- return this.driver.queue.execute(async () => {
275
- this.checkInterpanLock();
276
- const table = [];
277
- const request = async (startIndex) => {
278
- const result = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Rtg_req, types_1.EmberZDOCmd.Mgmt_Rtg_rsp, { startindex: startIndex });
279
- if (result.status !== types_1.EmberStatus.SUCCESS) {
280
- throw new Error(`Routing table for '${networkAddress}' failed with status code ${result.status}`);
281
- }
282
- return result;
283
- };
284
- // eslint-disable-next-line
285
- const add = (list) => {
286
- for (const entry of list) {
287
- table.push({
288
- destinationAddress: entry.destination,
289
- status: entry.status,
290
- nextHop: entry.nexthop
291
- });
292
- }
293
- };
294
- let response = await request(0);
295
- add(response.routingtablelist.table);
296
- const size = response.routingtablelist.entries;
297
- let nextStartIndex = response.routingtablelist.table.length;
298
- while (table.length < size) {
299
- response = await request(nextStartIndex);
300
- add(response.routingtablelist.table);
301
- nextStartIndex += response.routingtablelist.table.length;
302
- }
303
- return { table };
304
- }, networkAddress);
305
- }
306
- async nodeDescriptor(networkAddress) {
307
- return this.driver.queue.execute(async () => {
308
- this.checkInterpanLock();
309
- try {
310
- debug(`Requesting 'Node Descriptor' for '${networkAddress}'`);
311
- const result = await this.nodeDescriptorInternal(networkAddress);
312
- return result;
313
- }
314
- catch (error) {
315
- debug(`Node descriptor request for '${networkAddress}' failed (${error}), retry`);
316
- throw error;
317
- }
318
- });
319
- }
320
- async nodeDescriptorInternal(networkAddress) {
321
- const descriptor = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Node_Desc_req, types_1.EmberZDOCmd.Node_Desc_rsp, { dstaddr: networkAddress });
322
- const logicaltype = descriptor.descriptor.byte1 & 0x07;
323
- return {
324
- manufacturerCode: descriptor.descriptor.manufacturer_code,
325
- type: (logicaltype == 0) ? 'Coordinator' : (logicaltype == 1) ? 'Router' : 'EndDevice'
326
- };
327
- }
328
- async activeEndpoints(networkAddress) {
329
- debug(`Requesting 'Active endpoints' for '${networkAddress}'`);
330
- return this.driver.queue.execute(async () => {
331
- const endpoints = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Active_EP_req, types_1.EmberZDOCmd.Active_EP_rsp, { dstaddr: networkAddress });
332
- return { endpoints: [...endpoints.activeeplist] };
333
- }, networkAddress);
334
- }
335
- async simpleDescriptor(networkAddress, endpointID) {
336
- debug(`Requesting 'Simple Descriptor' for '${networkAddress}' endpoint ${endpointID}`);
337
- return this.driver.queue.execute(async () => {
338
- this.checkInterpanLock();
339
- const descriptor = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Simple_Desc_req, types_1.EmberZDOCmd.Simple_Desc_rsp, { dstaddr: networkAddress, targetEp: endpointID });
340
- return {
341
- profileID: descriptor.descriptor.profileid,
342
- endpointID: descriptor.descriptor.endpoint,
343
- deviceID: descriptor.descriptor.deviceid,
344
- inputClusters: descriptor.descriptor.inclusterlist,
345
- outputClusters: descriptor.descriptor.outclusterlist,
346
- };
347
- }, networkAddress);
348
- }
349
- async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
350
- return this.driver.queue.execute(async () => {
351
- this.checkInterpanLock();
352
- return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint || 1, zclFrame, timeout, disableResponse, disableRecovery, 0, 0, false, false, false, null);
353
- }, networkAddress);
354
- }
355
- async sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt, dataRequestAttempt, checkedNetworkAddress, discoveredRoute, assocRemove, assocRestore) {
356
- if (ieeeAddr == null) {
357
- ieeeAddr = `0x${this.driver.ieee.toString()}`;
358
- }
359
- debug('sendZclFrameToEndpointInternal %s:%i/%i (%i,%i,%i)', ieeeAddr, networkAddress, endpoint, responseAttempt, dataRequestAttempt, this.driver.queue.count());
360
- let response = null;
361
- const command = zclFrame.getCommand();
362
- if (command.hasOwnProperty('response') && disableResponse === false) {
363
- response = this.waitForInternal(networkAddress, endpoint, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, command.response, timeout);
364
- }
365
- else if (!zclFrame.Header.frameControl.disableDefaultResponse) {
366
- response = this.waitForInternal(networkAddress, endpoint, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, zcl_1.Foundation.defaultRsp.ID, timeout);
367
- }
368
- const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, disableResponse || zclFrame.Header.frameControl.disableDefaultResponse);
369
- frame.profileId = 0x0104;
370
- frame.sourceEndpoint = sourceEndpoint || 0x01;
371
- frame.destinationEndpoint = endpoint;
372
- frame.groupId = 0;
373
- this.driver.setNode(networkAddress, new types_1.EmberEUI64(ieeeAddr));
374
- const dataConfirmResult = await this.driver.request(networkAddress, frame, zclFrame.toBuffer());
375
- if (!dataConfirmResult) {
376
- if (response != null) {
377
- response.cancel();
378
- }
379
- throw Error('sendZclFrameToEndpointInternal error');
380
- }
381
- if (response !== null) {
382
- try {
383
- const result = await response.start().promise;
384
- return result;
385
- }
386
- catch (error) {
387
- debug('Response timeout (%s:%d,%d)', ieeeAddr, networkAddress, responseAttempt);
388
- if (responseAttempt < 1 && !disableRecovery) {
389
- return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute, assocRemove, assocRestore);
390
- }
391
- else {
392
- throw error;
393
- }
394
- }
395
- }
396
- else {
397
- return null;
398
- }
399
- }
400
- async sendZclFrameToGroup(groupID, zclFrame) {
401
- return this.driver.queue.execute(async () => {
402
- this.checkInterpanLock();
403
- const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, false);
404
- frame.profileId = 0x0104;
405
- frame.sourceEndpoint = 0x01;
406
- frame.destinationEndpoint = 0x01;
407
- frame.groupId = groupID;
408
- const dataConfirmResult = await this.driver.mrequest(frame, zclFrame.toBuffer());
409
- /**
410
- * As a group command is not confirmed and thus immidiately returns
411
- * (contrary to network address requests) we will give the
412
- * command some time to 'settle' in the network.
413
- */
414
- await (0, utils_1.Wait)(200);
415
- });
416
- }
417
- async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
418
- return this.driver.queue.execute(async () => {
419
- this.checkInterpanLock();
420
- const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, false);
421
- frame.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xA1E0 : 0x0104;
422
- frame.sourceEndpoint = sourceEndpoint;
423
- frame.destinationEndpoint = endpoint;
424
- frame.groupId = 0xFFFD;
425
- const dataConfirmResult = await this.driver.mrequest(frame, zclFrame.toBuffer());
426
- /**
427
- * As a broadcast command is not confirmed and thus immidiately returns
428
- * (contrary to network address requests) we will give the
429
- * command some time to 'settle' in the network.
430
- */
431
- await (0, utils_1.Wait)(200);
432
- });
433
- }
434
- async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
435
- return this.driver.queue.execute(async () => {
436
- this.checkInterpanLock();
437
- const ieee = new types_1.EmberEUI64(sourceIeeeAddress);
438
- const addrmode = (type === 'group') ? 1 : 3;
439
- const ieeeDst = (type === 'group') ? destinationAddressOrGroup :
440
- new types_1.EmberEUI64(destinationAddressOrGroup);
441
- if (type !== 'group') {
442
- this.driver.setNode(destinationNetworkAddress, ieeeDst);
443
- }
444
- await this.driver.zdoRequest(destinationNetworkAddress, types_1.EmberZDOCmd.Bind_req, types_1.EmberZDOCmd.Bind_rsp, { sourceEui: ieee, sourceEp: sourceEndpoint, clusterId: clusterID,
445
- destAddr: { addrmode: addrmode, ieee: ieeeDst, endpoint: destinationEndpoint } });
446
- }, destinationNetworkAddress);
447
- }
448
- async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
449
- return this.driver.queue.execute(async () => {
450
- this.checkInterpanLock();
451
- const ieee = new types_1.EmberEUI64(sourceIeeeAddress);
452
- const addrmode = (type === 'group') ? 1 : 3;
453
- const ieeeDst = (type === 'group') ? destinationAddressOrGroup :
454
- new types_1.EmberEUI64(destinationAddressOrGroup);
455
- if (type !== 'group') {
456
- this.driver.setNode(destinationNetworkAddress, ieeeDst);
457
- }
458
- await this.driver.zdoRequest(destinationNetworkAddress, types_1.EmberZDOCmd.Unbind_req, types_1.EmberZDOCmd.Unbind_rsp, { sourceEui: ieee, sourceEp: sourceEndpoint, clusterId: clusterID,
459
- destAddr: { addrmode: addrmode, ieee: ieeeDst, endpoint: destinationEndpoint } });
460
- }, destinationNetworkAddress);
461
- }
462
- removeDevice(networkAddress, ieeeAddr) {
463
- return this.driver.queue.execute(async () => {
464
- this.checkInterpanLock();
465
- const ieee = new types_1.EmberEUI64(ieeeAddr);
466
- this.driver.setNode(networkAddress, ieee);
467
- await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Leave_req, types_1.EmberZDOCmd.Mgmt_Leave_rsp, { destAddr: ieee, removechildrenRejoin: 0x00 });
468
- }, networkAddress);
469
- }
470
- async getNetworkParameters() {
471
- return {
472
- panID: this.driver.networkParams.panId,
473
- extendedPanID: this.driver.networkParams.extendedPanId[0],
474
- channel: this.driver.networkParams.radioChannel
475
- };
476
- }
477
- async supportsBackup() {
478
- return true;
479
- }
480
- async backup() {
481
- return this.backupMan.createBackup();
482
- }
483
- async restoreChannelInterPAN() {
484
- return this.driver.queue.execute(async () => {
485
- const channel = (await this.getNetworkParameters()).channel;
486
- await this.driver.setChannel(channel);
487
- // Give adapter some time to restore, otherwise stuff crashes
488
- await (0, utils_1.Wait)(3000);
489
- this.interpanLock = false;
490
- });
491
- }
492
- checkInterpanLock() {
493
- if (this.interpanLock) {
494
- throw new Error(`Cannot execute command, in Inter-PAN mode`);
495
- }
496
- }
497
- async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddr) {
498
- return this.driver.queue.execute(async () => {
499
- debug(`sendZclFrameInterPANToIeeeAddr to ${ieeeAddr}`);
500
- try {
501
- const frame = this.driver.makeEmberIeeeRawFrame();
502
- frame.ieeeFrameControl = 0xcc21;
503
- frame.destPanId = 0xFFFF;
504
- frame.destAddress = new types_1.EmberEUI64(ieeeAddr);
505
- frame.sourcePanId = this.driver.networkParams.panId;
506
- frame.sourceAddress = this.driver.ieee;
507
- frame.nwkFrameControl = 0x000b;
508
- frame.appFrameControl = 0x03;
509
- frame.clusterId = zclFrame.Cluster.ID;
510
- frame.profileId = 0xc05e;
511
- const dataConfirmResult = await this.driver.ieeerawrequest(frame, zclFrame.toBuffer());
512
- }
513
- catch (error) {
514
- throw error;
515
- }
516
- });
517
- }
518
- async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
519
- return this.driver.queue.execute(async () => {
520
- debug(`sendZclFrameInterPANBroadcast`);
521
- const command = zclFrame.getCommand();
522
- if (!command.hasOwnProperty('response')) {
523
- throw new Error(`Command '${command.name}' has no response, cannot wait for response`);
524
- }
525
- const response = this.waitForInternal(null, 0xFE, null, zclFrame.Cluster.ID, command.response, timeout);
526
- try {
527
- const frame = this.driver.makeEmberRawFrame();
528
- frame.ieeeFrameControl = 0xc801;
529
- frame.destPanId = 0xFFFF;
530
- frame.destNodeId = 0xFFFF;
531
- frame.sourcePanId = this.driver.networkParams.panId;
532
- frame.ieeeAddress = this.driver.ieee;
533
- frame.nwkFrameControl = 0x000b;
534
- frame.appFrameControl = 0x0b;
535
- frame.clusterId = zclFrame.Cluster.ID;
536
- frame.profileId = 0xc05e;
537
- const dataConfirmResult = await this.driver.rawrequest(frame, zclFrame.toBuffer());
538
- }
539
- catch (error) {
540
- response.cancel();
541
- throw error;
542
- }
543
- return response.start().promise;
544
- });
545
- }
546
- async setTransmitPower(value) {
547
- debug(`setTransmitPower to ${value}`);
548
- return this.driver.queue.execute(async () => {
549
- await this.driver.setRadioPower(value);
550
- });
551
- }
552
- async setChannelInterPAN(channel) {
553
- return this.driver.queue.execute(async () => {
554
- this.interpanLock = true;
555
- await this.driver.setChannel(channel);
556
- });
557
- }
558
- waitForInternal(networkAddress, endpoint, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
559
- const payload = {
560
- address: networkAddress, endpoint, clusterID, commandIdentifier,
561
- transactionSequenceNumber,
562
- };
563
- const waiter = this.waitress.waitFor(payload, timeout);
564
- const cancel = () => this.waitress.remove(waiter.ID);
565
- return { start: waiter.start, cancel };
566
- }
567
- waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
568
- const waiter = this.waitForInternal(networkAddress, endpoint, transactionSequenceNumber, clusterID, commandIdentifier, timeout);
569
- return { cancel: waiter.cancel, promise: waiter.start().promise };
570
- }
571
- waitressTimeoutFormatter(matcher, timeout) {
572
- return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
573
- ` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
574
- ` - ${matcher.commandIdentifier} after ${timeout}ms`;
575
- }
576
- waitressValidator(payload, matcher) {
577
- const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
578
- return (!matcher.address || payload.address === matcher.address) &&
579
- payload.endpoint === matcher.endpoint &&
580
- (!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
581
- payload.frame.Cluster.ID === matcher.clusterID &&
582
- matcher.commandIdentifier === payload.frame.Header.commandIdentifier;
583
- }
584
- }
585
- exports.default = EZSPAdapter;
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:adapter:ezsp:debg");
32
+ const driver_1 = require("../driver");
33
+ const types_1 = require("../driver/types");
34
+ const zcl_1 = require("../../../zcl");
35
+ const Events = __importStar(require("../../events"));
36
+ const utils_1 = require("../../../utils");
37
+ const serialPortUtils_1 = __importDefault(require("../../serialPortUtils"));
38
+ const socketPortUtils_1 = __importDefault(require("../../socketPortUtils"));
39
+ const backup_1 = require("./backup");
40
+ const autoDetectDefinitions = [
41
+ { manufacturer: 'ITEAD', vendorId: '1a86', productId: '55d4' },
42
+ { manufacturer: 'Nabu Casa', vendorId: '10c4', productId: 'ea60' }, // Home Assistant SkyConnect
43
+ ];
44
+ class EZSPAdapter extends adapter_1.default {
45
+ constructor(networkOptions, serialPortOptions, backupPath, adapterOptions) {
46
+ super(networkOptions, serialPortOptions, backupPath, adapterOptions);
47
+ this.port = serialPortOptions;
48
+ this.waitress = new utils_1.Waitress(this.waitressValidator, this.waitressTimeoutFormatter);
49
+ this.interpanLock = false;
50
+ this.driver = new driver_1.Driver();
51
+ this.driver.on('deviceJoined', this.handleDeviceJoin.bind(this));
52
+ this.driver.on('deviceLeft', this.handleDeviceLeft.bind(this));
53
+ this.driver.on('incomingMessage', this.processMessage.bind(this));
54
+ this.backupMan = new backup_1.EZSPAdapterBackup(this.driver, backupPath);
55
+ }
56
+ async processMessage(frame) {
57
+ debug(`processMessage: ${JSON.stringify(frame)}`);
58
+ if (frame.apsFrame.profileId == 0) {
59
+ if (frame.apsFrame.clusterId == types_1.EmberZDOCmd.Device_annce &&
60
+ frame.apsFrame.destinationEndpoint == 0) {
61
+ let nwk, rst, ieee;
62
+ [nwk, rst] = types_1.uint16_t.deserialize(types_1.uint16_t, frame.message.subarray(1));
63
+ [ieee, rst] = types_1.EmberEUI64.deserialize(types_1.EmberEUI64, rst);
64
+ ieee = new types_1.EmberEUI64(ieee);
65
+ debug("ZDO Device announce: %s, %s", nwk, ieee.toString());
66
+ this.driver.handleNodeJoined(nwk, ieee);
67
+ }
68
+ }
69
+ else if (frame.apsFrame.profileId == 260 || frame.apsFrame.profileId == 0xFFFF) {
70
+ try {
71
+ const payload = {
72
+ frame: zcl_1.ZclFrame.fromBuffer(frame.apsFrame.clusterId, frame.message),
73
+ address: frame.sender,
74
+ endpoint: frame.apsFrame.sourceEndpoint,
75
+ linkquality: frame.lqi,
76
+ groupID: frame.apsFrame.groupId,
77
+ wasBroadcast: false,
78
+ destinationEndpoint: frame.apsFrame.destinationEndpoint,
79
+ };
80
+ this.waitress.resolve(payload);
81
+ this.emit(Events.Events.zclData, payload);
82
+ }
83
+ catch (error) {
84
+ const payload = {
85
+ clusterID: frame.apsFrame.clusterId,
86
+ data: frame.message,
87
+ address: frame.sender,
88
+ endpoint: frame.apsFrame.sourceEndpoint,
89
+ linkquality: frame.lqi,
90
+ groupID: frame.apsFrame.groupId,
91
+ wasBroadcast: false,
92
+ destinationEndpoint: frame.apsFrame.destinationEndpoint,
93
+ };
94
+ this.emit(Events.Events.rawData, payload);
95
+ }
96
+ }
97
+ else if (frame.apsFrame.profileId == 0xc05e && frame.senderEui64) { // ZLL Frame
98
+ const payload = {
99
+ frame: zcl_1.ZclFrame.fromBuffer(frame.apsFrame.clusterId, frame.message),
100
+ address: `0x${frame.senderEui64.toString()}`,
101
+ endpoint: 0xFE,
102
+ linkquality: frame.lqi,
103
+ groupID: null,
104
+ wasBroadcast: false,
105
+ destinationEndpoint: null,
106
+ };
107
+ this.waitress.resolve(payload);
108
+ this.emit(Events.Events.zclData, payload);
109
+ }
110
+ else if (frame.apsFrame.profileId == 0xA1E0) { // GP Frame
111
+ const zclFrame = zcl_1.ZclFrame.create(zcl_1.FrameType.SPECIFIC, zcl_1.Direction.CLIENT_TO_SERVER, true, null, frame.apsFrame.sequence, (frame.messageType == 0xE0) ? 'commisioningNotification' : 'notification', frame.apsFrame.clusterId, frame.message);
112
+ const payload = {
113
+ frame: zclFrame,
114
+ address: frame.sender,
115
+ endpoint: frame.apsFrame.sourceEndpoint,
116
+ linkquality: frame.lqi,
117
+ groupID: null,
118
+ wasBroadcast: true,
119
+ destinationEndpoint: frame.apsFrame.sourceEndpoint,
120
+ };
121
+ this.waitress.resolve(payload);
122
+ this.emit(Events.Events.zclData, payload);
123
+ }
124
+ this.emit('event', frame);
125
+ }
126
+ async handleDeviceJoin(arr) {
127
+ let [nwk, ieee] = arr;
128
+ debug('Device join request received: %s %s', nwk, ieee.toString('hex'));
129
+ const payload = {
130
+ networkAddress: nwk,
131
+ ieeeAddr: `0x${ieee.toString('hex')}`,
132
+ };
133
+ if (nwk == 0) {
134
+ const nd = await this.nodeDescriptor(nwk);
135
+ }
136
+ else {
137
+ this.emit(Events.Events.deviceJoined, payload);
138
+ }
139
+ }
140
+ handleDeviceLeft(arr) {
141
+ let [nwk, ieee] = arr;
142
+ debug('Device left network request received: %s %s', nwk, ieee);
143
+ const payload = {
144
+ networkAddress: nwk,
145
+ ieeeAddr: `0x${ieee.toString('hex')}`,
146
+ };
147
+ this.emit(Events.Events.deviceLeave, payload);
148
+ }
149
+ /**
150
+ * Adapter methods
151
+ */
152
+ async start() {
153
+ return await this.driver.startup(this.port.path, {
154
+ baudRate: this.port.baudRate || 115200,
155
+ rtscts: this.port.rtscts,
156
+ parity: 'none',
157
+ stopBits: 1,
158
+ xon: true,
159
+ xoff: true
160
+ }, this.networkOptions, this.greenPowerGroup);
161
+ }
162
+ async stop() {
163
+ await this.driver.stop();
164
+ }
165
+ static async isValidPath(path) {
166
+ // For TCP paths we cannot get device information, therefore we cannot validate it.
167
+ if (socketPortUtils_1.default.isTcpPath(path)) {
168
+ return false;
169
+ }
170
+ try {
171
+ return serialPortUtils_1.default.is((0, utils_1.RealpathSync)(path), autoDetectDefinitions);
172
+ }
173
+ catch (error) {
174
+ debug(`Failed to determine if path is valid: '${error}'`);
175
+ return false;
176
+ }
177
+ }
178
+ static async autoDetectPath() {
179
+ const paths = await serialPortUtils_1.default.find(autoDetectDefinitions);
180
+ paths.sort((a, b) => (a < b) ? -1 : 1);
181
+ return paths.length > 0 ? paths[0] : null;
182
+ }
183
+ async getCoordinator() {
184
+ return this.driver.queue.execute(async () => {
185
+ this.checkInterpanLock();
186
+ const networkAddress = 0x0000;
187
+ const message = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Active_EP_req, types_1.EmberZDOCmd.Active_EP_rsp, { dstaddr: networkAddress });
188
+ const activeEndpoints = message.activeeplist;
189
+ const endpoints = [];
190
+ for (const endpoint of activeEndpoints) {
191
+ const descriptor = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Simple_Desc_req, types_1.EmberZDOCmd.Simple_Desc_rsp, { dstaddr: networkAddress, targetEp: endpoint });
192
+ endpoints.push({
193
+ profileID: descriptor.descriptor.profileid,
194
+ ID: descriptor.descriptor.endpoint,
195
+ deviceID: descriptor.descriptor.deviceid,
196
+ inputClusters: descriptor.descriptor.inclusterlist,
197
+ outputClusters: descriptor.descriptor.outclusterlist,
198
+ });
199
+ }
200
+ return {
201
+ networkAddress: networkAddress,
202
+ manufacturerID: 0,
203
+ ieeeAddr: `0x${this.driver.ieee.toString()}`,
204
+ endpoints,
205
+ };
206
+ });
207
+ }
208
+ async permitJoin(seconds, networkAddress) {
209
+ return this.driver.queue.execute(async () => {
210
+ this.checkInterpanLock();
211
+ if (seconds) {
212
+ this.driver.preJoining();
213
+ }
214
+ if (networkAddress) {
215
+ const result = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Permit_Joining_req, types_1.EmberZDOCmd.Mgmt_Permit_Joining_rsp, { duration: seconds, tcSignificant: false });
216
+ if (result.status !== types_1.EmberStatus.SUCCESS) {
217
+ throw new Error(`permitJoin for '${networkAddress}' failed`);
218
+ }
219
+ }
220
+ else {
221
+ await this.driver.permitJoining(seconds);
222
+ }
223
+ });
224
+ }
225
+ async getCoordinatorVersion() {
226
+ return { type: `EZSP v${this.driver.version.product}`, meta: this.driver.version };
227
+ }
228
+ async addInstallCode(ieeeAddress, key) {
229
+ if ([8, 10, 14, 18].indexOf(key.length) === -1) {
230
+ throw new Error('Wrong install code length');
231
+ }
232
+ await this.driver.addInstallCode(ieeeAddress, key);
233
+ }
234
+ async reset(type) {
235
+ return Promise.reject(new Error("Not supported"));
236
+ }
237
+ async lqi(networkAddress) {
238
+ return this.driver.queue.execute(async () => {
239
+ this.checkInterpanLock();
240
+ const neighbors = [];
241
+ const request = async (startIndex) => {
242
+ const result = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Lqi_req, types_1.EmberZDOCmd.Mgmt_Lqi_rsp, { startindex: startIndex });
243
+ if (result.status !== types_1.EmberStatus.SUCCESS) {
244
+ throw new Error(`LQI for '${networkAddress}' failed with with status code ${result.status}`);
245
+ }
246
+ return result;
247
+ };
248
+ // eslint-disable-next-line
249
+ const add = (list) => {
250
+ for (const entry of list) {
251
+ this.driver.setNode(entry.nodeid, entry.ieee);
252
+ neighbors.push({
253
+ linkquality: entry.lqi,
254
+ networkAddress: entry.nodeid,
255
+ ieeeAddr: `0x${new types_1.EmberEUI64(entry.ieee).toString()}`,
256
+ relationship: (entry.packed >> 4) & 0x7,
257
+ depth: entry.depth,
258
+ });
259
+ }
260
+ };
261
+ let response = await request(0);
262
+ add(response.neighborlqilist.neighbors);
263
+ const size = response.neighborlqilist.entries;
264
+ let nextStartIndex = response.neighborlqilist.neighbors.length;
265
+ while (neighbors.length < size) {
266
+ response = await request(nextStartIndex);
267
+ add(response.neighborlqilist.neighbors);
268
+ nextStartIndex += response.neighborlqilist.neighbors.length;
269
+ }
270
+ return { neighbors };
271
+ }, networkAddress);
272
+ }
273
+ async routingTable(networkAddress) {
274
+ return this.driver.queue.execute(async () => {
275
+ this.checkInterpanLock();
276
+ const table = [];
277
+ const request = async (startIndex) => {
278
+ const result = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Rtg_req, types_1.EmberZDOCmd.Mgmt_Rtg_rsp, { startindex: startIndex });
279
+ if (result.status !== types_1.EmberStatus.SUCCESS) {
280
+ throw new Error(`Routing table for '${networkAddress}' failed with status code ${result.status}`);
281
+ }
282
+ return result;
283
+ };
284
+ // eslint-disable-next-line
285
+ const add = (list) => {
286
+ for (const entry of list) {
287
+ table.push({
288
+ destinationAddress: entry.destination,
289
+ status: entry.status,
290
+ nextHop: entry.nexthop
291
+ });
292
+ }
293
+ };
294
+ let response = await request(0);
295
+ add(response.routingtablelist.table);
296
+ const size = response.routingtablelist.entries;
297
+ let nextStartIndex = response.routingtablelist.table.length;
298
+ while (table.length < size) {
299
+ response = await request(nextStartIndex);
300
+ add(response.routingtablelist.table);
301
+ nextStartIndex += response.routingtablelist.table.length;
302
+ }
303
+ return { table };
304
+ }, networkAddress);
305
+ }
306
+ async nodeDescriptor(networkAddress) {
307
+ return this.driver.queue.execute(async () => {
308
+ this.checkInterpanLock();
309
+ try {
310
+ debug(`Requesting 'Node Descriptor' for '${networkAddress}'`);
311
+ const result = await this.nodeDescriptorInternal(networkAddress);
312
+ return result;
313
+ }
314
+ catch (error) {
315
+ debug(`Node descriptor request for '${networkAddress}' failed (${error}), retry`);
316
+ throw error;
317
+ }
318
+ });
319
+ }
320
+ async nodeDescriptorInternal(networkAddress) {
321
+ const descriptor = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Node_Desc_req, types_1.EmberZDOCmd.Node_Desc_rsp, { dstaddr: networkAddress });
322
+ const logicaltype = descriptor.descriptor.byte1 & 0x07;
323
+ return {
324
+ manufacturerCode: descriptor.descriptor.manufacturer_code,
325
+ type: (logicaltype == 0) ? 'Coordinator' : (logicaltype == 1) ? 'Router' : 'EndDevice'
326
+ };
327
+ }
328
+ async activeEndpoints(networkAddress) {
329
+ debug(`Requesting 'Active endpoints' for '${networkAddress}'`);
330
+ return this.driver.queue.execute(async () => {
331
+ const endpoints = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Active_EP_req, types_1.EmberZDOCmd.Active_EP_rsp, { dstaddr: networkAddress });
332
+ return { endpoints: [...endpoints.activeeplist] };
333
+ }, networkAddress);
334
+ }
335
+ async simpleDescriptor(networkAddress, endpointID) {
336
+ debug(`Requesting 'Simple Descriptor' for '${networkAddress}' endpoint ${endpointID}`);
337
+ return this.driver.queue.execute(async () => {
338
+ this.checkInterpanLock();
339
+ const descriptor = await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Simple_Desc_req, types_1.EmberZDOCmd.Simple_Desc_rsp, { dstaddr: networkAddress, targetEp: endpointID });
340
+ return {
341
+ profileID: descriptor.descriptor.profileid,
342
+ endpointID: descriptor.descriptor.endpoint,
343
+ deviceID: descriptor.descriptor.deviceid,
344
+ inputClusters: descriptor.descriptor.inclusterlist,
345
+ outputClusters: descriptor.descriptor.outclusterlist,
346
+ };
347
+ }, networkAddress);
348
+ }
349
+ async sendZclFrameToEndpoint(ieeeAddr, networkAddress, endpoint, zclFrame, timeout, disableResponse, disableRecovery, sourceEndpoint) {
350
+ return this.driver.queue.execute(async () => {
351
+ this.checkInterpanLock();
352
+ return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint || 1, zclFrame, timeout, disableResponse, disableRecovery, 0, 0, false, false, false, null);
353
+ }, networkAddress);
354
+ }
355
+ async sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt, dataRequestAttempt, checkedNetworkAddress, discoveredRoute, assocRemove, assocRestore) {
356
+ if (ieeeAddr == null) {
357
+ ieeeAddr = `0x${this.driver.ieee.toString()}`;
358
+ }
359
+ debug('sendZclFrameToEndpointInternal %s:%i/%i (%i,%i,%i)', ieeeAddr, networkAddress, endpoint, responseAttempt, dataRequestAttempt, this.driver.queue.count());
360
+ let response = null;
361
+ const command = zclFrame.getCommand();
362
+ if (command.hasOwnProperty('response') && disableResponse === false) {
363
+ response = this.waitForInternal(networkAddress, endpoint, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, command.response, timeout);
364
+ }
365
+ else if (!zclFrame.Header.frameControl.disableDefaultResponse) {
366
+ response = this.waitForInternal(networkAddress, endpoint, zclFrame.Header.transactionSequenceNumber, zclFrame.Cluster.ID, zcl_1.Foundation.defaultRsp.ID, timeout);
367
+ }
368
+ const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, disableResponse || zclFrame.Header.frameControl.disableDefaultResponse);
369
+ frame.profileId = 0x0104;
370
+ frame.sourceEndpoint = sourceEndpoint || 0x01;
371
+ frame.destinationEndpoint = endpoint;
372
+ frame.groupId = 0;
373
+ this.driver.setNode(networkAddress, new types_1.EmberEUI64(ieeeAddr));
374
+ const dataConfirmResult = await this.driver.request(networkAddress, frame, zclFrame.toBuffer());
375
+ if (!dataConfirmResult) {
376
+ if (response != null) {
377
+ response.cancel();
378
+ }
379
+ throw Error('sendZclFrameToEndpointInternal error');
380
+ }
381
+ if (response !== null) {
382
+ try {
383
+ const result = await response.start().promise;
384
+ return result;
385
+ }
386
+ catch (error) {
387
+ debug('Response timeout (%s:%d,%d)', ieeeAddr, networkAddress, responseAttempt);
388
+ if (responseAttempt < 1 && !disableRecovery) {
389
+ return this.sendZclFrameToEndpointInternal(ieeeAddr, networkAddress, endpoint, sourceEndpoint, zclFrame, timeout, disableResponse, disableRecovery, responseAttempt + 1, dataRequestAttempt, checkedNetworkAddress, discoveredRoute, assocRemove, assocRestore);
390
+ }
391
+ else {
392
+ throw error;
393
+ }
394
+ }
395
+ }
396
+ else {
397
+ return null;
398
+ }
399
+ }
400
+ async sendZclFrameToGroup(groupID, zclFrame) {
401
+ return this.driver.queue.execute(async () => {
402
+ this.checkInterpanLock();
403
+ const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, false);
404
+ frame.profileId = 0x0104;
405
+ frame.sourceEndpoint = 0x01;
406
+ frame.destinationEndpoint = 0x01;
407
+ frame.groupId = groupID;
408
+ const dataConfirmResult = await this.driver.mrequest(frame, zclFrame.toBuffer());
409
+ /**
410
+ * As a group command is not confirmed and thus immidiately returns
411
+ * (contrary to network address requests) we will give the
412
+ * command some time to 'settle' in the network.
413
+ */
414
+ await (0, utils_1.Wait)(200);
415
+ });
416
+ }
417
+ async sendZclFrameToAll(endpoint, zclFrame, sourceEndpoint) {
418
+ return this.driver.queue.execute(async () => {
419
+ this.checkInterpanLock();
420
+ const frame = this.driver.makeApsFrame(zclFrame.Cluster.ID, false);
421
+ frame.profileId = sourceEndpoint === 242 && endpoint === 242 ? 0xA1E0 : 0x0104;
422
+ frame.sourceEndpoint = sourceEndpoint;
423
+ frame.destinationEndpoint = endpoint;
424
+ frame.groupId = 0xFFFD;
425
+ const dataConfirmResult = await this.driver.mrequest(frame, zclFrame.toBuffer());
426
+ /**
427
+ * As a broadcast command is not confirmed and thus immidiately returns
428
+ * (contrary to network address requests) we will give the
429
+ * command some time to 'settle' in the network.
430
+ */
431
+ await (0, utils_1.Wait)(200);
432
+ });
433
+ }
434
+ async bind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
435
+ return this.driver.queue.execute(async () => {
436
+ this.checkInterpanLock();
437
+ const ieee = new types_1.EmberEUI64(sourceIeeeAddress);
438
+ const addrmode = (type === 'group') ? 1 : 3;
439
+ const ieeeDst = (type === 'group') ? destinationAddressOrGroup :
440
+ new types_1.EmberEUI64(destinationAddressOrGroup);
441
+ if (type !== 'group') {
442
+ this.driver.setNode(destinationNetworkAddress, ieeeDst);
443
+ }
444
+ await this.driver.zdoRequest(destinationNetworkAddress, types_1.EmberZDOCmd.Bind_req, types_1.EmberZDOCmd.Bind_rsp, { sourceEui: ieee, sourceEp: sourceEndpoint, clusterId: clusterID,
445
+ destAddr: { addrmode: addrmode, ieee: ieeeDst, endpoint: destinationEndpoint } });
446
+ }, destinationNetworkAddress);
447
+ }
448
+ async unbind(destinationNetworkAddress, sourceIeeeAddress, sourceEndpoint, clusterID, destinationAddressOrGroup, type, destinationEndpoint) {
449
+ return this.driver.queue.execute(async () => {
450
+ this.checkInterpanLock();
451
+ const ieee = new types_1.EmberEUI64(sourceIeeeAddress);
452
+ const addrmode = (type === 'group') ? 1 : 3;
453
+ const ieeeDst = (type === 'group') ? destinationAddressOrGroup :
454
+ new types_1.EmberEUI64(destinationAddressOrGroup);
455
+ if (type !== 'group') {
456
+ this.driver.setNode(destinationNetworkAddress, ieeeDst);
457
+ }
458
+ await this.driver.zdoRequest(destinationNetworkAddress, types_1.EmberZDOCmd.Unbind_req, types_1.EmberZDOCmd.Unbind_rsp, { sourceEui: ieee, sourceEp: sourceEndpoint, clusterId: clusterID,
459
+ destAddr: { addrmode: addrmode, ieee: ieeeDst, endpoint: destinationEndpoint } });
460
+ }, destinationNetworkAddress);
461
+ }
462
+ removeDevice(networkAddress, ieeeAddr) {
463
+ return this.driver.queue.execute(async () => {
464
+ this.checkInterpanLock();
465
+ const ieee = new types_1.EmberEUI64(ieeeAddr);
466
+ this.driver.setNode(networkAddress, ieee);
467
+ await this.driver.zdoRequest(networkAddress, types_1.EmberZDOCmd.Mgmt_Leave_req, types_1.EmberZDOCmd.Mgmt_Leave_rsp, { destAddr: ieee, removechildrenRejoin: 0x00 });
468
+ }, networkAddress);
469
+ }
470
+ async getNetworkParameters() {
471
+ return {
472
+ panID: this.driver.networkParams.panId,
473
+ extendedPanID: this.driver.networkParams.extendedPanId[0],
474
+ channel: this.driver.networkParams.radioChannel
475
+ };
476
+ }
477
+ async supportsBackup() {
478
+ return true;
479
+ }
480
+ async backup() {
481
+ return this.backupMan.createBackup();
482
+ }
483
+ async restoreChannelInterPAN() {
484
+ return this.driver.queue.execute(async () => {
485
+ const channel = (await this.getNetworkParameters()).channel;
486
+ await this.driver.setChannel(channel);
487
+ // Give adapter some time to restore, otherwise stuff crashes
488
+ await (0, utils_1.Wait)(3000);
489
+ this.interpanLock = false;
490
+ });
491
+ }
492
+ checkInterpanLock() {
493
+ if (this.interpanLock) {
494
+ throw new Error(`Cannot execute command, in Inter-PAN mode`);
495
+ }
496
+ }
497
+ async sendZclFrameInterPANToIeeeAddr(zclFrame, ieeeAddr) {
498
+ return this.driver.queue.execute(async () => {
499
+ debug(`sendZclFrameInterPANToIeeeAddr to ${ieeeAddr}`);
500
+ try {
501
+ const frame = this.driver.makeEmberIeeeRawFrame();
502
+ frame.ieeeFrameControl = 0xcc21;
503
+ frame.destPanId = 0xFFFF;
504
+ frame.destAddress = new types_1.EmberEUI64(ieeeAddr);
505
+ frame.sourcePanId = this.driver.networkParams.panId;
506
+ frame.sourceAddress = this.driver.ieee;
507
+ frame.nwkFrameControl = 0x000b;
508
+ frame.appFrameControl = 0x03;
509
+ frame.clusterId = zclFrame.Cluster.ID;
510
+ frame.profileId = 0xc05e;
511
+ const dataConfirmResult = await this.driver.ieeerawrequest(frame, zclFrame.toBuffer());
512
+ }
513
+ catch (error) {
514
+ throw error;
515
+ }
516
+ });
517
+ }
518
+ async sendZclFrameInterPANBroadcast(zclFrame, timeout) {
519
+ return this.driver.queue.execute(async () => {
520
+ debug(`sendZclFrameInterPANBroadcast`);
521
+ const command = zclFrame.getCommand();
522
+ if (!command.hasOwnProperty('response')) {
523
+ throw new Error(`Command '${command.name}' has no response, cannot wait for response`);
524
+ }
525
+ const response = this.waitForInternal(null, 0xFE, null, zclFrame.Cluster.ID, command.response, timeout);
526
+ try {
527
+ const frame = this.driver.makeEmberRawFrame();
528
+ frame.ieeeFrameControl = 0xc801;
529
+ frame.destPanId = 0xFFFF;
530
+ frame.destNodeId = 0xFFFF;
531
+ frame.sourcePanId = this.driver.networkParams.panId;
532
+ frame.ieeeAddress = this.driver.ieee;
533
+ frame.nwkFrameControl = 0x000b;
534
+ frame.appFrameControl = 0x0b;
535
+ frame.clusterId = zclFrame.Cluster.ID;
536
+ frame.profileId = 0xc05e;
537
+ const dataConfirmResult = await this.driver.rawrequest(frame, zclFrame.toBuffer());
538
+ }
539
+ catch (error) {
540
+ response.cancel();
541
+ throw error;
542
+ }
543
+ return response.start().promise;
544
+ });
545
+ }
546
+ async setTransmitPower(value) {
547
+ debug(`setTransmitPower to ${value}`);
548
+ return this.driver.queue.execute(async () => {
549
+ await this.driver.setRadioPower(value);
550
+ });
551
+ }
552
+ async setChannelInterPAN(channel) {
553
+ return this.driver.queue.execute(async () => {
554
+ this.interpanLock = true;
555
+ await this.driver.setChannel(channel);
556
+ });
557
+ }
558
+ waitForInternal(networkAddress, endpoint, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
559
+ const payload = {
560
+ address: networkAddress, endpoint, clusterID, commandIdentifier,
561
+ transactionSequenceNumber,
562
+ };
563
+ const waiter = this.waitress.waitFor(payload, timeout);
564
+ const cancel = () => this.waitress.remove(waiter.ID);
565
+ return { start: waiter.start, cancel };
566
+ }
567
+ waitFor(networkAddress, endpoint, frameType, direction, transactionSequenceNumber, clusterID, commandIdentifier, timeout) {
568
+ const waiter = this.waitForInternal(networkAddress, endpoint, transactionSequenceNumber, clusterID, commandIdentifier, timeout);
569
+ return { cancel: waiter.cancel, promise: waiter.start().promise };
570
+ }
571
+ waitressTimeoutFormatter(matcher, timeout) {
572
+ return `Timeout - ${matcher.address} - ${matcher.endpoint}` +
573
+ ` - ${matcher.transactionSequenceNumber} - ${matcher.clusterID}` +
574
+ ` - ${matcher.commandIdentifier} after ${timeout}ms`;
575
+ }
576
+ waitressValidator(payload, matcher) {
577
+ const transactionSequenceNumber = payload.frame.Header.transactionSequenceNumber;
578
+ return (!matcher.address || payload.address === matcher.address) &&
579
+ payload.endpoint === matcher.endpoint &&
580
+ (!matcher.transactionSequenceNumber || transactionSequenceNumber === matcher.transactionSequenceNumber) &&
581
+ payload.frame.Cluster.ID === matcher.clusterID &&
582
+ matcher.commandIdentifier === payload.frame.Header.commandIdentifier;
583
+ }
584
+ }
585
+ exports.default = EZSPAdapter;
586
586
  //# sourceMappingURL=ezspAdapter.js.map