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