@willieee802/zigbee-herdsman 0.19.2 → 0.34.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (530) hide show
  1. package/.babelrc.js +0 -4
  2. package/.release-please-manifest.json +1 -2
  3. package/CHANGELOG.md +376 -0
  4. package/README.md +1 -1
  5. package/dist/adapter/adapter.d.ts +61 -61
  6. package/dist/adapter/adapter.d.ts.map +1 -1
  7. package/dist/adapter/adapter.js +158 -146
  8. package/dist/adapter/adapter.js.map +1 -1
  9. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts +68 -68
  10. package/dist/adapter/deconz/adapter/deconzAdapter.d.ts.map +1 -1
  11. package/dist/adapter/deconz/adapter/deconzAdapter.js +1081 -1060
  12. package/dist/adapter/deconz/adapter/deconzAdapter.js.map +1 -1
  13. package/dist/adapter/deconz/adapter/index.d.ts +2 -2
  14. package/dist/adapter/deconz/adapter/index.js +10 -10
  15. package/dist/adapter/deconz/driver/constants.d.ts +104 -104
  16. package/dist/adapter/deconz/driver/constants.js +55 -55
  17. package/dist/adapter/deconz/driver/driver.d.ts +81 -81
  18. package/dist/adapter/deconz/driver/driver.d.ts.map +1 -1
  19. package/dist/adapter/deconz/driver/driver.js +750 -732
  20. package/dist/adapter/deconz/driver/driver.js.map +1 -1
  21. package/dist/adapter/deconz/driver/frame.d.ts +6 -6
  22. package/dist/adapter/deconz/driver/frame.js +13 -13
  23. package/dist/adapter/deconz/driver/frameParser.d.ts +2 -2
  24. package/dist/adapter/deconz/driver/frameParser.js +443 -443
  25. package/dist/adapter/deconz/driver/frameParser.js.map +1 -1
  26. package/dist/adapter/deconz/driver/parser.d.ts +12 -12
  27. package/dist/adapter/deconz/driver/parser.js +63 -61
  28. package/dist/adapter/deconz/driver/parser.js.map +1 -1
  29. package/dist/adapter/deconz/driver/writer.d.ts +8 -8
  30. package/dist/adapter/deconz/driver/writer.js +44 -44
  31. package/dist/adapter/ember/adapter/emberAdapter.d.ts +817 -0
  32. package/dist/adapter/ember/adapter/emberAdapter.d.ts.map +1 -0
  33. package/dist/adapter/ember/adapter/emberAdapter.js +2981 -0
  34. package/dist/adapter/ember/adapter/emberAdapter.js.map +1 -0
  35. package/dist/adapter/ember/adapter/endpoints.d.ts +25 -0
  36. package/dist/adapter/ember/adapter/endpoints.d.ts.map +1 -0
  37. package/dist/adapter/ember/adapter/endpoints.js +66 -0
  38. package/dist/adapter/ember/adapter/endpoints.js.map +1 -0
  39. package/dist/adapter/ember/adapter/index.d.ts +3 -0
  40. package/dist/adapter/ember/adapter/index.d.ts.map +1 -0
  41. package/dist/adapter/ember/adapter/index.js +6 -0
  42. package/dist/adapter/ember/adapter/index.js.map +1 -0
  43. package/dist/adapter/ember/adapter/oneWaitress.d.ts +97 -0
  44. package/dist/adapter/ember/adapter/oneWaitress.d.ts.map +1 -0
  45. package/dist/adapter/ember/adapter/oneWaitress.js +226 -0
  46. package/dist/adapter/ember/adapter/oneWaitress.js.map +1 -0
  47. package/dist/adapter/ember/adapter/requestQueue.d.ts +59 -0
  48. package/dist/adapter/ember/adapter/requestQueue.d.ts.map +1 -0
  49. package/dist/adapter/ember/adapter/requestQueue.js +144 -0
  50. package/dist/adapter/ember/adapter/requestQueue.js.map +1 -0
  51. package/dist/adapter/ember/adapter/tokensManager.d.ts +69 -0
  52. package/dist/adapter/ember/adapter/tokensManager.d.ts.map +1 -0
  53. package/dist/adapter/ember/adapter/tokensManager.js +685 -0
  54. package/dist/adapter/ember/adapter/tokensManager.js.map +1 -0
  55. package/dist/adapter/ember/consts.d.ts +198 -0
  56. package/dist/adapter/ember/consts.d.ts.map +1 -0
  57. package/dist/adapter/ember/consts.js +253 -0
  58. package/dist/adapter/ember/consts.js.map +1 -0
  59. package/dist/adapter/ember/enums.d.ts +2184 -0
  60. package/dist/adapter/ember/enums.d.ts.map +1 -0
  61. package/dist/adapter/ember/enums.js +2391 -0
  62. package/dist/adapter/ember/enums.js.map +1 -0
  63. package/dist/adapter/ember/ezsp/buffalo.d.ts +156 -0
  64. package/dist/adapter/ember/ezsp/buffalo.d.ts.map +1 -0
  65. package/dist/adapter/ember/ezsp/buffalo.js +1033 -0
  66. package/dist/adapter/ember/ezsp/buffalo.js.map +1 -0
  67. package/dist/adapter/ember/ezsp/consts.d.ts +116 -0
  68. package/dist/adapter/ember/ezsp/consts.d.ts.map +1 -0
  69. package/dist/adapter/ember/ezsp/consts.js +128 -0
  70. package/dist/adapter/ember/ezsp/consts.js.map +1 -0
  71. package/dist/adapter/ember/ezsp/enums.d.ts +879 -0
  72. package/dist/adapter/ember/ezsp/enums.d.ts.map +1 -0
  73. package/dist/adapter/ember/ezsp/enums.js +948 -0
  74. package/dist/adapter/ember/ezsp/enums.js.map +1 -0
  75. package/dist/adapter/ember/ezsp/ezsp.d.ts +2664 -0
  76. package/dist/adapter/ember/ezsp/ezsp.d.ts.map +1 -0
  77. package/dist/adapter/ember/ezsp/ezsp.js +6438 -0
  78. package/dist/adapter/ember/ezsp/ezsp.js.map +1 -0
  79. package/dist/adapter/ember/types.d.ts +733 -0
  80. package/dist/adapter/ember/types.d.ts.map +1 -0
  81. package/dist/adapter/ember/types.js +3 -0
  82. package/dist/adapter/ember/types.js.map +1 -0
  83. package/dist/adapter/ember/uart/ash.d.ts +451 -0
  84. package/dist/adapter/ember/uart/ash.d.ts.map +1 -0
  85. package/dist/adapter/ember/uart/ash.js +1584 -0
  86. package/dist/adapter/ember/uart/ash.js.map +1 -0
  87. package/dist/adapter/ember/uart/consts.d.ts +91 -0
  88. package/dist/adapter/ember/uart/consts.d.ts.map +1 -0
  89. package/dist/adapter/ember/uart/consts.js +100 -0
  90. package/dist/adapter/ember/uart/consts.js.map +1 -0
  91. package/dist/adapter/ember/uart/enums.d.ts +191 -0
  92. package/dist/adapter/ember/uart/enums.d.ts.map +1 -0
  93. package/dist/adapter/ember/uart/enums.js +197 -0
  94. package/dist/adapter/ember/uart/enums.js.map +1 -0
  95. package/dist/adapter/ember/uart/parser.d.ts +10 -0
  96. package/dist/adapter/ember/uart/parser.d.ts.map +1 -0
  97. package/dist/adapter/ember/uart/parser.js +41 -0
  98. package/dist/adapter/ember/uart/parser.js.map +1 -0
  99. package/dist/adapter/ember/uart/queues.d.ts +85 -0
  100. package/dist/adapter/ember/uart/queues.d.ts.map +1 -0
  101. package/dist/adapter/ember/uart/queues.js +212 -0
  102. package/dist/adapter/ember/uart/queues.js.map +1 -0
  103. package/dist/adapter/ember/uart/writer.d.ts +15 -0
  104. package/dist/adapter/ember/uart/writer.d.ts.map +1 -0
  105. package/dist/adapter/ember/uart/writer.js +48 -0
  106. package/dist/adapter/ember/uart/writer.js.map +1 -0
  107. package/dist/adapter/ember/utils/initters.d.ts +20 -0
  108. package/dist/adapter/ember/utils/initters.d.ts.map +1 -0
  109. package/dist/adapter/ember/utils/initters.js +58 -0
  110. package/dist/adapter/ember/utils/initters.js.map +1 -0
  111. package/dist/adapter/ember/utils/math.d.ts +51 -0
  112. package/dist/adapter/ember/utils/math.d.ts.map +1 -0
  113. package/dist/adapter/ember/utils/math.js +102 -0
  114. package/dist/adapter/ember/utils/math.js.map +1 -0
  115. package/dist/adapter/ember/zdo.d.ts +921 -0
  116. package/dist/adapter/ember/zdo.d.ts.map +1 -0
  117. package/dist/adapter/ember/zdo.js +723 -0
  118. package/dist/adapter/ember/zdo.js.map +1 -0
  119. package/dist/adapter/events.d.ts +47 -47
  120. package/dist/adapter/events.js +13 -14
  121. package/dist/adapter/events.js.map +1 -1
  122. package/dist/adapter/ezsp/adapter/backup.d.ts +9 -9
  123. package/dist/adapter/ezsp/adapter/backup.d.ts.map +1 -1
  124. package/dist/adapter/ezsp/adapter/backup.js +72 -53
  125. package/dist/adapter/ezsp/adapter/backup.js.map +1 -1
  126. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts +61 -59
  127. package/dist/adapter/ezsp/adapter/ezspAdapter.d.ts.map +1 -1
  128. package/dist/adapter/ezsp/adapter/ezspAdapter.js +629 -603
  129. package/dist/adapter/ezsp/adapter/ezspAdapter.js.map +1 -1
  130. package/dist/adapter/ezsp/adapter/index.d.ts +2 -2
  131. package/dist/adapter/ezsp/adapter/index.js +10 -10
  132. package/dist/adapter/ezsp/driver/commands.d.ts +36 -36
  133. package/dist/adapter/ezsp/driver/commands.d.ts.map +1 -1
  134. package/dist/adapter/ezsp/driver/commands.js +2388 -2359
  135. package/dist/adapter/ezsp/driver/commands.js.map +1 -1
  136. package/dist/adapter/ezsp/driver/consts.d.ts +10 -10
  137. package/dist/adapter/ezsp/driver/consts.js +13 -13
  138. package/dist/adapter/ezsp/driver/driver.d.ts +106 -103
  139. package/dist/adapter/ezsp/driver/driver.d.ts.map +1 -1
  140. package/dist/adapter/ezsp/driver/driver.js +731 -639
  141. package/dist/adapter/ezsp/driver/driver.js.map +1 -1
  142. package/dist/adapter/ezsp/driver/ezsp.d.ts +105 -96
  143. package/dist/adapter/ezsp/driver/ezsp.d.ts.map +1 -1
  144. package/dist/adapter/ezsp/driver/ezsp.js +651 -586
  145. package/dist/adapter/ezsp/driver/ezsp.js.map +1 -1
  146. package/dist/adapter/ezsp/driver/frame.d.ts +40 -0
  147. package/dist/adapter/ezsp/driver/frame.d.ts.map +1 -0
  148. package/dist/adapter/ezsp/driver/frame.js +101 -0
  149. package/dist/adapter/ezsp/driver/frame.js.map +1 -0
  150. package/dist/adapter/ezsp/driver/index.d.ts +3 -3
  151. package/dist/adapter/ezsp/driver/index.js +8 -8
  152. package/dist/adapter/ezsp/driver/multicast.d.ts +12 -12
  153. package/dist/adapter/ezsp/driver/multicast.d.ts.map +1 -1
  154. package/dist/adapter/ezsp/driver/multicast.js +77 -74
  155. package/dist/adapter/ezsp/driver/multicast.js.map +1 -1
  156. package/dist/adapter/ezsp/driver/parser.d.ts +11 -12
  157. package/dist/adapter/ezsp/driver/parser.d.ts.map +1 -1
  158. package/dist/adapter/ezsp/driver/parser.js +104 -111
  159. package/dist/adapter/ezsp/driver/parser.js.map +1 -1
  160. package/dist/adapter/ezsp/driver/types/basic.d.ts +62 -62
  161. package/dist/adapter/ezsp/driver/types/basic.js +208 -208
  162. package/dist/adapter/ezsp/driver/types/basic.js.map +1 -1
  163. package/dist/adapter/ezsp/driver/types/index.d.ts +9 -9
  164. package/dist/adapter/ezsp/driver/types/index.d.ts.map +1 -1
  165. package/dist/adapter/ezsp/driver/types/index.js +138 -133
  166. package/dist/adapter/ezsp/driver/types/index.js.map +1 -1
  167. package/dist/adapter/ezsp/driver/types/named.d.ts +1287 -697
  168. package/dist/adapter/ezsp/driver/types/named.d.ts.map +1 -1
  169. package/dist/adapter/ezsp/driver/types/named.js +2329 -1726
  170. package/dist/adapter/ezsp/driver/types/named.js.map +1 -1
  171. package/dist/adapter/ezsp/driver/types/struct.d.ts +270 -251
  172. package/dist/adapter/ezsp/driver/types/struct.d.ts.map +1 -1
  173. package/dist/adapter/ezsp/driver/types/struct.js +803 -708
  174. package/dist/adapter/ezsp/driver/types/struct.js.map +1 -1
  175. package/dist/adapter/ezsp/driver/uart.d.ts +48 -44
  176. package/dist/adapter/ezsp/driver/uart.d.ts.map +1 -1
  177. package/dist/adapter/ezsp/driver/uart.js +382 -368
  178. package/dist/adapter/ezsp/driver/uart.js.map +1 -1
  179. package/dist/adapter/ezsp/driver/utils/crc16ccitt.d.ts +2 -2
  180. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js +55 -55
  181. package/dist/adapter/ezsp/driver/utils/crc16ccitt.js.map +1 -1
  182. package/dist/adapter/ezsp/driver/utils/index.d.ts +18 -18
  183. package/dist/adapter/ezsp/driver/utils/index.js +72 -67
  184. package/dist/adapter/ezsp/driver/utils/index.js.map +1 -1
  185. package/dist/adapter/ezsp/driver/writer.d.ts +13 -13
  186. package/dist/adapter/ezsp/driver/writer.d.ts.map +1 -1
  187. package/dist/adapter/ezsp/driver/writer.js +85 -88
  188. package/dist/adapter/ezsp/driver/writer.js.map +1 -1
  189. package/dist/adapter/index.d.ts +4 -4
  190. package/dist/adapter/index.js +35 -35
  191. package/dist/adapter/serialPort.d.ts +10 -8
  192. package/dist/adapter/serialPort.d.ts.map +1 -1
  193. package/dist/adapter/serialPort.js +53 -22
  194. package/dist/adapter/serialPort.js.map +1 -1
  195. package/dist/adapter/serialPortUtils.d.ts +12 -12
  196. package/dist/adapter/serialPortUtils.js +18 -18
  197. package/dist/adapter/serialPortUtils.js.map +1 -1
  198. package/dist/adapter/socketPortUtils.d.ts +10 -10
  199. package/dist/adapter/socketPortUtils.js +16 -16
  200. package/dist/adapter/tstype.d.ts +85 -85
  201. package/dist/adapter/tstype.d.ts.map +1 -1
  202. package/dist/adapter/tstype.js +2 -2
  203. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts +62 -62
  204. package/dist/adapter/z-stack/adapter/adapter-backup.d.ts.map +1 -1
  205. package/dist/adapter/z-stack/adapter/adapter-backup.js +462 -460
  206. package/dist/adapter/z-stack/adapter/adapter-backup.js.map +1 -1
  207. package/dist/adapter/z-stack/adapter/adapter-nv-memory.d.ts +150 -150
  208. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js +258 -258
  209. package/dist/adapter/z-stack/adapter/adapter-nv-memory.js.map +1 -1
  210. package/dist/adapter/z-stack/adapter/endpoints.d.ts +11 -11
  211. package/dist/adapter/z-stack/adapter/endpoints.js +73 -73
  212. package/dist/adapter/z-stack/adapter/index.d.ts +2 -2
  213. package/dist/adapter/z-stack/adapter/index.js +8 -8
  214. package/dist/adapter/z-stack/adapter/manager.d.ts +86 -86
  215. package/dist/adapter/z-stack/adapter/manager.d.ts.map +1 -1
  216. package/dist/adapter/z-stack/adapter/manager.js +482 -476
  217. package/dist/adapter/z-stack/adapter/manager.js.map +1 -1
  218. package/dist/adapter/z-stack/adapter/tstype.d.ts +6 -6
  219. package/dist/adapter/z-stack/adapter/tstype.js +9 -10
  220. package/dist/adapter/z-stack/adapter/tstype.js.map +1 -1
  221. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts +81 -81
  222. package/dist/adapter/z-stack/adapter/zStackAdapter.d.ts.map +1 -1
  223. package/dist/adapter/z-stack/adapter/zStackAdapter.js +891 -868
  224. package/dist/adapter/z-stack/adapter/zStackAdapter.js.map +1 -1
  225. package/dist/adapter/z-stack/constants/af.d.ts +23 -23
  226. package/dist/adapter/z-stack/constants/af.js +27 -27
  227. package/dist/adapter/z-stack/constants/common.d.ts +278 -278
  228. package/dist/adapter/z-stack/constants/common.d.ts.map +1 -1
  229. package/dist/adapter/z-stack/constants/common.js +292 -289
  230. package/dist/adapter/z-stack/constants/common.js.map +1 -1
  231. package/dist/adapter/z-stack/constants/dbg.d.ts +22 -22
  232. package/dist/adapter/z-stack/constants/dbg.js +24 -24
  233. package/dist/adapter/z-stack/constants/index.d.ts +10 -10
  234. package/dist/adapter/z-stack/constants/index.js +47 -47
  235. package/dist/adapter/z-stack/constants/mac.d.ts +127 -127
  236. package/dist/adapter/z-stack/constants/mac.js +129 -129
  237. package/dist/adapter/z-stack/constants/sapi.d.ts +24 -24
  238. package/dist/adapter/z-stack/constants/sapi.js +26 -26
  239. package/dist/adapter/z-stack/constants/sys.d.ts +71 -71
  240. package/dist/adapter/z-stack/constants/sys.js +73 -73
  241. package/dist/adapter/z-stack/constants/util.d.ts +81 -81
  242. package/dist/adapter/z-stack/constants/util.js +83 -83
  243. package/dist/adapter/z-stack/constants/utils.d.ts +4 -4
  244. package/dist/adapter/z-stack/constants/utils.js +14 -14
  245. package/dist/adapter/z-stack/constants/zdo.d.ts +102 -102
  246. package/dist/adapter/z-stack/constants/zdo.js +104 -104
  247. package/dist/adapter/z-stack/models/index.d.ts +1 -1
  248. package/dist/adapter/z-stack/models/index.js +17 -17
  249. package/dist/adapter/z-stack/models/startup-options.d.ts +12 -12
  250. package/dist/adapter/z-stack/models/startup-options.js +2 -2
  251. package/dist/adapter/z-stack/structs/entries/address-manager-entry.d.ts +23 -23
  252. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js +45 -45
  253. package/dist/adapter/z-stack/structs/entries/address-manager-entry.js.map +1 -1
  254. package/dist/adapter/z-stack/structs/entries/address-manager-table.d.ts +10 -10
  255. package/dist/adapter/z-stack/structs/entries/address-manager-table.js +22 -22
  256. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.d.ts +10 -10
  257. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-entry.js +21 -21
  258. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.d.ts +10 -10
  259. package/dist/adapter/z-stack/structs/entries/aps-link-key-data-table.js +23 -23
  260. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.d.ts +10 -10
  261. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-entry.js +24 -24
  262. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.d.ts +10 -10
  263. package/dist/adapter/z-stack/structs/entries/aps-tc-link-key-table.js +23 -23
  264. package/dist/adapter/z-stack/structs/entries/channel-list.d.ts +8 -8
  265. package/dist/adapter/z-stack/structs/entries/channel-list.js +15 -15
  266. package/dist/adapter/z-stack/structs/entries/has-configured.d.ts +8 -8
  267. package/dist/adapter/z-stack/structs/entries/has-configured.js +16 -16
  268. package/dist/adapter/z-stack/structs/entries/index.d.ts +16 -16
  269. package/dist/adapter/z-stack/structs/entries/index.js +32 -32
  270. package/dist/adapter/z-stack/structs/entries/nib.d.ts +10 -10
  271. package/dist/adapter/z-stack/structs/entries/nib.js +68 -68
  272. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.d.ts +10 -10
  273. package/dist/adapter/z-stack/structs/entries/nwk-key-descriptor.js +18 -18
  274. package/dist/adapter/z-stack/structs/entries/nwk-key.d.ts +8 -8
  275. package/dist/adapter/z-stack/structs/entries/nwk-key.js +15 -15
  276. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.d.ts +8 -8
  277. package/dist/adapter/z-stack/structs/entries/nwk-pan-id.js +15 -15
  278. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.d.ts +13 -13
  279. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.js +23 -23
  280. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.d.ts +10 -10
  281. package/dist/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.js +22 -22
  282. package/dist/adapter/z-stack/structs/entries/security-manager-entry.d.ts +20 -20
  283. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js +36 -36
  284. package/dist/adapter/z-stack/structs/entries/security-manager-entry.js.map +1 -1
  285. package/dist/adapter/z-stack/structs/entries/security-manager-table.d.ts +10 -10
  286. package/dist/adapter/z-stack/structs/entries/security-manager-table.js +24 -24
  287. package/dist/adapter/z-stack/structs/index.d.ts +4 -4
  288. package/dist/adapter/z-stack/structs/index.js +20 -20
  289. package/dist/adapter/z-stack/structs/serializable-memory-object.d.ts +13 -13
  290. package/dist/adapter/z-stack/structs/serializable-memory-object.js +2 -2
  291. package/dist/adapter/z-stack/structs/struct.d.ts +99 -99
  292. package/dist/adapter/z-stack/structs/struct.js +296 -295
  293. package/dist/adapter/z-stack/structs/struct.js.map +1 -1
  294. package/dist/adapter/z-stack/structs/table.d.ts +94 -94
  295. package/dist/adapter/z-stack/structs/table.js +163 -161
  296. package/dist/adapter/z-stack/structs/table.js.map +1 -1
  297. package/dist/adapter/z-stack/unpi/constants.d.ts +28 -28
  298. package/dist/adapter/z-stack/unpi/constants.js +39 -41
  299. package/dist/adapter/z-stack/unpi/constants.js.map +1 -1
  300. package/dist/adapter/z-stack/unpi/frame.d.ts +16 -16
  301. package/dist/adapter/z-stack/unpi/frame.js +54 -48
  302. package/dist/adapter/z-stack/unpi/frame.js.map +1 -1
  303. package/dist/adapter/z-stack/unpi/index.d.ts +5 -5
  304. package/dist/adapter/z-stack/unpi/index.js +37 -37
  305. package/dist/adapter/z-stack/unpi/parser.d.ts +10 -10
  306. package/dist/adapter/z-stack/unpi/parser.js +75 -74
  307. package/dist/adapter/z-stack/unpi/parser.js.map +1 -1
  308. package/dist/adapter/z-stack/unpi/writer.d.ts +10 -10
  309. package/dist/adapter/z-stack/unpi/writer.js +44 -44
  310. package/dist/adapter/z-stack/utils/channel-list.d.ts +20 -20
  311. package/dist/adapter/z-stack/utils/channel-list.js +40 -40
  312. package/dist/adapter/z-stack/utils/channel-list.js.map +1 -1
  313. package/dist/adapter/z-stack/utils/index.d.ts +2 -2
  314. package/dist/adapter/z-stack/utils/index.js +18 -18
  315. package/dist/adapter/z-stack/utils/network-options.d.ts +8 -8
  316. package/dist/adapter/z-stack/utils/network-options.js +22 -22
  317. package/dist/adapter/z-stack/znp/buffaloZnp.d.ts +11 -11
  318. package/dist/adapter/z-stack/znp/buffaloZnp.js +113 -113
  319. package/dist/adapter/z-stack/znp/buffaloZnp.js.map +1 -1
  320. package/dist/adapter/z-stack/znp/definition.d.ts +5 -5
  321. package/dist/adapter/z-stack/znp/definition.js +3050 -3050
  322. package/dist/adapter/z-stack/znp/index.d.ts +3 -3
  323. package/dist/adapter/z-stack/znp/index.js +10 -10
  324. package/dist/adapter/z-stack/znp/parameterType.d.ts +22 -22
  325. package/dist/adapter/z-stack/znp/parameterType.js +25 -25
  326. package/dist/adapter/z-stack/znp/tstype.d.ts +21 -21
  327. package/dist/adapter/z-stack/znp/tstype.js +2 -2
  328. package/dist/adapter/z-stack/znp/znp.d.ts +44 -43
  329. package/dist/adapter/z-stack/znp/znp.d.ts.map +1 -1
  330. package/dist/adapter/z-stack/znp/znp.js +326 -325
  331. package/dist/adapter/z-stack/znp/znp.js.map +1 -1
  332. package/dist/adapter/z-stack/znp/zpiObject.d.ts +19 -19
  333. package/dist/adapter/z-stack/znp/zpiObject.js +102 -96
  334. package/dist/adapter/z-stack/znp/zpiObject.js.map +1 -1
  335. package/dist/adapter/zigate/adapter/index.d.ts +2 -2
  336. package/dist/adapter/zigate/adapter/index.js +10 -10
  337. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts +70 -69
  338. package/dist/adapter/zigate/adapter/zigateAdapter.d.ts.map +1 -1
  339. package/dist/adapter/zigate/adapter/zigateAdapter.js +689 -678
  340. package/dist/adapter/zigate/adapter/zigateAdapter.js.map +1 -1
  341. package/dist/adapter/zigate/debug.d.ts +7 -7
  342. package/dist/adapter/zigate/debug.d.ts.map +1 -1
  343. package/dist/adapter/zigate/debug.js +19 -22
  344. package/dist/adapter/zigate/debug.js.map +1 -1
  345. package/dist/adapter/zigate/driver/buffaloZiGate.d.ts +18 -18
  346. package/dist/adapter/zigate/driver/buffaloZiGate.js +139 -139
  347. package/dist/adapter/zigate/driver/buffaloZiGate.js.map +1 -1
  348. package/dist/adapter/zigate/driver/commandType.d.ts +41 -41
  349. package/dist/adapter/zigate/driver/commandType.js +385 -385
  350. package/dist/adapter/zigate/driver/commandType.js.map +1 -1
  351. package/dist/adapter/zigate/driver/constants.d.ts +276 -276
  352. package/dist/adapter/zigate/driver/constants.d.ts.map +1 -1
  353. package/dist/adapter/zigate/driver/constants.js +371 -371
  354. package/dist/adapter/zigate/driver/constants.js.map +1 -1
  355. package/dist/adapter/zigate/driver/frame.d.ts +26 -26
  356. package/dist/adapter/zigate/driver/frame.js +172 -172
  357. package/dist/adapter/zigate/driver/frame.js.map +1 -1
  358. package/dist/adapter/zigate/driver/messageType.d.ts +11 -11
  359. package/dist/adapter/zigate/driver/messageType.js +278 -278
  360. package/dist/adapter/zigate/driver/messageType.js.map +1 -1
  361. package/dist/adapter/zigate/driver/parameterType.d.ts +20 -20
  362. package/dist/adapter/zigate/driver/parameterType.js +23 -23
  363. package/dist/adapter/zigate/driver/ziGateObject.d.ts +23 -23
  364. package/dist/adapter/zigate/driver/ziGateObject.js +110 -106
  365. package/dist/adapter/zigate/driver/ziGateObject.js.map +1 -1
  366. package/dist/adapter/zigate/driver/zigate.d.ts +49 -49
  367. package/dist/adapter/zigate/driver/zigate.d.ts.map +1 -1
  368. package/dist/adapter/zigate/driver/zigate.js +296 -303
  369. package/dist/adapter/zigate/driver/zigate.js.map +1 -1
  370. package/dist/buffalo/buffalo.d.ts +50 -50
  371. package/dist/buffalo/buffalo.js +324 -322
  372. package/dist/buffalo/buffalo.js.map +1 -1
  373. package/dist/buffalo/index.d.ts +3 -3
  374. package/dist/buffalo/index.js +33 -33
  375. package/dist/buffalo/tstype.d.ts +8 -8
  376. package/dist/buffalo/tstype.js +2 -2
  377. package/dist/controller/controller.d.ts +113 -113
  378. package/dist/controller/controller.d.ts.map +1 -1
  379. package/dist/controller/controller.js +641 -619
  380. package/dist/controller/controller.js.map +1 -1
  381. package/dist/controller/database.d.ts +18 -18
  382. package/dist/controller/database.js +96 -93
  383. package/dist/controller/database.js.map +1 -1
  384. package/dist/controller/events.d.ts +58 -58
  385. package/dist/controller/events.d.ts.map +1 -1
  386. package/dist/controller/events.js +108 -101
  387. package/dist/controller/events.js.map +1 -1
  388. package/dist/controller/greenPower.d.ts +12 -12
  389. package/dist/controller/greenPower.js +221 -220
  390. package/dist/controller/greenPower.js.map +1 -1
  391. package/dist/controller/helpers/index.d.ts +2 -2
  392. package/dist/controller/helpers/index.js +28 -28
  393. package/dist/controller/helpers/request.d.ts +21 -22
  394. package/dist/controller/helpers/request.d.ts.map +1 -1
  395. package/dist/controller/helpers/request.js +77 -71
  396. package/dist/controller/helpers/request.js.map +1 -1
  397. package/dist/controller/helpers/requestQueue.d.ts +13 -0
  398. package/dist/controller/helpers/requestQueue.d.ts.map +1 -0
  399. package/dist/controller/helpers/requestQueue.js +116 -0
  400. package/dist/controller/helpers/requestQueue.js.map +1 -0
  401. package/dist/controller/helpers/zclFrameConverter.d.ts +7 -7
  402. package/dist/controller/helpers/zclFrameConverter.d.ts.map +1 -1
  403. package/dist/controller/helpers/zclFrameConverter.js +50 -31
  404. package/dist/controller/helpers/zclFrameConverter.js.map +1 -1
  405. package/dist/controller/helpers/zclTransactionSequenceNumber.d.ts +5 -5
  406. package/dist/controller/helpers/zclTransactionSequenceNumber.js +13 -13
  407. package/dist/controller/helpers/zclTransactionSequenceNumber.js.map +1 -1
  408. package/dist/controller/index.d.ts +5 -5
  409. package/dist/controller/index.js +8 -8
  410. package/dist/controller/logger-stub.d.ts +6 -6
  411. package/dist/controller/logger-stub.js +2 -2
  412. package/dist/controller/model/device.d.ts +132 -133
  413. package/dist/controller/model/device.d.ts.map +1 -1
  414. package/dist/controller/model/device.js +724 -717
  415. package/dist/controller/model/device.js.map +1 -1
  416. package/dist/controller/model/endpoint.d.ts +128 -131
  417. package/dist/controller/model/endpoint.d.ts.map +1 -1
  418. package/dist/controller/model/endpoint.js +755 -816
  419. package/dist/controller/model/endpoint.js.map +1 -1
  420. package/dist/controller/model/entity.d.ts +14 -14
  421. package/dist/controller/model/entity.js +26 -26
  422. package/dist/controller/model/entity.js.map +1 -1
  423. package/dist/controller/model/group.d.ts +38 -38
  424. package/dist/controller/model/group.d.ts.map +1 -1
  425. package/dist/controller/model/group.js +225 -221
  426. package/dist/controller/model/group.js.map +1 -1
  427. package/dist/controller/model/index.d.ts +5 -5
  428. package/dist/controller/model/index.js +14 -14
  429. package/dist/controller/touchlink.d.ts +19 -19
  430. package/dist/controller/touchlink.js +159 -157
  431. package/dist/controller/touchlink.js.map +1 -1
  432. package/dist/controller/tstype.d.ts +20 -21
  433. package/dist/controller/tstype.d.ts.map +1 -1
  434. package/dist/controller/tstype.js +8 -9
  435. package/dist/controller/tstype.js.map +1 -1
  436. package/dist/index.d.ts +3 -3
  437. package/dist/index.js +33 -33
  438. package/dist/models/backup-storage-legacy.d.ts +26 -26
  439. package/dist/models/backup-storage-legacy.js +2 -2
  440. package/dist/models/backup-storage-unified.d.ts +49 -49
  441. package/dist/models/backup-storage-unified.js +2 -2
  442. package/dist/models/backup.d.ts +37 -37
  443. package/dist/models/backup.js +2 -2
  444. package/dist/models/index.d.ts +4 -4
  445. package/dist/models/index.js +20 -20
  446. package/dist/models/network-options.d.ts +12 -12
  447. package/dist/models/network-options.js +2 -2
  448. package/dist/utils/assertString.d.ts +2 -2
  449. package/dist/utils/assertString.js +8 -8
  450. package/dist/utils/assertString.js.map +1 -1
  451. package/dist/utils/backup.d.ts +20 -20
  452. package/dist/utils/backup.d.ts.map +1 -1
  453. package/dist/utils/backup.js +189 -187
  454. package/dist/utils/backup.js.map +1 -1
  455. package/dist/utils/equalsPartial.d.ts +2 -2
  456. package/dist/utils/equalsPartial.js +11 -11
  457. package/dist/utils/index.d.ts +9 -9
  458. package/dist/utils/index.js +45 -45
  459. package/dist/utils/isNumberArray.d.ts +2 -2
  460. package/dist/utils/isNumberArray.js +6 -6
  461. package/dist/utils/queue.d.ts +11 -11
  462. package/dist/utils/queue.d.ts.map +1 -1
  463. package/dist/utils/queue.js +61 -50
  464. package/dist/utils/queue.js.map +1 -1
  465. package/dist/utils/realpathSync.d.ts +2 -2
  466. package/dist/utils/realpathSync.js +12 -12
  467. package/dist/utils/wait.d.ts +2 -2
  468. package/dist/utils/wait.js +8 -8
  469. package/dist/utils/waitress.d.ts +21 -21
  470. package/dist/utils/waitress.d.ts.map +1 -1
  471. package/dist/utils/waitress.js +68 -61
  472. package/dist/utils/waitress.js.map +1 -1
  473. package/dist/zcl/buffaloZcl.d.ts +41 -41
  474. package/dist/zcl/buffaloZcl.d.ts.map +1 -1
  475. package/dist/zcl/buffaloZcl.js +594 -591
  476. package/dist/zcl/buffaloZcl.js.map +1 -1
  477. package/dist/zcl/definition/buffaloZclDataType.d.ts +17 -17
  478. package/dist/zcl/definition/buffaloZclDataType.js +20 -20
  479. package/dist/zcl/definition/cluster.d.ts +29 -29
  480. package/dist/zcl/definition/cluster.d.ts.map +1 -1
  481. package/dist/zcl/definition/cluster.js +5520 -5335
  482. package/dist/zcl/definition/cluster.js.map +1 -1
  483. package/dist/zcl/definition/dataType.d.ts +59 -59
  484. package/dist/zcl/definition/dataType.js +64 -64
  485. package/dist/zcl/definition/direction.d.ts +5 -5
  486. package/dist/zcl/definition/direction.js +8 -8
  487. package/dist/zcl/definition/endpointDeviceType.d.ts +4 -4
  488. package/dist/zcl/definition/endpointDeviceType.js +15 -15
  489. package/dist/zcl/definition/foundation.d.ts +11 -11
  490. package/dist/zcl/definition/foundation.js +167 -167
  491. package/dist/zcl/definition/frameControl.d.ts +10 -10
  492. package/dist/zcl/definition/frameControl.js +2 -2
  493. package/dist/zcl/definition/frameType.d.ts +5 -5
  494. package/dist/zcl/definition/frameType.js +8 -8
  495. package/dist/zcl/definition/index.d.ts +13 -13
  496. package/dist/zcl/definition/index.js +51 -51
  497. package/dist/zcl/definition/manufacturerCode.d.ts +1077 -1074
  498. package/dist/zcl/definition/manufacturerCode.d.ts.map +1 -1
  499. package/dist/zcl/definition/manufacturerCode.js +1082 -1079
  500. package/dist/zcl/definition/manufacturerCode.js.map +1 -1
  501. package/dist/zcl/definition/powerSource.d.ts +4 -4
  502. package/dist/zcl/definition/powerSource.js +12 -12
  503. package/dist/zcl/definition/status.d.ts +38 -38
  504. package/dist/zcl/definition/status.js +41 -41
  505. package/dist/zcl/definition/tstype.d.ts +16 -16
  506. package/dist/zcl/definition/tstype.js +2 -2
  507. package/dist/zcl/index.d.ts +16 -15
  508. package/dist/zcl/index.d.ts.map +1 -1
  509. package/dist/zcl/index.js +55 -55
  510. package/dist/zcl/index.js.map +1 -1
  511. package/dist/zcl/tstype.d.ts +56 -56
  512. package/dist/zcl/tstype.js +9 -10
  513. package/dist/zcl/tstype.js.map +1 -1
  514. package/dist/zcl/utils.d.ts +6 -6
  515. package/dist/zcl/utils.js +164 -165
  516. package/dist/zcl/utils.js.map +1 -1
  517. package/dist/zcl/zclFrame.d.ts +40 -45
  518. package/dist/zcl/zclFrame.d.ts.map +1 -1
  519. package/dist/zcl/zclFrame.js +351 -347
  520. package/dist/zcl/zclFrame.js.map +1 -1
  521. package/dist/zcl/zclHeader.d.ts +9 -0
  522. package/dist/zcl/zclHeader.d.ts.map +1 -0
  523. package/dist/zcl/zclHeader.js +3 -0
  524. package/dist/zcl/zclHeader.js.map +1 -0
  525. package/dist/zcl/zclStatusError.d.ts +5 -5
  526. package/dist/zcl/zclStatusError.js +14 -13
  527. package/dist/zcl/zclStatusError.js.map +1 -1
  528. package/package.json +11 -11
  529. package/release-please-config.json +1 -5
  530. package/tsconfig.json +4 -2
@@ -1,817 +1,756 @@
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 entity_1 = __importDefault(require("./entity"));
30
- const Zcl = __importStar(require("../../zcl"));
31
- const zclTransactionSequenceNumber_1 = __importDefault(require("../helpers/zclTransactionSequenceNumber"));
32
- const ZclFrameConverter = __importStar(require("../helpers/zclFrameConverter"));
33
- const request_1 = __importDefault(require("../helpers/request"));
34
- const group_1 = __importDefault(require("./group"));
35
- const device_1 = __importDefault(require("./device"));
36
- const debug_1 = __importDefault(require("debug"));
37
- const assert_1 = __importDefault(require("assert"));
38
- const debug = {
39
- info: (0, debug_1.default)('zigbee-herdsman:controller:endpoint'),
40
- error: (0, debug_1.default)('zigbee-herdsman:controller:endpoint'),
41
- };
42
- class Endpoint extends entity_1.default {
43
- // Getters/setters
44
- get binds() {
45
- return this._binds
46
- .map((entry) => {
47
- let target = null;
48
- if (entry.type === 'endpoint') {
49
- const device = device_1.default.byIeeeAddr(this.databaseID, entry.deviceIeeeAddress);
50
- if (device) {
51
- target = device.getEndpoint(entry.endpointID);
52
- }
53
- }
54
- else {
55
- target = group_1.default.byGroupID(entry.groupID, this.databaseID);
56
- }
57
- if (target) {
58
- return { target, cluster: Zcl.Utils.getCluster(entry.cluster, this.getDevice().manufacturerID) };
59
- }
60
- else {
61
- return undefined;
62
- }
63
- }).filter(b => b !== undefined);
64
- }
65
- get configuredReportings() {
66
- return this._configuredReportings.map((entry) => {
67
- const cluster = Zcl.Utils.getCluster(entry.cluster, this.getDevice().manufacturerID);
68
- let attribute;
69
- if (cluster.hasAttribute(entry.attrId)) {
70
- attribute = cluster.getAttribute(entry.attrId);
71
- }
72
- else {
73
- attribute = {
74
- ID: entry.attrId,
75
- name: undefined,
76
- type: undefined,
77
- manufacturerCode: undefined,
78
- };
79
- }
80
- return {
81
- cluster,
82
- attribute,
83
- minimumReportInterval: entry.minRepIntval,
84
- maximumReportInterval: entry.maxRepIntval,
85
- reportableChange: entry.repChange,
86
- };
87
- });
88
- }
89
- constructor(databaseID, ID, profileID, deviceID, inputClusters, outputClusters, deviceNetworkAddress, deviceIeeeAddress, clusters, binds, configuredReportings, meta) {
90
- super();
91
- this.databaseID = databaseID;
92
- this.ID = ID;
93
- this.profileID = profileID;
94
- this.deviceID = deviceID;
95
- this.inputClusters = inputClusters;
96
- this.outputClusters = outputClusters;
97
- this.deviceNetworkAddress = deviceNetworkAddress;
98
- this.deviceIeeeAddress = deviceIeeeAddress;
99
- this.clusters = clusters;
100
- this._binds = binds;
101
- this._configuredReportings = configuredReportings;
102
- this.meta = meta;
103
- this.pendingRequests = new Set();
104
- this.sendInProgress = false;
105
- }
106
- /**
107
- * Get device of this endpoint
108
- */
109
- getDevice() {
110
- return device_1.default.byIeeeAddr(this.databaseID, this.deviceIeeeAddress);
111
- }
112
- /**
113
- * @param {number|string} clusterKey
114
- * @returns {boolean}
115
- */
116
- supportsInputCluster(clusterKey) {
117
- const cluster = Zcl.Utils.getCluster(clusterKey);
118
- return this.inputClusters.includes(cluster.ID);
119
- }
120
- /**
121
- * @param {number|string} clusterKey
122
- * @returns {boolean}
123
- */
124
- supportsOutputCluster(clusterKey) {
125
- const cluster = Zcl.Utils.getCluster(clusterKey);
126
- return this.outputClusters.includes(cluster.ID);
127
- }
128
- /**
129
- * @returns {Zcl.TsType.Cluster[]}
130
- */
131
- getInputClusters() {
132
- return this.clusterNumbersToClusters(this.inputClusters);
133
- }
134
- /**
135
- * @returns {Zcl.TsType.Cluster[]}
136
- */
137
- getOutputClusters() {
138
- return this.clusterNumbersToClusters(this.outputClusters);
139
- }
140
- clusterNumbersToClusters(clusterNumbers) {
141
- return clusterNumbers.map((c) => Zcl.Utils.getCluster(c, this.getDevice().manufacturerID));
142
- }
143
- /*
144
- * CRUD
145
- */
146
- static fromDatabaseRecord(record, deviceNetworkAddress, deviceIeeeAddress, databaseID) {
147
- // Migrate attrs to attributes
148
- for (const entry of Object.values(record.clusters).filter((e) => e.hasOwnProperty('attrs'))) {
149
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
150
- // @ts-ignore
151
- entry.attributes = entry.attrs;
152
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
153
- // @ts-ignore
154
- delete entry.attrs;
155
- }
156
- return new Endpoint(databaseID, record.epId, record.profId, record.devId, record.inClusterList, record.outClusterList, deviceNetworkAddress, deviceIeeeAddress, record.clusters, record.binds || [], record.configuredReportings || [], record.meta || {});
157
- }
158
- toDatabaseRecord() {
159
- return {
160
- profId: this.profileID,
161
- epId: this.ID,
162
- devId: this.deviceID,
163
- inClusterList: this.inputClusters,
164
- outClusterList: this.outputClusters,
165
- clusters: this.clusters,
166
- binds: this._binds,
167
- configuredReportings: this._configuredReportings,
168
- meta: this.meta,
169
- };
170
- }
171
- static create(databaseID, ID, profileID, deviceID, inputClusters, outputClusters, deviceNetworkAddress, deviceIeeeAddress) {
172
- return new Endpoint(databaseID, ID, profileID, deviceID, inputClusters, outputClusters, deviceNetworkAddress, deviceIeeeAddress, {}, [], [], {});
173
- }
174
- saveClusterAttributeKeyValue(clusterKey, list) {
175
- const cluster = Zcl.Utils.getCluster(clusterKey);
176
- if (!this.clusters[cluster.name])
177
- this.clusters[cluster.name] = { attributes: {} };
178
- for (const [attribute, value] of Object.entries(list)) {
179
- this.clusters[cluster.name].attributes[attribute] = value;
180
- }
181
- }
182
- getClusterAttributeValue(clusterKey, attributeKey) {
183
- const cluster = Zcl.Utils.getCluster(clusterKey);
184
- const attribute = cluster.getAttribute(attributeKey);
185
- if (this.clusters[cluster.name] && this.clusters[cluster.name].attributes) {
186
- return this.clusters[cluster.name].attributes[attribute.name];
187
- }
188
- return null;
189
- }
190
- hasPendingRequests() {
191
- return this.pendingRequests.size > 0;
192
- }
193
- async sendPendingRequests(fastPolling) {
194
- if (this.pendingRequests.size === 0)
195
- return;
196
- if (this.sendInProgress) {
197
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): sendPendingRequests already in progress`);
198
- return;
199
- }
200
- this.sendInProgress = true;
201
- // Remove expired requests first
202
- const now = Date.now();
203
- for (const request of this.pendingRequests) {
204
- if (now > request.expires) {
205
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): discard after timeout. ` +
206
- `Size before: ${this.pendingRequests.size}`);
207
- request.reject();
208
- this.pendingRequests.delete(request);
209
- }
210
- }
211
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send pending requests (` +
212
- `${this.pendingRequests.size}, ${fastPolling})`);
213
- for (const request of this.pendingRequests) {
214
- if (fastPolling ||
215
- (request.sendWhen !== 'fastpoll' && request.sendPolicy !== 'bulk')) {
216
- try {
217
- const result = await request.send();
218
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send success`);
219
- request.resolve(result);
220
- }
221
- catch (error) {
222
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send failed, expires in ` +
223
- `${(request.expires - now) / 1000} seconds`);
224
- request.reject(error);
225
- }
226
- this.pendingRequests.delete(request);
227
- }
228
- }
229
- this.sendInProgress = false;
230
- }
231
- async queueRequest(request) {
232
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): Sending when active. ` +
233
- `Timeout ${this.getDevice().pendingRequestTimeout / 1000} seconds`);
234
- return new Promise((resolve, reject) => {
235
- request.addCallbacks(resolve, reject);
236
- this.pendingRequests.add(request);
237
- });
238
- }
239
- filterRequests(newRequest) {
240
- var _a, _b;
241
- if (this.pendingRequests.size === 0 ||
242
- !(typeof newRequest.frame.getCommand === 'function')) {
243
- return;
244
- }
245
- const clusterID = newRequest.frame.Cluster.ID;
246
- const payload = newRequest.frame.Payload;
247
- const commandID = newRequest.frame.getCommand().ID;
248
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): ZCL ${newRequest.frame.getCommand().name} ` + `command, filter requests. Before: ${this.pendingRequests.size}`);
249
- for (const request of this.pendingRequests) {
250
- if (((_b = (_a = request === null || request === void 0 ? void 0 : request.frame) === null || _a === void 0 ? void 0 : _a.Cluster) === null || _b === void 0 ? void 0 : _b.ID) === undefined ||
251
- typeof request.frame.getCommand !== 'function') {
252
- continue;
253
- }
254
- if (['bulk', 'queue', 'immediate'].includes(request.sendPolicy)) {
255
- continue;
256
- }
257
- /* istanbul ignore else */
258
- if (request.frame.Cluster.ID === clusterID &&
259
- request.frame.getCommand().ID === commandID) {
260
- /* istanbul ignore else */
261
- if (newRequest.sendPolicy === 'keep-payload' &&
262
- JSON.stringify(request.frame.Payload) === JSON.stringify(payload)) {
263
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): Merge duplicate request`);
264
- this.pendingRequests.delete(request);
265
- newRequest.moveCallbacks(request);
266
- }
267
- else if ((newRequest.sendPolicy === 'keep-command' || newRequest.sendPolicy === 'keep-cmd-undiv') &&
268
- Array.isArray(request.frame.Payload)) {
269
- const filteredPayload = request.frame.Payload.filter((oldEl) => !payload.find((newEl) => oldEl.attrId === newEl.attrId));
270
- if (filteredPayload.length == 0) {
271
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): Remove & reject request`);
272
- if (JSON.stringify(request.frame.Payload) === JSON.stringify(payload)) {
273
- newRequest.moveCallbacks(request);
274
- }
275
- else {
276
- request.reject();
277
- }
278
- this.pendingRequests.delete(request);
279
- }
280
- else if (newRequest.sendPolicy !== 'keep-cmd-undiv') {
281
- // remove all duplicate attributes if we shall not write undivided
282
- request.frame.Payload = filteredPayload;
283
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): ` +
284
- `Remove commands from request`);
285
- }
286
- }
287
- }
288
- }
289
- debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): After: ${this.pendingRequests.size}`);
290
- }
291
- async sendRequest(frame, options, func = (d) => {
292
- return entity_1.default.getAdapterByID(this.databaseID).sendZclFrameToEndpoint(this.deviceIeeeAddress, this.deviceNetworkAddress, this.ID, d, options.timeout, options.disableResponse, options.disableRecovery, options.srcEndpoint);
293
- }) {
294
- const logPrefix = `Request Queue (${this.deviceIeeeAddress}/${this.ID}): `;
295
- const request = new request_1.default(func, frame, this.getDevice().pendingRequestTimeout, options.sendWhen, options.sendPolicy);
296
- if (request.sendPolicy !== 'bulk') {
297
- // Check if such a request is already in the queue and remove the old one(s) if necessary
298
- this.filterRequests(request);
299
- }
300
- // send without queueing if sendWhen or sendPolicy is 'immediate' or if the device has no timeout set
301
- if (request.sendWhen === 'immediate' ||
302
- request.sendPolicy === 'immediate' ||
303
- !this.getDevice().pendingRequestTimeout) {
304
- if (this.getDevice().defaultSendRequestWhen !== 'immediate') {
305
- debug.info(logPrefix +
306
- `send ${frame.getCommand().name} request immediately ` +
307
- `(sendWhen=${options.sendWhen})`);
308
- }
309
- return request.send();
310
- }
311
- // If this is a bulk message, we queue directly.
312
- if (request.sendPolicy === 'bulk') {
313
- debug.info(logPrefix +
314
- `queue request (${this.pendingRequests.size} / ${this.sendInProgress})))`);
315
- return this.queueRequest(request);
316
- }
317
- try {
318
- debug.info(logPrefix + `send request`);
319
- return await request.send();
320
- }
321
- catch (error) {
322
- // If we got a failed transaction, the device is likely sleeping.
323
- // Queue for transmission later.
324
- debug.info(logPrefix + `queue request (transaction failed)`);
325
- return this.queueRequest(request);
326
- }
327
- }
328
- /*
329
- * Zigbee functions
330
- */
331
- checkStatus(payload) {
332
- const codes = Array.isArray(payload)
333
- ? payload.map((i) => i.status)
334
- : [payload.statusCode];
335
- const invalid = codes.find((c) => c !== Zcl.Status.SUCCESS);
336
- if (invalid)
337
- throw new Zcl.ZclStatusError(invalid);
338
- }
339
- async report(clusterKey, attributes, options) {
340
- var _a;
341
- const cluster = Zcl.Utils.getCluster(clusterKey);
342
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
343
- const payload = [];
344
- for (const [nameOrID, value] of Object.entries(attributes)) {
345
- if (cluster.hasAttribute(nameOrID)) {
346
- const attribute = cluster.getAttribute(nameOrID);
347
- payload.push({
348
- attrId: attribute.ID,
349
- attrData: value,
350
- dataType: attribute.type,
351
- });
352
- }
353
- else if (!isNaN(Number(nameOrID))) {
354
- payload.push({
355
- attrId: Number(nameOrID),
356
- attrData: value.value,
357
- dataType: value.type,
358
- });
359
- }
360
- else {
361
- throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
362
- }
363
- }
364
- const log = `Report to ${this.deviceIeeeAddress}/${this.ID} ` +
365
- `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
366
- debug.info(log);
367
- try {
368
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, (_a = options.transactionSequenceNumber) !== null && _a !== void 0 ? _a : zclTransactionSequenceNumber_1.default.next(), 'report', cluster.ID, payload, options.reservedBits);
369
- await this.sendRequest(frame, options);
370
- }
371
- catch (error) {
372
- error.message = `${log} failed (${error.message})`;
373
- debug.error(error.message);
374
- throw error;
375
- }
376
- }
377
- async write(clusterKey, attributes, options) {
378
- var _a;
379
- const cluster = Zcl.Utils.getCluster(clusterKey);
380
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
381
- const payload = [];
382
- for (const [nameOrID, value] of Object.entries(attributes)) {
383
- if (cluster.hasAttribute(nameOrID)) {
384
- const attribute = cluster.getAttribute(nameOrID);
385
- payload.push({
386
- attrId: attribute.ID,
387
- attrData: value,
388
- dataType: attribute.type,
389
- });
390
- }
391
- else if (!isNaN(Number(nameOrID))) {
392
- payload.push({
393
- attrId: Number(nameOrID),
394
- attrData: value.value,
395
- dataType: value.type,
396
- });
397
- }
398
- else {
399
- throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
400
- }
401
- }
402
- const log = `Write ${this.deviceIeeeAddress}/${this.ID} ` +
403
- `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
404
- debug.info(log);
405
- try {
406
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, (_a = options.transactionSequenceNumber) !== null && _a !== void 0 ? _a : zclTransactionSequenceNumber_1.default.next(), options.writeUndiv ? 'writeUndiv' : 'write', cluster.ID, payload, options.reservedBits);
407
- const result = await this.sendRequest(frame, options);
408
- if (!options.disableResponse) {
409
- this.checkStatus(result.frame.Payload);
410
- }
411
- }
412
- catch (error) {
413
- error.message = `${log} failed (${error.message})`;
414
- debug.error(error.message);
415
- throw error;
416
- }
417
- }
418
- async writeResponse(clusterKey, transactionSequenceNumber, attributes, options) {
419
- (0, assert_1.default)(!options || !options.hasOwnProperty('transactionSequenceNumber'), 'Use parameter');
420
- const cluster = Zcl.Utils.getCluster(clusterKey);
421
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, cluster.manufacturerCode);
422
- const payload = [];
423
- for (const [nameOrID, value] of Object.entries(attributes)) {
424
- if (value.hasOwnProperty('status')) {
425
- if (cluster.hasAttribute(nameOrID)) {
426
- const attribute = cluster.getAttribute(nameOrID);
427
- payload.push({ attrId: attribute.ID, status: value.status });
428
- }
429
- else if (!isNaN(Number(nameOrID))) {
430
- payload.push({ attrId: Number(nameOrID), status: value.status });
431
- }
432
- else {
433
- throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
434
- }
435
- }
436
- else {
437
- throw new Error(`Missing attribute 'status'`);
438
- }
439
- }
440
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, 'writeRsp', cluster.ID, payload, options.reservedBits);
441
- const log = `WriteResponse ${this.deviceIeeeAddress}/${this.ID} ` +
442
- `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
443
- debug.info(log);
444
- try {
445
- await this.sendRequest(frame, options);
446
- }
447
- catch (error) {
448
- error.message = `${log} failed (${error.message})`;
449
- debug.error(error.message);
450
- throw error;
451
- }
452
- }
453
- async read(clusterKey, attributes, options) {
454
- var _a;
455
- const cluster = Zcl.Utils.getCluster(clusterKey);
456
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
457
- const payload = [];
458
- for (const attribute of attributes) {
459
- payload.push({
460
- attrId: typeof attribute === 'number'
461
- ? attribute
462
- : cluster.getAttribute(attribute).ID,
463
- });
464
- }
465
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, (_a = options.transactionSequenceNumber) !== null && _a !== void 0 ? _a : zclTransactionSequenceNumber_1.default.next(), 'read', cluster.ID, payload, options.reservedBits);
466
- const log = `Read ${this.deviceIeeeAddress}/${this.ID} ` +
467
- `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
468
- debug.info(log);
469
- try {
470
- const result = await this.sendRequest(frame, options);
471
- if (!options.disableResponse) {
472
- this.checkStatus(result.frame.Payload);
473
- return ZclFrameConverter.attributeKeyValue(result.frame);
474
- }
475
- else {
476
- return null;
477
- }
478
- }
479
- catch (error) {
480
- error.message = `${log} failed (${error.message})`;
481
- debug.error(error.message);
482
- throw error;
483
- }
484
- }
485
- async readResponse(clusterKey, transactionSequenceNumber, attributes, options) {
486
- (0, assert_1.default)(!options || !options.hasOwnProperty('transactionSequenceNumber'), 'Use parameter');
487
- const cluster = Zcl.Utils.getCluster(clusterKey);
488
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, cluster.manufacturerCode);
489
- const payload = [];
490
- for (const [nameOrID, value] of Object.entries(attributes)) {
491
- if (cluster.hasAttribute(nameOrID)) {
492
- const attribute = cluster.getAttribute(nameOrID);
493
- payload.push({
494
- attrId: attribute.ID,
495
- attrData: value,
496
- dataType: attribute.type,
497
- status: 0,
498
- });
499
- }
500
- else if (!isNaN(Number(nameOrID))) {
501
- payload.push({
502
- attrId: Number(nameOrID),
503
- attrData: value.value,
504
- dataType: value.type,
505
- status: 0,
506
- });
507
- }
508
- else {
509
- throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
510
- }
511
- }
512
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, 'readRsp', cluster.ID, payload, options.reservedBits);
513
- const log = `ReadResponse ${this.deviceIeeeAddress}/${this.ID} ` +
514
- `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
515
- debug.info(log);
516
- try {
517
- await this.sendRequest(frame, options);
518
- }
519
- catch (error) {
520
- error.message = `${log} failed (${error.message})`;
521
- debug.error(error.message);
522
- throw error;
523
- }
524
- }
525
- addBinding(clusterKey, target) {
526
- const cluster = Zcl.Utils.getCluster(clusterKey);
527
- if (typeof target === 'number') {
528
- target =
529
- group_1.default.byGroupID(target, this.databaseID) ||
530
- group_1.default.create(target, this.databaseID);
531
- }
532
- if (!this.binds.find((b) => b.cluster.ID === cluster.ID && b.target === target)) {
533
- if (target instanceof group_1.default) {
534
- this._binds.push({
535
- cluster: cluster.ID,
536
- groupID: target.groupID,
537
- type: 'group',
538
- });
539
- }
540
- else {
541
- this._binds.push({
542
- cluster: cluster.ID,
543
- type: 'endpoint',
544
- deviceIeeeAddress: target.deviceIeeeAddress,
545
- endpointID: target.ID,
546
- });
547
- }
548
- this.save();
549
- }
550
- }
551
- async bind(clusterKey, target) {
552
- const cluster = Zcl.Utils.getCluster(clusterKey);
553
- const type = target instanceof Endpoint ? 'endpoint' : 'group';
554
- if (typeof target === 'number') {
555
- target =
556
- group_1.default.byGroupID(target, this.databaseID) ||
557
- group_1.default.create(target, this.databaseID);
558
- }
559
- const destinationAddress = target instanceof Endpoint ? target.deviceIeeeAddress : target.groupID;
560
- const log = `Bind ${this.deviceIeeeAddress}/${this.ID} ${cluster.name} from ` +
561
- `'${target instanceof Endpoint
562
- ? `${destinationAddress}/${target.ID}`
563
- : destinationAddress}'`;
564
- debug.info(log);
565
- try {
566
- await entity_1.default.getAdapterByID(this.databaseID).bind(this.deviceNetworkAddress, this.deviceIeeeAddress, this.ID, cluster.ID, destinationAddress, type, target instanceof Endpoint ? target.ID : null);
567
- this.addBinding(clusterKey, target);
568
- }
569
- catch (error) {
570
- error.message = `${log} failed (${error.message})`;
571
- debug.error(error.message);
572
- throw error;
573
- }
574
- }
575
- save() {
576
- this.getDevice().save();
577
- }
578
- async unbind(clusterKey, target) {
579
- const cluster = Zcl.Utils.getCluster(clusterKey);
580
- const type = target instanceof Endpoint ? 'endpoint' : 'group';
581
- const destinationAddress = target instanceof Endpoint
582
- ? target.deviceIeeeAddress
583
- : target instanceof group_1.default
584
- ? target.groupID
585
- : target;
586
- const log = `Unbind ${this.deviceIeeeAddress}/${this.ID} ${cluster.name} from ` +
587
- `'${target instanceof Endpoint
588
- ? `${destinationAddress}/${target.ID}`
589
- : destinationAddress}'`;
590
- debug.info(log);
591
- try {
592
- await entity_1.default.getAdapterByID(this.databaseID).unbind(this.deviceNetworkAddress, this.deviceIeeeAddress, this.ID, cluster.ID, destinationAddress, type, target instanceof Endpoint ? target.ID : null);
593
- if (typeof target === 'number' &&
594
- group_1.default.byGroupID(target, this.databaseID)) {
595
- target = group_1.default.byGroupID(target, this.databaseID);
596
- }
597
- const index = this.binds.findIndex((b) => b.cluster.ID === cluster.ID && b.target === target);
598
- if (index !== -1) {
599
- this._binds.splice(index, 1);
600
- this.save();
601
- }
602
- }
603
- catch (error) {
604
- error.message = `${log} failed (${error.message})`;
605
- debug.error(error.message);
606
- throw error;
607
- }
608
- }
609
- async defaultResponse(commandID, status, clusterID, transactionSequenceNumber, options) {
610
- (0, assert_1.default)(!options || !options.hasOwnProperty('transactionSequenceNumber'), 'Use parameter');
611
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, null);
612
- const payload = { cmdId: commandID, statusCode: status };
613
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, 'defaultRsp', clusterID, payload, options.reservedBits);
614
- const log = `DefaultResponse ${this.deviceIeeeAddress}/${this.ID} ` +
615
- `${clusterID}(${commandID}, ${JSON.stringify(options)})`;
616
- debug.info(log);
617
- try {
618
- await this.sendRequest(frame, options);
619
- }
620
- catch (error) {
621
- error.message = `${log} failed (${error.message})`;
622
- debug.error(error.message);
623
- throw error;
624
- }
625
- }
626
- async configureReporting(clusterKey, items, options) {
627
- var _a;
628
- const cluster = Zcl.Utils.getCluster(clusterKey);
629
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
630
- const payload = items.map((item) => {
631
- let dataType, attrId;
632
- if (typeof item.attribute === 'object') {
633
- dataType = item.attribute.type;
634
- attrId = item.attribute.ID;
635
- }
636
- else {
637
- /* istanbul ignore else */
638
- if (cluster.hasAttribute(item.attribute)) {
639
- const attribute = cluster.getAttribute(item.attribute);
640
- dataType = attribute.type;
641
- attrId = attribute.ID;
642
- }
643
- }
644
- return {
645
- direction: Zcl.Direction.CLIENT_TO_SERVER,
646
- attrId,
647
- dataType,
648
- minRepIntval: item.minimumReportInterval,
649
- maxRepIntval: item.maximumReportInterval,
650
- repChange: item.reportableChange,
651
- };
652
- });
653
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, (_a = options.transactionSequenceNumber) !== null && _a !== void 0 ? _a : zclTransactionSequenceNumber_1.default.next(), 'configReport', cluster.ID, payload, options.reservedBits);
654
- const log = `ConfigureReporting ${this.deviceIeeeAddress}/${this.ID} ` +
655
- `${cluster.name}(${JSON.stringify(items)}, ${JSON.stringify(options)})`;
656
- debug.info(log);
657
- try {
658
- const result = await this.sendRequest(frame, options);
659
- if (!options.disableResponse) {
660
- this.checkStatus(result.frame.Payload);
661
- }
662
- for (const e of payload) {
663
- const match = this._configuredReportings.find((c) => c.attrId === e.attrId && c.cluster === cluster.ID);
664
- if (match) {
665
- this._configuredReportings.splice(this._configuredReportings.indexOf(match), 1);
666
- }
667
- }
668
- for (const entry of payload) {
669
- if (entry.maxRepIntval !== 0xffff) {
670
- this._configuredReportings.push({
671
- cluster: cluster.ID,
672
- attrId: entry.attrId,
673
- minRepIntval: entry.minRepIntval,
674
- maxRepIntval: entry.maxRepIntval,
675
- repChange: entry.repChange,
676
- });
677
- }
678
- }
679
- this.save();
680
- }
681
- catch (error) {
682
- error.message = `${log} failed (${error.message})`;
683
- debug.error(error.message);
684
- throw error;
685
- }
686
- }
687
- async writeStructured(clusterKey, payload, options) {
688
- var _a;
689
- const cluster = Zcl.Utils.getCluster(clusterKey);
690
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
691
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, (_a = options.transactionSequenceNumber) !== null && _a !== void 0 ? _a : zclTransactionSequenceNumber_1.default.next(), `writeStructured`, cluster.ID, payload, options.reservedBits);
692
- const log = `WriteStructured ${this.deviceIeeeAddress}/${this.ID} ` +
693
- `${cluster.name}(${JSON.stringify(payload)}, ${JSON.stringify(options)})`;
694
- debug.info(log);
695
- try {
696
- await this.sendRequest(frame, options);
697
- // TODO: support `writeStructuredResponse`
698
- }
699
- catch (error) {
700
- error.message = `${log} failed (${error.message})`;
701
- debug.error(error.message);
702
- throw error;
703
- }
704
- }
705
- async command(clusterKey, commandKey, payload, options) {
706
- var _a;
707
- const cluster = Zcl.Utils.getCluster(clusterKey);
708
- const command = cluster.getCommand(commandKey);
709
- const hasResponse = command.hasOwnProperty('response');
710
- options = this.getOptionsWithDefaults(options, hasResponse, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
711
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.SPECIFIC, options.direction, options.disableDefaultResponse, options.manufacturerCode, (_a = options.transactionSequenceNumber) !== null && _a !== void 0 ? _a : zclTransactionSequenceNumber_1.default.next(), command.name, cluster.name, payload, options.reservedBits);
712
- const log = `Command ${this.deviceIeeeAddress}/${this.ID} ` +
713
- `${cluster.name}.${command.name}(${JSON.stringify(payload)}, ${JSON.stringify(options)})`;
714
- debug.info(log);
715
- try {
716
- const result = await this.sendRequest(frame, options);
717
- if (result) {
718
- return result.frame.Payload;
719
- }
720
- }
721
- catch (error) {
722
- error.message = `${log} failed (${error.message})`;
723
- debug.error(error.message);
724
- throw error;
725
- }
726
- }
727
- async commandResponse(clusterKey, commandKey, payload, options, transactionSequenceNumber) {
728
- (0, assert_1.default)(!options || !options.hasOwnProperty('transactionSequenceNumber'), 'Use parameter');
729
- const cluster = Zcl.Utils.getCluster(clusterKey);
730
- const command = cluster.getCommandResponse(commandKey);
731
- transactionSequenceNumber =
732
- transactionSequenceNumber || zclTransactionSequenceNumber_1.default.next();
733
- options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, cluster.manufacturerCode);
734
- const frame = Zcl.ZclFrame.create(Zcl.FrameType.SPECIFIC, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, command.name, cluster.name, payload, options.reservedBits);
735
- const log = `CommandResponse ${this.deviceIeeeAddress}/${this.ID} ` +
736
- `${cluster.name}.${command.name}(${JSON.stringify(payload)}, ${JSON.stringify(options)})`;
737
- debug.info(log);
738
- try {
739
- await this.sendRequest(frame, options, async (f) => {
740
- // Broadcast Green Power responses
741
- if (this.ID === 242) {
742
- await entity_1.default.getAdapterByID(this.databaseID).sendZclFrameToAll(242, f, 242);
743
- }
744
- else {
745
- await entity_1.default.getAdapterByID(this.databaseID).sendZclFrameToEndpoint(this.deviceIeeeAddress, this.deviceNetworkAddress, this.ID, f, options.timeout, options.disableResponse, options.disableRecovery, options.srcEndpoint);
746
- }
747
- });
748
- }
749
- catch (error) {
750
- error.message = `${log} failed (${error.message})`;
751
- debug.error(error.message);
752
- throw error;
753
- }
754
- }
755
- waitForCommand(clusterKey, commandKey, transactionSequenceNumber, timeout) {
756
- const cluster = Zcl.Utils.getCluster(clusterKey);
757
- const command = cluster.getCommand(commandKey);
758
- const waiter = entity_1.default.getAdapterByID(this.databaseID).waitFor(this.deviceNetworkAddress, this.ID, Zcl.FrameType.SPECIFIC, Zcl.Direction.CLIENT_TO_SERVER, transactionSequenceNumber, cluster.ID, command.ID, timeout);
759
- const promise = new Promise((resolve, reject) => {
760
- waiter.promise.then((payload) => resolve({
761
- header: payload.frame.Header,
762
- payload: payload.frame.Payload,
763
- }), (error) => reject(error));
764
- });
765
- return { promise, cancel: waiter.cancel };
766
- }
767
- getOptionsWithDefaults(options, disableDefaultResponse, direction, manufacturerCode) {
768
- const providedOptions = options || {};
769
- return {
770
- sendWhen: this.getDevice().defaultSendRequestWhen,
771
- timeout: 10000,
772
- disableResponse: false,
773
- disableRecovery: false,
774
- disableDefaultResponse,
775
- direction,
776
- srcEndpoint: null,
777
- reservedBits: 0,
778
- manufacturerCode: manufacturerCode ? manufacturerCode : null,
779
- transactionSequenceNumber: null,
780
- writeUndiv: false,
781
- ...providedOptions,
782
- };
783
- }
784
- async addToGroup(group) {
785
- await this.command('genGroups', 'add', {
786
- groupid: group.groupID,
787
- groupname: '',
788
- });
789
- group.addMember(this);
790
- }
791
- /**
792
- * Remove endpoint from a group, accepts both a Group and number as parameter.
793
- * The number parameter type should only be used when removing from a group which is not known
794
- * to zigbee-herdsman.
795
- */
796
- async removeFromGroup(group) {
797
- await this.command('genGroups', 'remove', {
798
- groupid: group instanceof group_1.default ? group.groupID : group,
799
- });
800
- if (group instanceof group_1.default) {
801
- group.removeMember(this);
802
- }
803
- }
804
- async removeFromAllGroups() {
805
- await this.command('genGroups', 'removeAll', {}, { disableDefaultResponse: true });
806
- this.removeFromAllGroupsDatabase();
807
- }
808
- removeFromAllGroupsDatabase() {
809
- for (const group of group_1.default.allByDatabaseID(this.databaseID)) {
810
- if (group.hasMember(this)) {
811
- group.removeMember(this);
812
- }
813
- }
814
- }
815
- }
816
- exports.default = Endpoint;
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 entity_1 = __importDefault(require("./entity"));
30
+ const Zcl = __importStar(require("../../zcl"));
31
+ const zclTransactionSequenceNumber_1 = __importDefault(require("../helpers/zclTransactionSequenceNumber"));
32
+ const ZclFrameConverter = __importStar(require("../helpers/zclFrameConverter"));
33
+ const request_1 = __importDefault(require("../helpers/request"));
34
+ const requestQueue_1 = __importDefault(require("../helpers/requestQueue"));
35
+ const group_1 = __importDefault(require("./group"));
36
+ const device_1 = __importDefault(require("./device"));
37
+ const debug_1 = __importDefault(require("debug"));
38
+ const assert_1 = __importDefault(require("assert"));
39
+ const debug = {
40
+ info: (0, debug_1.default)("zigbee-herdsman:controller:endpoint"),
41
+ error: (0, debug_1.default)("zigbee-herdsman:controller:endpoint"),
42
+ };
43
+ class Endpoint extends entity_1.default {
44
+ databaseID;
45
+ deviceID;
46
+ inputClusters;
47
+ outputClusters;
48
+ profileID;
49
+ ID;
50
+ clusters;
51
+ deviceIeeeAddress;
52
+ deviceNetworkAddress;
53
+ _binds;
54
+ _configuredReportings;
55
+ meta;
56
+ pendingRequests;
57
+ // Getters/setters
58
+ get binds() {
59
+ return this._binds
60
+ .map((entry) => {
61
+ let target = null;
62
+ if (entry.type === "endpoint") {
63
+ const device = device_1.default.byIeeeAddr(this.databaseID, entry.deviceIeeeAddress);
64
+ if (device) {
65
+ target = device.getEndpoint(entry.endpointID);
66
+ }
67
+ }
68
+ else {
69
+ target = group_1.default.byGroupID(entry.groupID, this.databaseID);
70
+ }
71
+ if (target) {
72
+ return {
73
+ target,
74
+ cluster: Zcl.Utils.getCluster(entry.cluster, this.getDevice().manufacturerID),
75
+ };
76
+ }
77
+ else {
78
+ return undefined;
79
+ }
80
+ })
81
+ .filter((b) => b !== undefined);
82
+ }
83
+ get configuredReportings() {
84
+ return this._configuredReportings.map((entry) => {
85
+ const cluster = Zcl.Utils.getCluster(entry.cluster, entry.manufacturerCode);
86
+ let attribute;
87
+ if (cluster.hasAttribute(entry.attrId)) {
88
+ attribute = cluster.getAttribute(entry.attrId);
89
+ }
90
+ else {
91
+ attribute = {
92
+ ID: entry.attrId,
93
+ name: undefined,
94
+ type: undefined,
95
+ manufacturerCode: undefined,
96
+ };
97
+ }
98
+ return {
99
+ cluster,
100
+ attribute,
101
+ minimumReportInterval: entry.minRepIntval,
102
+ maximumReportInterval: entry.maxRepIntval,
103
+ reportableChange: entry.repChange,
104
+ };
105
+ });
106
+ }
107
+ constructor(databaseID, ID, profileID, deviceID, inputClusters, outputClusters, deviceNetworkAddress, deviceIeeeAddress, clusters, binds, configuredReportings, meta) {
108
+ super();
109
+ this.databaseID = databaseID;
110
+ this.ID = ID;
111
+ this.profileID = profileID;
112
+ this.deviceID = deviceID;
113
+ this.inputClusters = inputClusters;
114
+ this.outputClusters = outputClusters;
115
+ this.deviceNetworkAddress = deviceNetworkAddress;
116
+ this.deviceIeeeAddress = deviceIeeeAddress;
117
+ this.clusters = clusters;
118
+ this._binds = binds;
119
+ this._configuredReportings = configuredReportings;
120
+ this.meta = meta;
121
+ this.pendingRequests = new requestQueue_1.default(this);
122
+ }
123
+ /**
124
+ * Get device of this endpoint
125
+ */
126
+ getDevice() {
127
+ return device_1.default.byIeeeAddr(this.databaseID, this.deviceIeeeAddress);
128
+ }
129
+ /**
130
+ * @param {number|string} clusterKey
131
+ * @returns {boolean}
132
+ */
133
+ supportsInputCluster(clusterKey) {
134
+ const cluster = Zcl.Utils.getCluster(clusterKey);
135
+ return this.inputClusters.includes(cluster.ID);
136
+ }
137
+ /**
138
+ * @param {number|string} clusterKey
139
+ * @returns {boolean}
140
+ */
141
+ supportsOutputCluster(clusterKey) {
142
+ const cluster = Zcl.Utils.getCluster(clusterKey);
143
+ return this.outputClusters.includes(cluster.ID);
144
+ }
145
+ /**
146
+ * @returns {Zcl.TsType.Cluster[]}
147
+ */
148
+ getInputClusters() {
149
+ return this.clusterNumbersToClusters(this.inputClusters);
150
+ }
151
+ /**
152
+ * @returns {Zcl.TsType.Cluster[]}
153
+ */
154
+ getOutputClusters() {
155
+ return this.clusterNumbersToClusters(this.outputClusters);
156
+ }
157
+ clusterNumbersToClusters(clusterNumbers) {
158
+ return clusterNumbers.map((c) => Zcl.Utils.getCluster(c, this.getDevice().manufacturerID));
159
+ }
160
+ /*
161
+ * CRUD
162
+ */
163
+ static fromDatabaseRecord(record, deviceNetworkAddress, deviceIeeeAddress, databaseID) {
164
+ // Migrate attrs to attributes
165
+ for (const entry of Object.values(record.clusters).filter((e) => e.hasOwnProperty("attrs"))) {
166
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
167
+ // @ts-ignore
168
+ entry.attributes = entry.attrs;
169
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
170
+ // @ts-ignore
171
+ delete entry.attrs;
172
+ }
173
+ return new Endpoint(databaseID, record.epId, record.profId, record.devId, record.inClusterList, record.outClusterList, deviceNetworkAddress, deviceIeeeAddress, record.clusters, record.binds || [], record.configuredReportings || [], record.meta || {});
174
+ }
175
+ toDatabaseRecord() {
176
+ return {
177
+ profId: this.profileID,
178
+ epId: this.ID,
179
+ devId: this.deviceID,
180
+ inClusterList: this.inputClusters,
181
+ outClusterList: this.outputClusters,
182
+ clusters: this.clusters,
183
+ binds: this._binds,
184
+ configuredReportings: this._configuredReportings,
185
+ meta: this.meta,
186
+ };
187
+ }
188
+ static create(databaseID, ID, profileID, deviceID, inputClusters, outputClusters, deviceNetworkAddress, deviceIeeeAddress) {
189
+ return new Endpoint(databaseID, ID, profileID, deviceID, inputClusters, outputClusters, deviceNetworkAddress, deviceIeeeAddress, {}, [], [], {});
190
+ }
191
+ saveClusterAttributeKeyValue(clusterKey, list) {
192
+ const cluster = Zcl.Utils.getCluster(clusterKey);
193
+ if (!this.clusters[cluster.name])
194
+ this.clusters[cluster.name] = { attributes: {} };
195
+ for (const [attribute, value] of Object.entries(list)) {
196
+ this.clusters[cluster.name].attributes[attribute] = value;
197
+ }
198
+ }
199
+ getClusterAttributeValue(clusterKey, attributeKey) {
200
+ const cluster = Zcl.Utils.getCluster(clusterKey);
201
+ const attribute = cluster.getAttribute(attributeKey);
202
+ if (this.clusters[cluster.name] && this.clusters[cluster.name].attributes) {
203
+ return this.clusters[cluster.name].attributes[attribute.name];
204
+ }
205
+ return null;
206
+ }
207
+ hasPendingRequests() {
208
+ return this.pendingRequests.size > 0;
209
+ }
210
+ async sendPendingRequests(fastPolling) {
211
+ return this.pendingRequests.send(fastPolling);
212
+ }
213
+ async sendRequest(frame, options, func = (d) => {
214
+ return entity_1.default.getAdapterByID(this.databaseID).sendZclFrameToEndpoint(this.deviceIeeeAddress, this.deviceNetworkAddress, this.ID, d, options.timeout, options.disableResponse, options.disableRecovery, options.srcEndpoint);
215
+ }) {
216
+ const logPrefix = `Request Queue (${this.deviceIeeeAddress}/${this.ID}): `;
217
+ const request = new request_1.default(func, frame, this.getDevice().pendingRequestTimeout, options.sendPolicy);
218
+ if (request.sendPolicy !== 'bulk') {
219
+ // Check if such a request is already in the queue and remove the old one(s) if necessary
220
+ this.pendingRequests.filter(request);
221
+ }
222
+ // send without queueing if sendPolicy is 'immediate' or if the device has no timeout set
223
+ if (request.sendPolicy === 'immediate'
224
+ || !this.getDevice().pendingRequestTimeout) {
225
+ if (this.getDevice().pendingRequestTimeout > 0) {
226
+ debug.info(logPrefix + `send ${frame.getCommand().name} request immediately ` +
227
+ `(sendPolicy=${options.sendPolicy})`);
228
+ }
229
+ return request.send();
230
+ }
231
+ // If this is a bulk message, we queue directly.
232
+ if (request.sendPolicy === 'bulk') {
233
+ debug.info(logPrefix + `queue request (${this.pendingRequests.size})))`);
234
+ return this.pendingRequests.queue(request);
235
+ }
236
+ try {
237
+ debug.info(logPrefix + `send request`);
238
+ return await request.send();
239
+ }
240
+ catch (error) {
241
+ // If we got a failed transaction, the device is likely sleeping.
242
+ // Queue for transmission later.
243
+ debug.info(logPrefix + `queue request (transaction failed)`);
244
+ return this.pendingRequests.queue(request);
245
+ }
246
+ }
247
+ /*
248
+ * Zigbee functions
249
+ */
250
+ checkStatus(payload) {
251
+ const codes = Array.isArray(payload)
252
+ ? payload.map((i) => i.status)
253
+ : [payload.statusCode];
254
+ const invalid = codes.find((c) => c !== Zcl.Status.SUCCESS);
255
+ if (invalid)
256
+ throw new Zcl.ZclStatusError(invalid);
257
+ }
258
+ async report(clusterKey, attributes, options) {
259
+ const cluster = Zcl.Utils.getCluster(clusterKey);
260
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
261
+ const payload = [];
262
+ for (const [nameOrID, value] of Object.entries(attributes)) {
263
+ if (cluster.hasAttribute(nameOrID)) {
264
+ const attribute = cluster.getAttribute(nameOrID);
265
+ payload.push({
266
+ attrId: attribute.ID,
267
+ attrData: value,
268
+ dataType: attribute.type,
269
+ });
270
+ }
271
+ else if (!isNaN(Number(nameOrID))) {
272
+ payload.push({
273
+ attrId: Number(nameOrID),
274
+ attrData: value.value,
275
+ dataType: value.type,
276
+ });
277
+ }
278
+ else {
279
+ throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
280
+ }
281
+ }
282
+ const log = `Report to ${this.deviceIeeeAddress}/${this.ID} ` +
283
+ `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
284
+ debug.info(log);
285
+ try {
286
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, options.transactionSequenceNumber ??
287
+ zclTransactionSequenceNumber_1.default.next(), "report", cluster.ID, payload, options.reservedBits);
288
+ await this.sendRequest(frame, options);
289
+ }
290
+ catch (error) {
291
+ error.message = `${log} failed (${error.message})`;
292
+ debug.error(error.message);
293
+ throw error;
294
+ }
295
+ }
296
+ async write(clusterKey, attributes, options) {
297
+ const cluster = Zcl.Utils.getCluster(clusterKey);
298
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
299
+ options.manufacturerCode = this.ensureManufacturerCodeIsUniqueAndGet(cluster, Object.keys(attributes), options.manufacturerCode, 'write');
300
+ const payload = [];
301
+ for (const [nameOrID, value] of Object.entries(attributes)) {
302
+ if (cluster.hasAttribute(nameOrID)) {
303
+ const attribute = cluster.getAttribute(nameOrID);
304
+ payload.push({ attrId: attribute.ID, attrData: value, dataType: attribute.type });
305
+ }
306
+ else if (!isNaN(Number(nameOrID))) {
307
+ payload.push({ attrId: Number(nameOrID), attrData: value.value, dataType: value.type });
308
+ }
309
+ else {
310
+ throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
311
+ }
312
+ }
313
+ const log = `Write ${this.deviceIeeeAddress}/${this.ID} ` +
314
+ `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
315
+ debug.info(log);
316
+ try {
317
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, options.transactionSequenceNumber ??
318
+ zclTransactionSequenceNumber_1.default.next(), options.writeUndiv ? "writeUndiv" : "write", cluster.ID, payload, options.reservedBits);
319
+ const result = await this.sendRequest(frame, options);
320
+ if (!options.disableResponse) {
321
+ this.checkStatus(result.frame.Payload);
322
+ }
323
+ }
324
+ catch (error) {
325
+ error.message = `${log} failed (${error.message})`;
326
+ debug.error(error.message);
327
+ throw error;
328
+ }
329
+ }
330
+ async writeResponse(clusterKey, transactionSequenceNumber, attributes, options) {
331
+ (0, assert_1.default)(!options || !options.hasOwnProperty('transactionSequenceNumber'), 'Use parameter');
332
+ const cluster = Zcl.Utils.getCluster(clusterKey);
333
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, cluster.manufacturerCode);
334
+ const payload = [];
335
+ for (const [nameOrID, value] of Object.entries(attributes)) {
336
+ if (value.hasOwnProperty('status')) {
337
+ if (cluster.hasAttribute(nameOrID)) {
338
+ const attribute = cluster.getAttribute(nameOrID);
339
+ payload.push({ attrId: attribute.ID, status: value.status });
340
+ }
341
+ else if (!isNaN(Number(nameOrID))) {
342
+ payload.push({ attrId: Number(nameOrID), status: value.status });
343
+ }
344
+ else {
345
+ throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
346
+ }
347
+ }
348
+ else {
349
+ throw new Error(`Missing attribute 'status'`);
350
+ }
351
+ }
352
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, "writeRsp", cluster.ID, payload, options.reservedBits);
353
+ const log = `WriteResponse ${this.deviceIeeeAddress}/${this.ID} ` +
354
+ `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
355
+ debug.info(log);
356
+ try {
357
+ await this.sendRequest(frame, options);
358
+ }
359
+ catch (error) {
360
+ error.message = `${log} failed (${error.message})`;
361
+ debug.error(error.message);
362
+ throw error;
363
+ }
364
+ }
365
+ async read(clusterKey, attributes, options) {
366
+ const cluster = Zcl.Utils.getCluster(clusterKey);
367
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
368
+ options.manufacturerCode = this.ensureManufacturerCodeIsUniqueAndGet(cluster, attributes, options.manufacturerCode, 'read');
369
+ const payload = [];
370
+ for (const attribute of attributes) {
371
+ payload.push({ attrId: typeof attribute === 'number' ? attribute : cluster.getAttribute(attribute).ID });
372
+ }
373
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, options.transactionSequenceNumber ?? zclTransactionSequenceNumber_1.default.next(), "read", cluster.ID, payload, options.reservedBits);
374
+ const log = `Read ${this.deviceIeeeAddress}/${this.ID} ` +
375
+ `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
376
+ debug.info(log);
377
+ try {
378
+ const result = await this.sendRequest(frame, options);
379
+ if (!options.disableResponse) {
380
+ this.checkStatus(result.frame.Payload);
381
+ return ZclFrameConverter.attributeKeyValue(result.frame, this.getDevice().manufacturerID);
382
+ }
383
+ else {
384
+ return null;
385
+ }
386
+ }
387
+ catch (error) {
388
+ error.message = `${log} failed (${error.message})`;
389
+ debug.error(error.message);
390
+ throw error;
391
+ }
392
+ }
393
+ async readResponse(clusterKey, transactionSequenceNumber, attributes, options) {
394
+ (0, assert_1.default)(!options || !options.hasOwnProperty("transactionSequenceNumber"), "Use parameter");
395
+ const cluster = Zcl.Utils.getCluster(clusterKey);
396
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, cluster.manufacturerCode);
397
+ const payload = [];
398
+ for (const [nameOrID, value] of Object.entries(attributes)) {
399
+ if (cluster.hasAttribute(nameOrID)) {
400
+ const attribute = cluster.getAttribute(nameOrID);
401
+ payload.push({
402
+ attrId: attribute.ID,
403
+ attrData: value,
404
+ dataType: attribute.type,
405
+ status: 0,
406
+ });
407
+ }
408
+ else if (!isNaN(Number(nameOrID))) {
409
+ payload.push({
410
+ attrId: Number(nameOrID),
411
+ attrData: value.value,
412
+ dataType: value.type,
413
+ status: 0,
414
+ });
415
+ }
416
+ else {
417
+ throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
418
+ }
419
+ }
420
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, "readRsp", cluster.ID, payload, options.reservedBits);
421
+ const log = `ReadResponse ${this.deviceIeeeAddress}/${this.ID} ` +
422
+ `${cluster.name}(${JSON.stringify(attributes)}, ${JSON.stringify(options)})`;
423
+ debug.info(log);
424
+ try {
425
+ await this.sendRequest(frame, options);
426
+ }
427
+ catch (error) {
428
+ error.message = `${log} failed (${error.message})`;
429
+ debug.error(error.message);
430
+ throw error;
431
+ }
432
+ }
433
+ addBinding(clusterKey, target) {
434
+ const cluster = Zcl.Utils.getCluster(clusterKey);
435
+ if (typeof target === "number") {
436
+ target =
437
+ group_1.default.byGroupID(target, this.databaseID) ||
438
+ group_1.default.create(target, this.databaseID);
439
+ }
440
+ if (!this.binds.find((b) => b.cluster.ID === cluster.ID && b.target === target)) {
441
+ if (target instanceof group_1.default) {
442
+ this._binds.push({
443
+ cluster: cluster.ID,
444
+ groupID: target.groupID,
445
+ type: "group",
446
+ });
447
+ }
448
+ else {
449
+ this._binds.push({
450
+ cluster: cluster.ID,
451
+ type: "endpoint",
452
+ deviceIeeeAddress: target.deviceIeeeAddress,
453
+ endpointID: target.ID,
454
+ });
455
+ }
456
+ this.save();
457
+ }
458
+ }
459
+ async bind(clusterKey, target) {
460
+ const cluster = Zcl.Utils.getCluster(clusterKey);
461
+ const type = target instanceof Endpoint ? "endpoint" : "group";
462
+ if (typeof target === "number") {
463
+ target =
464
+ group_1.default.byGroupID(target, this.databaseID) ||
465
+ group_1.default.create(target, this.databaseID);
466
+ }
467
+ const destinationAddress = target instanceof Endpoint ? target.deviceIeeeAddress : target.groupID;
468
+ const log = `Bind ${this.deviceIeeeAddress}/${this.ID} ${cluster.name} from ` +
469
+ `'${target instanceof Endpoint
470
+ ? `${destinationAddress}/${target.ID}`
471
+ : destinationAddress}'`;
472
+ debug.info(log);
473
+ try {
474
+ await entity_1.default.getAdapterByID(this.databaseID).bind(this.deviceNetworkAddress, this.deviceIeeeAddress, this.ID, cluster.ID, destinationAddress, type, target instanceof Endpoint ? target.ID : null);
475
+ this.addBinding(clusterKey, target);
476
+ }
477
+ catch (error) {
478
+ error.message = `${log} failed (${error.message})`;
479
+ debug.error(error.message);
480
+ throw error;
481
+ }
482
+ }
483
+ save() {
484
+ this.getDevice().save();
485
+ }
486
+ async unbind(clusterKey, target) {
487
+ const cluster = Zcl.Utils.getCluster(clusterKey);
488
+ const type = target instanceof Endpoint ? "endpoint" : "group";
489
+ const destinationAddress = target instanceof Endpoint
490
+ ? target.deviceIeeeAddress
491
+ : target instanceof group_1.default
492
+ ? target.groupID
493
+ : target;
494
+ const log = `Unbind ${this.deviceIeeeAddress}/${this.ID} ${cluster.name} from ` +
495
+ `'${target instanceof Endpoint
496
+ ? `${destinationAddress}/${target.ID}`
497
+ : destinationAddress}'`;
498
+ debug.info(log);
499
+ try {
500
+ await entity_1.default.getAdapterByID(this.databaseID).unbind(this.deviceNetworkAddress, this.deviceIeeeAddress, this.ID, cluster.ID, destinationAddress, type, target instanceof Endpoint ? target.ID : null);
501
+ if (typeof target === "number" &&
502
+ group_1.default.byGroupID(target, this.databaseID)) {
503
+ target = group_1.default.byGroupID(target, this.databaseID);
504
+ }
505
+ const index = this.binds.findIndex((b) => b.cluster.ID === cluster.ID && b.target === target);
506
+ if (index !== -1) {
507
+ this._binds.splice(index, 1);
508
+ this.save();
509
+ }
510
+ }
511
+ catch (error) {
512
+ error.message = `${log} failed (${error.message})`;
513
+ debug.error(error.message);
514
+ throw error;
515
+ }
516
+ }
517
+ async defaultResponse(commandID, status, clusterID, transactionSequenceNumber, options) {
518
+ (0, assert_1.default)(!options || !options.hasOwnProperty("transactionSequenceNumber"), "Use parameter");
519
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, null);
520
+ const payload = { cmdId: commandID, statusCode: status };
521
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, "defaultRsp", clusterID, payload, options.reservedBits);
522
+ const log = `DefaultResponse ${this.deviceIeeeAddress}/${this.ID} ` +
523
+ `${clusterID}(${commandID}, ${JSON.stringify(options)})`;
524
+ debug.info(log);
525
+ try {
526
+ await this.sendRequest(frame, options);
527
+ }
528
+ catch (error) {
529
+ error.message = `${log} failed (${error.message})`;
530
+ debug.error(error.message);
531
+ throw error;
532
+ }
533
+ }
534
+ async configureReporting(clusterKey, items, options) {
535
+ const cluster = Zcl.Utils.getCluster(clusterKey);
536
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
537
+ options.manufacturerCode = this.ensureManufacturerCodeIsUniqueAndGet(cluster, items, options.manufacturerCode, 'configureReporting');
538
+ const payload = items.map((item) => {
539
+ let dataType, attrId;
540
+ if (typeof item.attribute === "object") {
541
+ dataType = item.attribute.type;
542
+ attrId = item.attribute.ID;
543
+ }
544
+ else {
545
+ /* istanbul ignore else */
546
+ if (cluster.hasAttribute(item.attribute)) {
547
+ const attribute = cluster.getAttribute(item.attribute);
548
+ dataType = attribute.type;
549
+ attrId = attribute.ID;
550
+ }
551
+ }
552
+ return {
553
+ direction: Zcl.Direction.CLIENT_TO_SERVER,
554
+ attrId,
555
+ dataType,
556
+ minRepIntval: item.minimumReportInterval,
557
+ maxRepIntval: item.maximumReportInterval,
558
+ repChange: item.reportableChange,
559
+ };
560
+ });
561
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, options.transactionSequenceNumber ?? zclTransactionSequenceNumber_1.default.next(), "configReport", cluster.ID, payload, options.reservedBits);
562
+ const log = `ConfigureReporting ${this.deviceIeeeAddress}/${this.ID} ` +
563
+ `${cluster.name}(${JSON.stringify(items)}, ${JSON.stringify(options)})`;
564
+ debug.info(log);
565
+ try {
566
+ const result = await this.sendRequest(frame, options);
567
+ if (!options.disableResponse) {
568
+ this.checkStatus(result.frame.Payload);
569
+ }
570
+ for (const e of payload) {
571
+ this._configuredReportings = this._configuredReportings.filter((c) => !(c.attrId === e.attrId && c.cluster === cluster.ID &&
572
+ (!('manufacturerCode' in c) || c.manufacturerCode === options.manufacturerCode)));
573
+ }
574
+ for (const entry of payload) {
575
+ if (entry.maxRepIntval !== 0xffff) {
576
+ this._configuredReportings.push({
577
+ cluster: cluster.ID,
578
+ attrId: entry.attrId,
579
+ minRepIntval: entry.minRepIntval,
580
+ maxRepIntval: entry.maxRepIntval,
581
+ repChange: entry.repChange,
582
+ manufacturerCode: options.manufacturerCode,
583
+ });
584
+ }
585
+ }
586
+ this.save();
587
+ }
588
+ catch (error) {
589
+ error.message = `${log} failed (${error.message})`;
590
+ debug.error(error.message);
591
+ throw error;
592
+ }
593
+ }
594
+ async writeStructured(clusterKey, payload, options) {
595
+ const cluster = Zcl.Utils.getCluster(clusterKey);
596
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
597
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.GLOBAL, options.direction, options.disableDefaultResponse, options.manufacturerCode, options.transactionSequenceNumber ?? zclTransactionSequenceNumber_1.default.next(), `writeStructured`, cluster.ID, payload, options.reservedBits);
598
+ const log = `WriteStructured ${this.deviceIeeeAddress}/${this.ID} ` +
599
+ `${cluster.name}(${JSON.stringify(payload)}, ${JSON.stringify(options)})`;
600
+ debug.info(log);
601
+ try {
602
+ await this.sendRequest(frame, options);
603
+ // TODO: support `writeStructuredResponse`
604
+ }
605
+ catch (error) {
606
+ error.message = `${log} failed (${error.message})`;
607
+ debug.error(error.message);
608
+ throw error;
609
+ }
610
+ }
611
+ async command(clusterKey, commandKey, payload, options) {
612
+ const cluster = Zcl.Utils.getCluster(clusterKey);
613
+ const command = cluster.getCommand(commandKey);
614
+ const hasResponse = command.hasOwnProperty("response");
615
+ options = this.getOptionsWithDefaults(options, hasResponse, Zcl.Direction.CLIENT_TO_SERVER, cluster.manufacturerCode);
616
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.SPECIFIC, options.direction, options.disableDefaultResponse, options.manufacturerCode, options.transactionSequenceNumber ?? zclTransactionSequenceNumber_1.default.next(), command.name, cluster.name, payload, options.reservedBits);
617
+ const log = `Command ${this.deviceIeeeAddress}/${this.ID} ` +
618
+ `${cluster.name}.${command.name}(${JSON.stringify(payload)}, ${JSON.stringify(options)})`;
619
+ debug.info(log);
620
+ try {
621
+ const result = await this.sendRequest(frame, options);
622
+ if (result) {
623
+ return result.frame.Payload;
624
+ }
625
+ }
626
+ catch (error) {
627
+ error.message = `${log} failed (${error.message})`;
628
+ debug.error(error.message);
629
+ throw error;
630
+ }
631
+ }
632
+ async commandResponse(clusterKey, commandKey, payload, options, transactionSequenceNumber) {
633
+ (0, assert_1.default)(!options || !options.hasOwnProperty("transactionSequenceNumber"), "Use parameter");
634
+ const cluster = Zcl.Utils.getCluster(clusterKey);
635
+ const command = cluster.getCommandResponse(commandKey);
636
+ transactionSequenceNumber =
637
+ transactionSequenceNumber || zclTransactionSequenceNumber_1.default.next();
638
+ options = this.getOptionsWithDefaults(options, true, Zcl.Direction.SERVER_TO_CLIENT, cluster.manufacturerCode);
639
+ const frame = Zcl.ZclFrame.create(Zcl.FrameType.SPECIFIC, options.direction, options.disableDefaultResponse, options.manufacturerCode, transactionSequenceNumber, command.name, cluster.name, payload, options.reservedBits);
640
+ const log = `CommandResponse ${this.deviceIeeeAddress}/${this.ID} ` +
641
+ `${cluster.name}.${command.name}(${JSON.stringify(payload)}, ${JSON.stringify(options)})`;
642
+ debug.info(log);
643
+ try {
644
+ await this.sendRequest(frame, options, async (f) => {
645
+ // Broadcast Green Power responses
646
+ if (this.ID === 242) {
647
+ await entity_1.default.getAdapterByID(this.databaseID).sendZclFrameToAll(242, f, 242);
648
+ }
649
+ else {
650
+ await entity_1.default.getAdapterByID(this.databaseID).sendZclFrameToEndpoint(this.deviceIeeeAddress, this.deviceNetworkAddress, this.ID, f, options.timeout, options.disableResponse, options.disableRecovery, options.srcEndpoint);
651
+ }
652
+ });
653
+ }
654
+ catch (error) {
655
+ error.message = `${log} failed (${error.message})`;
656
+ debug.error(error.message);
657
+ throw error;
658
+ }
659
+ }
660
+ waitForCommand(clusterKey, commandKey, transactionSequenceNumber, timeout) {
661
+ const cluster = Zcl.Utils.getCluster(clusterKey);
662
+ const command = cluster.getCommand(commandKey);
663
+ const waiter = entity_1.default.getAdapterByID(this.databaseID).waitFor(this.deviceNetworkAddress, this.ID, Zcl.FrameType.SPECIFIC, Zcl.Direction.CLIENT_TO_SERVER, transactionSequenceNumber, cluster.ID, command.ID, timeout);
664
+ const promise = new Promise((resolve, reject) => {
665
+ waiter.promise.then((payload) => resolve({
666
+ header: payload.frame.Header,
667
+ payload: payload.frame.Payload,
668
+ }), (error) => reject(error));
669
+ });
670
+ return { promise, cancel: waiter.cancel };
671
+ }
672
+ getOptionsWithDefaults(options, disableDefaultResponse, direction, manufacturerCode) {
673
+ const providedOptions = options || {};
674
+ return {
675
+ timeout: 10000,
676
+ disableResponse: false,
677
+ disableRecovery: false,
678
+ disableDefaultResponse,
679
+ direction,
680
+ srcEndpoint: null,
681
+ reservedBits: 0,
682
+ manufacturerCode: manufacturerCode ? manufacturerCode : null,
683
+ transactionSequenceNumber: null,
684
+ writeUndiv: false,
685
+ ...providedOptions
686
+ };
687
+ }
688
+ ensureManufacturerCodeIsUniqueAndGet(cluster, attributes, fallbackManufacturerCode, caller) {
689
+ const manufacturerCodes = new Set(attributes.map((nameOrID) => {
690
+ let attributeID;
691
+ if (typeof nameOrID == 'object') {
692
+ // ConfigureReportingItem
693
+ if (typeof nameOrID.attribute !== 'object') {
694
+ attributeID = nameOrID.attribute;
695
+ }
696
+ else {
697
+ return fallbackManufacturerCode;
698
+ }
699
+ }
700
+ else {
701
+ // string || number
702
+ attributeID = nameOrID;
703
+ }
704
+ // we fall back to caller|cluster provided manufacturerCode
705
+ if (cluster.hasAttribute(attributeID)) {
706
+ const attribute = cluster.getAttribute(attributeID);
707
+ return (attribute.manufacturerCode === undefined) ?
708
+ fallbackManufacturerCode :
709
+ attribute.manufacturerCode;
710
+ }
711
+ else {
712
+ // unknown attribute, we should not fail on this here
713
+ return fallbackManufacturerCode;
714
+ }
715
+ }));
716
+ if (manufacturerCodes.size == 1) {
717
+ return manufacturerCodes.values().next().value;
718
+ }
719
+ else {
720
+ throw new Error(`Cannot have attributes with different manufacturerCode in single '${caller}' call`);
721
+ }
722
+ }
723
+ async addToGroup(group) {
724
+ await this.command("genGroups", "add", {
725
+ groupid: group.groupID,
726
+ groupname: "",
727
+ });
728
+ group.addMember(this);
729
+ }
730
+ /**
731
+ * Remove endpoint from a group, accepts both a Group and number as parameter.
732
+ * The number parameter type should only be used when removing from a group which is not known
733
+ * to zigbee-herdsman.
734
+ */
735
+ async removeFromGroup(group) {
736
+ await this.command("genGroups", "remove", {
737
+ groupid: group instanceof group_1.default ? group.groupID : group,
738
+ });
739
+ if (group instanceof group_1.default) {
740
+ group.removeMember(this);
741
+ }
742
+ }
743
+ async removeFromAllGroups() {
744
+ await this.command("genGroups", "removeAll", {}, { disableDefaultResponse: true });
745
+ this.removeFromAllGroupsDatabase();
746
+ }
747
+ removeFromAllGroupsDatabase() {
748
+ for (const group of group_1.default.allByDatabaseID(this.databaseID)) {
749
+ if (group.hasMember(this)) {
750
+ group.removeMember(this);
751
+ }
752
+ }
753
+ }
754
+ }
755
+ exports.default = Endpoint;
817
756
  //# sourceMappingURL=endpoint.js.map