@matter/protocol 0.16.0-alpha.0-20251213-e83db3732 → 0.16.0-alpha.0-20251217-038f88085

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 (309) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/action/client/ClientInteraction.d.ts +12 -5
  3. package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
  4. package/dist/cjs/action/client/ClientInteraction.js +39 -15
  5. package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
  6. package/dist/cjs/action/client/ClientRead.d.ts +10 -0
  7. package/dist/cjs/action/client/ClientRead.d.ts.map +1 -0
  8. package/dist/cjs/action/client/ClientRead.js +22 -0
  9. package/dist/cjs/action/client/ClientRead.js.map +6 -0
  10. package/dist/cjs/action/client/ClientRequest.d.ts +20 -0
  11. package/dist/cjs/action/client/ClientRequest.d.ts.map +1 -0
  12. package/dist/cjs/action/client/ClientRequest.js +22 -0
  13. package/dist/cjs/action/client/ClientRequest.js.map +6 -0
  14. package/dist/cjs/action/client/ClientWrite.d.ts +10 -0
  15. package/dist/cjs/action/client/ClientWrite.d.ts.map +1 -0
  16. package/dist/cjs/action/client/ClientWrite.js +22 -0
  17. package/dist/cjs/action/client/ClientWrite.js.map +6 -0
  18. package/dist/cjs/action/client/QueuedClientInteraction.d.ts +49 -0
  19. package/dist/cjs/action/client/QueuedClientInteraction.d.ts.map +1 -0
  20. package/dist/cjs/action/client/QueuedClientInteraction.js +160 -0
  21. package/dist/cjs/action/client/QueuedClientInteraction.js.map +6 -0
  22. package/dist/cjs/action/client/index.d.ts +4 -0
  23. package/dist/cjs/action/client/index.d.ts.map +1 -1
  24. package/dist/cjs/action/client/index.js +4 -0
  25. package/dist/cjs/action/client/index.js.map +1 -1
  26. package/dist/cjs/action/client/subscription/ClientSubscribe.d.ts +2 -1
  27. package/dist/cjs/action/client/subscription/ClientSubscribe.d.ts.map +1 -1
  28. package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.d.ts.map +1 -1
  29. package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.js +14 -3
  30. package/dist/cjs/action/client/subscription/ClientSubscriptionHandler.js.map +1 -1
  31. package/dist/cjs/action/client/subscription/SustainedSubscription.d.ts +1 -1
  32. package/dist/cjs/action/client/subscription/SustainedSubscription.d.ts.map +1 -1
  33. package/dist/cjs/action/client/subscription/SustainedSubscription.js +1 -4
  34. package/dist/cjs/action/client/subscription/SustainedSubscription.js.map +1 -1
  35. package/dist/cjs/action/request/Invoke.d.ts +7 -1
  36. package/dist/cjs/action/request/Invoke.d.ts.map +1 -1
  37. package/dist/cjs/action/request/Invoke.js +0 -3
  38. package/dist/cjs/action/request/Invoke.js.map +1 -1
  39. package/dist/cjs/action/request/Read.d.ts.map +1 -1
  40. package/dist/cjs/action/request/Read.js +3 -2
  41. package/dist/cjs/action/request/Read.js.map +1 -1
  42. package/dist/cjs/action/request/Specifier.d.ts +1 -1
  43. package/dist/cjs/action/request/Specifier.d.ts.map +1 -1
  44. package/dist/cjs/action/request/Specifier.js +3 -0
  45. package/dist/cjs/action/request/Specifier.js.map +1 -1
  46. package/dist/cjs/action/request/Write.d.ts +1 -0
  47. package/dist/cjs/action/request/Write.d.ts.map +1 -1
  48. package/dist/cjs/action/request/Write.js +10 -2
  49. package/dist/cjs/action/request/Write.js.map +1 -1
  50. package/dist/cjs/action/response/ReadResult.d.ts +1 -1
  51. package/dist/cjs/action/response/ReadResult.d.ts.map +1 -1
  52. package/dist/cjs/cluster/client/ClusterClientTypes.d.ts +37 -8
  53. package/dist/cjs/cluster/client/ClusterClientTypes.d.ts.map +1 -1
  54. package/dist/cjs/cluster/client/index.d.ts +0 -3
  55. package/dist/cjs/cluster/client/index.d.ts.map +1 -1
  56. package/dist/cjs/cluster/client/index.js +0 -3
  57. package/dist/cjs/cluster/client/index.js.map +1 -1
  58. package/dist/cjs/interaction/InteractionMessenger.d.ts.map +1 -1
  59. package/dist/cjs/interaction/InteractionMessenger.js +3 -2
  60. package/dist/cjs/interaction/InteractionMessenger.js.map +1 -1
  61. package/dist/cjs/interaction/SubscriptionClient.d.ts.map +1 -1
  62. package/dist/cjs/interaction/SubscriptionClient.js +2 -1
  63. package/dist/cjs/interaction/SubscriptionClient.js.map +1 -1
  64. package/dist/cjs/interaction/index.d.ts +1 -1
  65. package/dist/cjs/interaction/index.d.ts.map +1 -1
  66. package/dist/cjs/interaction/index.js +1 -1
  67. package/dist/cjs/interaction/index.js.map +1 -1
  68. package/dist/cjs/peer/CommissioningError.d.ts +13 -0
  69. package/dist/cjs/peer/CommissioningError.d.ts.map +1 -0
  70. package/dist/cjs/peer/CommissioningError.js +32 -0
  71. package/dist/cjs/peer/CommissioningError.js.map +6 -0
  72. package/dist/cjs/peer/ControllerCommissioner.d.ts +2 -3
  73. package/dist/cjs/peer/ControllerCommissioner.d.ts.map +1 -1
  74. package/dist/cjs/peer/ControllerCommissioner.js +20 -13
  75. package/dist/cjs/peer/ControllerCommissioner.js.map +2 -2
  76. package/dist/cjs/peer/ControllerCommissioningFlow.d.ts +7 -16
  77. package/dist/cjs/peer/ControllerCommissioningFlow.d.ts.map +1 -1
  78. package/dist/cjs/peer/ControllerCommissioningFlow.js +395 -178
  79. package/dist/cjs/peer/ControllerCommissioningFlow.js.map +1 -1
  80. package/dist/cjs/peer/ControllerDiscovery.d.ts +4 -0
  81. package/dist/cjs/peer/ControllerDiscovery.d.ts.map +1 -1
  82. package/dist/cjs/peer/ControllerDiscovery.js +6 -3
  83. package/dist/cjs/peer/ControllerDiscovery.js.map +1 -1
  84. package/dist/cjs/peer/InteractionQueue.d.ts +2 -2
  85. package/dist/cjs/peer/InteractionQueue.d.ts.map +1 -1
  86. package/dist/cjs/peer/InteractionQueue.js +1 -1
  87. package/dist/cjs/peer/InteractionQueue.js.map +1 -1
  88. package/dist/cjs/peer/PeerAddressStore.d.ts +0 -9
  89. package/dist/cjs/peer/PeerAddressStore.d.ts.map +1 -1
  90. package/dist/cjs/peer/PeerAddressStore.js.map +1 -1
  91. package/dist/cjs/peer/PeerSet.d.ts +0 -2
  92. package/dist/cjs/peer/PeerSet.d.ts.map +1 -1
  93. package/dist/cjs/peer/PeerSet.js +32 -18
  94. package/dist/cjs/peer/PeerSet.js.map +1 -1
  95. package/dist/cjs/peer/PhysicalDeviceProperties.js +1 -1
  96. package/dist/cjs/peer/PhysicalDeviceProperties.js.map +1 -1
  97. package/dist/cjs/peer/index.d.ts +1 -0
  98. package/dist/cjs/peer/index.d.ts.map +1 -1
  99. package/dist/cjs/peer/index.js +1 -0
  100. package/dist/cjs/peer/index.js.map +1 -1
  101. package/dist/cjs/protocol/DeviceCommissioner.d.ts.map +1 -1
  102. package/dist/cjs/protocol/DeviceCommissioner.js.map +1 -1
  103. package/dist/cjs/protocol/ExchangeManager.js +2 -2
  104. package/dist/cjs/protocol/ExchangeManager.js.map +1 -1
  105. package/dist/cjs/protocol/ExchangeProvider.d.ts +13 -4
  106. package/dist/cjs/protocol/ExchangeProvider.d.ts.map +1 -1
  107. package/dist/cjs/protocol/ExchangeProvider.js +5 -3
  108. package/dist/cjs/protocol/ExchangeProvider.js.map +1 -1
  109. package/dist/cjs/session/NodeSession.d.ts +5 -2
  110. package/dist/cjs/session/NodeSession.d.ts.map +1 -1
  111. package/dist/cjs/session/NodeSession.js +5 -4
  112. package/dist/cjs/session/NodeSession.js.map +1 -1
  113. package/dist/cjs/session/Session.d.ts +5 -3
  114. package/dist/cjs/session/Session.d.ts.map +1 -1
  115. package/dist/cjs/session/Session.js +8 -4
  116. package/dist/cjs/session/Session.js.map +1 -1
  117. package/dist/cjs/session/SessionManager.d.ts +8 -0
  118. package/dist/cjs/session/SessionManager.d.ts.map +1 -1
  119. package/dist/cjs/session/SessionManager.js +16 -2
  120. package/dist/cjs/session/SessionManager.js.map +1 -1
  121. package/dist/esm/action/client/ClientInteraction.d.ts +12 -5
  122. package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
  123. package/dist/esm/action/client/ClientInteraction.js +42 -16
  124. package/dist/esm/action/client/ClientInteraction.js.map +1 -1
  125. package/dist/esm/action/client/ClientRead.d.ts +10 -0
  126. package/dist/esm/action/client/ClientRead.d.ts.map +1 -0
  127. package/dist/esm/action/client/ClientRead.js +6 -0
  128. package/dist/esm/action/client/ClientRead.js.map +6 -0
  129. package/dist/esm/action/client/ClientRequest.d.ts +20 -0
  130. package/dist/esm/action/client/ClientRequest.d.ts.map +1 -0
  131. package/dist/esm/action/client/ClientRequest.js +6 -0
  132. package/dist/esm/action/client/ClientRequest.js.map +6 -0
  133. package/dist/esm/action/client/ClientWrite.d.ts +10 -0
  134. package/dist/esm/action/client/ClientWrite.d.ts.map +1 -0
  135. package/dist/esm/action/client/ClientWrite.js +6 -0
  136. package/dist/esm/action/client/ClientWrite.js.map +6 -0
  137. package/dist/esm/action/client/QueuedClientInteraction.d.ts +49 -0
  138. package/dist/esm/action/client/QueuedClientInteraction.d.ts.map +1 -0
  139. package/dist/esm/action/client/QueuedClientInteraction.js +140 -0
  140. package/dist/esm/action/client/QueuedClientInteraction.js.map +6 -0
  141. package/dist/esm/action/client/index.d.ts +4 -0
  142. package/dist/esm/action/client/index.d.ts.map +1 -1
  143. package/dist/esm/action/client/index.js +4 -0
  144. package/dist/esm/action/client/index.js.map +1 -1
  145. package/dist/esm/action/client/subscription/ClientSubscribe.d.ts +2 -1
  146. package/dist/esm/action/client/subscription/ClientSubscribe.d.ts.map +1 -1
  147. package/dist/esm/action/client/subscription/ClientSubscriptionHandler.d.ts.map +1 -1
  148. package/dist/esm/action/client/subscription/ClientSubscriptionHandler.js +14 -3
  149. package/dist/esm/action/client/subscription/ClientSubscriptionHandler.js.map +1 -1
  150. package/dist/esm/action/client/subscription/SustainedSubscription.d.ts +1 -1
  151. package/dist/esm/action/client/subscription/SustainedSubscription.d.ts.map +1 -1
  152. package/dist/esm/action/client/subscription/SustainedSubscription.js +1 -4
  153. package/dist/esm/action/client/subscription/SustainedSubscription.js.map +1 -1
  154. package/dist/esm/action/request/Invoke.d.ts +7 -1
  155. package/dist/esm/action/request/Invoke.d.ts.map +1 -1
  156. package/dist/esm/action/request/Invoke.js +0 -3
  157. package/dist/esm/action/request/Invoke.js.map +1 -1
  158. package/dist/esm/action/request/Read.d.ts.map +1 -1
  159. package/dist/esm/action/request/Read.js +3 -2
  160. package/dist/esm/action/request/Read.js.map +1 -1
  161. package/dist/esm/action/request/Specifier.d.ts +1 -1
  162. package/dist/esm/action/request/Specifier.d.ts.map +1 -1
  163. package/dist/esm/action/request/Specifier.js +3 -0
  164. package/dist/esm/action/request/Specifier.js.map +1 -1
  165. package/dist/esm/action/request/Write.d.ts +1 -0
  166. package/dist/esm/action/request/Write.d.ts.map +1 -1
  167. package/dist/esm/action/request/Write.js +10 -2
  168. package/dist/esm/action/request/Write.js.map +1 -1
  169. package/dist/esm/action/response/ReadResult.d.ts +1 -1
  170. package/dist/esm/action/response/ReadResult.d.ts.map +1 -1
  171. package/dist/esm/cluster/client/ClusterClientTypes.d.ts +37 -8
  172. package/dist/esm/cluster/client/ClusterClientTypes.d.ts.map +1 -1
  173. package/dist/esm/cluster/client/index.d.ts +0 -3
  174. package/dist/esm/cluster/client/index.d.ts.map +1 -1
  175. package/dist/esm/cluster/client/index.js +0 -3
  176. package/dist/esm/cluster/client/index.js.map +1 -1
  177. package/dist/esm/interaction/InteractionMessenger.d.ts.map +1 -1
  178. package/dist/esm/interaction/InteractionMessenger.js +4 -3
  179. package/dist/esm/interaction/InteractionMessenger.js.map +1 -1
  180. package/dist/esm/interaction/SubscriptionClient.d.ts.map +1 -1
  181. package/dist/esm/interaction/SubscriptionClient.js +2 -1
  182. package/dist/esm/interaction/SubscriptionClient.js.map +1 -1
  183. package/dist/esm/interaction/index.d.ts +1 -1
  184. package/dist/esm/interaction/index.d.ts.map +1 -1
  185. package/dist/esm/interaction/index.js +1 -1
  186. package/dist/esm/peer/CommissioningError.d.ts +13 -0
  187. package/dist/esm/peer/CommissioningError.d.ts.map +1 -0
  188. package/dist/esm/peer/CommissioningError.js +12 -0
  189. package/dist/esm/peer/CommissioningError.js.map +6 -0
  190. package/dist/esm/peer/ControllerCommissioner.d.ts +2 -3
  191. package/dist/esm/peer/ControllerCommissioner.d.ts.map +1 -1
  192. package/dist/esm/peer/ControllerCommissioner.js +19 -13
  193. package/dist/esm/peer/ControllerCommissioner.js.map +2 -2
  194. package/dist/esm/peer/ControllerCommissioningFlow.d.ts +7 -16
  195. package/dist/esm/peer/ControllerCommissioningFlow.d.ts.map +1 -1
  196. package/dist/esm/peer/ControllerCommissioningFlow.js +380 -162
  197. package/dist/esm/peer/ControllerCommissioningFlow.js.map +1 -1
  198. package/dist/esm/peer/ControllerDiscovery.d.ts +4 -0
  199. package/dist/esm/peer/ControllerDiscovery.d.ts.map +1 -1
  200. package/dist/esm/peer/ControllerDiscovery.js +4 -1
  201. package/dist/esm/peer/ControllerDiscovery.js.map +1 -1
  202. package/dist/esm/peer/InteractionQueue.d.ts +2 -2
  203. package/dist/esm/peer/InteractionQueue.d.ts.map +1 -1
  204. package/dist/esm/peer/InteractionQueue.js +2 -2
  205. package/dist/esm/peer/InteractionQueue.js.map +1 -1
  206. package/dist/esm/peer/PeerAddressStore.d.ts +0 -9
  207. package/dist/esm/peer/PeerAddressStore.d.ts.map +1 -1
  208. package/dist/esm/peer/PeerAddressStore.js.map +1 -1
  209. package/dist/esm/peer/PeerSet.d.ts +0 -2
  210. package/dist/esm/peer/PeerSet.d.ts.map +1 -1
  211. package/dist/esm/peer/PeerSet.js +32 -18
  212. package/dist/esm/peer/PeerSet.js.map +1 -1
  213. package/dist/esm/peer/PhysicalDeviceProperties.js +1 -1
  214. package/dist/esm/peer/PhysicalDeviceProperties.js.map +1 -1
  215. package/dist/esm/peer/index.d.ts +1 -0
  216. package/dist/esm/peer/index.d.ts.map +1 -1
  217. package/dist/esm/peer/index.js +1 -0
  218. package/dist/esm/peer/index.js.map +1 -1
  219. package/dist/esm/protocol/DeviceCommissioner.d.ts.map +1 -1
  220. package/dist/esm/protocol/DeviceCommissioner.js.map +1 -1
  221. package/dist/esm/protocol/ExchangeManager.js +2 -2
  222. package/dist/esm/protocol/ExchangeManager.js.map +1 -1
  223. package/dist/esm/protocol/ExchangeProvider.d.ts +13 -4
  224. package/dist/esm/protocol/ExchangeProvider.d.ts.map +1 -1
  225. package/dist/esm/protocol/ExchangeProvider.js +5 -3
  226. package/dist/esm/protocol/ExchangeProvider.js.map +1 -1
  227. package/dist/esm/session/NodeSession.d.ts +5 -2
  228. package/dist/esm/session/NodeSession.d.ts.map +1 -1
  229. package/dist/esm/session/NodeSession.js +5 -4
  230. package/dist/esm/session/NodeSession.js.map +1 -1
  231. package/dist/esm/session/Session.d.ts +5 -3
  232. package/dist/esm/session/Session.d.ts.map +1 -1
  233. package/dist/esm/session/Session.js +8 -4
  234. package/dist/esm/session/Session.js.map +1 -1
  235. package/dist/esm/session/SessionManager.d.ts +8 -0
  236. package/dist/esm/session/SessionManager.d.ts.map +1 -1
  237. package/dist/esm/session/SessionManager.js +17 -2
  238. package/dist/esm/session/SessionManager.js.map +1 -1
  239. package/package.json +6 -6
  240. package/src/action/client/ClientInteraction.ts +58 -19
  241. package/src/action/client/ClientRead.ts +10 -0
  242. package/src/action/client/ClientRequest.ts +20 -0
  243. package/src/action/client/ClientWrite.ts +10 -0
  244. package/src/action/client/QueuedClientInteraction.ts +91 -0
  245. package/src/action/client/index.ts +4 -0
  246. package/src/action/client/subscription/ClientSubscribe.ts +2 -1
  247. package/src/action/client/subscription/ClientSubscriptionHandler.ts +14 -3
  248. package/src/action/client/subscription/SustainedSubscription.ts +6 -9
  249. package/src/action/request/Invoke.ts +11 -4
  250. package/src/action/request/Read.ts +3 -2
  251. package/src/action/request/Specifier.ts +4 -1
  252. package/src/action/request/Write.ts +11 -2
  253. package/src/action/response/ReadResult.ts +1 -1
  254. package/src/cluster/client/ClusterClientTypes.ts +47 -7
  255. package/src/cluster/client/index.ts +0 -3
  256. package/src/interaction/InteractionMessenger.ts +5 -4
  257. package/src/interaction/SubscriptionClient.ts +2 -1
  258. package/src/interaction/index.ts +1 -1
  259. package/src/peer/CommissioningError.ts +13 -0
  260. package/src/peer/ControllerCommissioner.ts +21 -13
  261. package/src/peer/ControllerCommissioningFlow.ts +418 -186
  262. package/src/peer/ControllerDiscovery.ts +4 -1
  263. package/src/peer/InteractionQueue.ts +2 -2
  264. package/src/peer/PeerAddressStore.ts +0 -9
  265. package/src/peer/PeerSet.ts +56 -23
  266. package/src/peer/PhysicalDeviceProperties.ts +1 -1
  267. package/src/peer/index.ts +1 -0
  268. package/src/protocol/DeviceCommissioner.ts +0 -1
  269. package/src/protocol/ExchangeManager.ts +2 -2
  270. package/src/protocol/ExchangeProvider.ts +9 -7
  271. package/src/session/NodeSession.ts +5 -4
  272. package/src/session/Session.ts +8 -4
  273. package/src/session/SessionManager.ts +19 -2
  274. package/dist/cjs/cluster/client/AttributeClient.d.ts +0 -75
  275. package/dist/cjs/cluster/client/AttributeClient.d.ts.map +0 -1
  276. package/dist/cjs/cluster/client/AttributeClient.js +0 -209
  277. package/dist/cjs/cluster/client/AttributeClient.js.map +0 -6
  278. package/dist/cjs/cluster/client/ClusterClient.d.ts +0 -11
  279. package/dist/cjs/cluster/client/ClusterClient.d.ts.map +0 -1
  280. package/dist/cjs/cluster/client/ClusterClient.js +0 -335
  281. package/dist/cjs/cluster/client/ClusterClient.js.map +0 -6
  282. package/dist/cjs/cluster/client/EventClient.d.ts +0 -33
  283. package/dist/cjs/cluster/client/EventClient.d.ts.map +0 -1
  284. package/dist/cjs/cluster/client/EventClient.js +0 -89
  285. package/dist/cjs/cluster/client/EventClient.js.map +0 -6
  286. package/dist/cjs/interaction/InteractionClient.d.ts +0 -375
  287. package/dist/cjs/interaction/InteractionClient.d.ts.map +0 -1
  288. package/dist/cjs/interaction/InteractionClient.js +0 -1046
  289. package/dist/cjs/interaction/InteractionClient.js.map +0 -6
  290. package/dist/esm/cluster/client/AttributeClient.d.ts +0 -75
  291. package/dist/esm/cluster/client/AttributeClient.d.ts.map +0 -1
  292. package/dist/esm/cluster/client/AttributeClient.js +0 -189
  293. package/dist/esm/cluster/client/AttributeClient.js.map +0 -6
  294. package/dist/esm/cluster/client/ClusterClient.d.ts +0 -11
  295. package/dist/esm/cluster/client/ClusterClient.d.ts.map +0 -1
  296. package/dist/esm/cluster/client/ClusterClient.js +0 -320
  297. package/dist/esm/cluster/client/ClusterClient.js.map +0 -6
  298. package/dist/esm/cluster/client/EventClient.d.ts +0 -33
  299. package/dist/esm/cluster/client/EventClient.d.ts.map +0 -1
  300. package/dist/esm/cluster/client/EventClient.js +0 -69
  301. package/dist/esm/cluster/client/EventClient.js.map +0 -6
  302. package/dist/esm/interaction/InteractionClient.d.ts +0 -375
  303. package/dist/esm/interaction/InteractionClient.d.ts.map +0 -1
  304. package/dist/esm/interaction/InteractionClient.js +0 -1047
  305. package/dist/esm/interaction/InteractionClient.js.map +0 -6
  306. package/src/cluster/client/AttributeClient.ts +0 -230
  307. package/src/cluster/client/ClusterClient.ts +0 -433
  308. package/src/cluster/client/EventClient.ts +0 -99
  309. package/src/interaction/InteractionClient.ts +0 -1614
@@ -1,1046 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var InteractionClient_exports = {};
20
- __export(InteractionClient_exports, {
21
- InteractionClient: () => InteractionClient,
22
- InteractionClientProvider: () => InteractionClientProvider
23
- });
24
- module.exports = __toCommonJS(InteractionClient_exports);
25
- var import_ReadScope = require("#action/client/ReadScope.js");
26
- var import_access_control = require("#clusters/access-control");
27
- var import_Mark = require("#common/Mark.js");
28
- var import_general = require("#general");
29
- var import_model = require("#model");
30
- var import_PeerAddress = require("#peer/PeerAddress.js");
31
- var import_PeerSet = require("#peer/PeerSet.js");
32
- var import_types = require("#types");
33
- var import_ExchangeProvider = require("../protocol/ExchangeProvider.js");
34
- var import_InteractionMessenger = require("./InteractionMessenger.js");
35
- var import_Subscription = require("./Subscription.js");
36
- var import_SubscriptionClient = require("./SubscriptionClient.js");
37
- /**
38
- * @license
39
- * Copyright 2022-2025 Matter.js Authors
40
- * SPDX-License-Identifier: Apache-2.0
41
- */
42
- const logger = import_general.Logger.get("InteractionClient");
43
- const REQUEST_ALL = [{}];
44
- const DEFAULT_TIMED_REQUEST_TIMEOUT = (0, import_general.Seconds)(10);
45
- const DEFAULT_MINIMUM_RESPONSE_TIMEOUT_WITH_FAILSAFE = (0, import_general.Seconds)(30);
46
- const AclClusterId = import_access_control.AccessControl.Complete.id;
47
- const AclAttributeId = import_access_control.AccessControl.Complete.attributes.acl.id;
48
- const AclExtensionAttributeId = import_access_control.AccessControl.Complete.attributes.extension.id;
49
- function isAclOrExtensionPath(path) {
50
- const { clusterId, attributeId } = path;
51
- return clusterId === AclClusterId && (attributeId === AclAttributeId || attributeId === AclExtensionAttributeId);
52
- }
53
- class InteractionClientProvider {
54
- #peers;
55
- #clients = new import_PeerAddress.PeerAddressMap();
56
- #subscriptionClient = new import_SubscriptionClient.SubscriptionClient();
57
- constructor(peers) {
58
- this.#peers = peers;
59
- this.#peers.deleted.on((peer) => this.#onPeerLoss(peer.address));
60
- this.#peers.disconnected.on((peer) => this.#onPeerLoss(peer.address));
61
- }
62
- static [import_general.Environmental.create](env) {
63
- const instance = new InteractionClientProvider(env.get(import_PeerSet.PeerSet));
64
- env.set(InteractionClientProvider, instance);
65
- return instance;
66
- }
67
- get peers() {
68
- return this.#peers;
69
- }
70
- get subscriptionClient() {
71
- return this.#subscriptionClient;
72
- }
73
- async connect(address, options) {
74
- await this.#peers.connect(address, options);
75
- return this.getInteractionClient(address, options);
76
- }
77
- async interactionClientFor(session) {
78
- const exchangeProvider = await this.#peers.exchangeProviderFor(session);
79
- return new InteractionClient(
80
- exchangeProvider,
81
- this.#subscriptionClient,
82
- void 0,
83
- this.#peers.interactionQueue
84
- );
85
- }
86
- async getInteractionClient(address, options = {}) {
87
- let client = this.#clients.get(address);
88
- if (client !== void 0) {
89
- return client;
90
- }
91
- const isGroupAddress = import_PeerAddress.PeerAddress.isGroup(address);
92
- const nodeStore = isGroupAddress ? void 0 : this.#peers.get(address)?.descriptor.dataStore;
93
- await nodeStore?.construction;
94
- const exchangeProvider = await this.#peers.exchangeProviderFor(address, options);
95
- client = new InteractionClient(
96
- exchangeProvider,
97
- this.#subscriptionClient,
98
- address,
99
- this.#peers.interactionQueue,
100
- nodeStore
101
- );
102
- this.#clients.set(address, client);
103
- return client;
104
- }
105
- #onPeerLoss(address) {
106
- const client = this.#clients.get(address);
107
- if (client !== void 0) {
108
- client.close();
109
- this.#clients.delete(address);
110
- }
111
- }
112
- }
113
- class InteractionClient {
114
- #exchangeProvider;
115
- #nodeStore;
116
- #ownSubscriptionIds = /* @__PURE__ */ new Set();
117
- #queue;
118
- #address;
119
- isGroupAddress;
120
- // TODO - SubscriptionClient is used by CommissioningController but not ClientNode. However InteractionClient *is*
121
- // used by ClientNode to perform commissioning, during which time SubscriptionClient is unnecessary. So this should
122
- // be set after commissioning
123
- //
124
- // If we remove CommissioningController then this entire class goes away; if we first move commissioning to
125
- // ClientInteraction then this should become required
126
- #subscriptionClient;
127
- constructor(exchangeProvider, subscriptionClient, address, queue, nodeStore) {
128
- this.#exchangeProvider = exchangeProvider;
129
- this.#nodeStore = nodeStore;
130
- this.#subscriptionClient = subscriptionClient;
131
- this.#queue = queue;
132
- this.#address = address;
133
- this.isGroupAddress = address !== void 0 ? import_PeerAddress.PeerAddress.isGroup(address) : false;
134
- }
135
- get address() {
136
- if (this.#address === void 0) {
137
- throw new import_general.ImplementationError("This InteractionClient is not bound to a specific peer.");
138
- }
139
- return this.#address;
140
- }
141
- get isReconnectable() {
142
- return this.#exchangeProvider instanceof import_ExchangeProvider.ReconnectableExchangeProvider;
143
- }
144
- get channelUpdated() {
145
- if (this.#exchangeProvider instanceof import_ExchangeProvider.ReconnectableExchangeProvider) {
146
- return this.#exchangeProvider.channelUpdated;
147
- }
148
- throw new import_general.ImplementationError("ExchangeProvider does not support channelUpdated");
149
- }
150
- /** Calculates the current maximum response time for a message use in additional logic like timers. */
151
- maximumPeerResponseTime(expectedProcessingTime) {
152
- return this.#exchangeProvider.maximumPeerResponseTime(expectedProcessingTime);
153
- }
154
- removeSubscription(subscriptionId) {
155
- this.#ownSubscriptionIds.delete(subscriptionId);
156
- this.#subscriptionClient?.delete(subscriptionId);
157
- }
158
- async getAllAttributes(options = {}) {
159
- return (await this.getMultipleAttributesAndEvents({
160
- attributes: REQUEST_ALL,
161
- ...options
162
- })).attributeReports;
163
- }
164
- async getAllEvents(options = {}) {
165
- return (await this.getMultipleAttributesAndEvents({
166
- events: REQUEST_ALL,
167
- ...options
168
- })).eventReports;
169
- }
170
- async getAllAttributesAndEvents(options = {}) {
171
- return this.getMultipleAttributesAndEvents({
172
- attributes: REQUEST_ALL,
173
- events: REQUEST_ALL,
174
- ...options
175
- });
176
- }
177
- async getMultipleAttributes(options = {}) {
178
- return (await this.getMultipleAttributesAndEvents(options)).attributeReports;
179
- }
180
- async getMultipleAttributesAndStatus(options = {}) {
181
- const { attributeReports, attributeStatus } = await this.getMultipleAttributesAndEvents(options);
182
- return { attributeData: attributeReports, attributeStatus };
183
- }
184
- async getMultipleEvents(options = {}) {
185
- return (await this.getMultipleAttributesAndEvents(options)).eventReports;
186
- }
187
- async getMultipleEventsAndStatus(options = {}) {
188
- const { eventReports, eventStatus } = await this.getMultipleAttributesAndEvents(options);
189
- return { eventData: eventReports, eventStatus };
190
- }
191
- async getMultipleAttributesAndEvents(options = {}) {
192
- if (this.isGroupAddress) {
193
- throw new import_general.ImplementationError("Reading data from group addresses is not supported.");
194
- }
195
- const {
196
- attributes: attributeRequests,
197
- dataVersionFilters,
198
- executeQueued,
199
- events: eventRequests,
200
- enrichCachedAttributeData,
201
- eventFilters,
202
- isFabricFiltered = true,
203
- attributeChangeListener
204
- } = options;
205
- if (attributeRequests === void 0 && eventRequests === void 0) {
206
- throw new import_general.ImplementationError("When reading attributes and events, at least one must be specified.");
207
- }
208
- const readPathsCount = (attributeRequests?.length ?? 0) + (eventRequests?.length ?? 0);
209
- if (readPathsCount > 9) {
210
- logger.debug(
211
- "Read interactions with more then 9 paths might be not allowed by the device. Consider splitting then into several read requests."
212
- );
213
- }
214
- const result = await this.withMessenger(async (messenger) => {
215
- return await this.processReadRequest(
216
- messenger,
217
- {
218
- attributeRequests,
219
- dataVersionFilters: dataVersionFilters?.map(({ endpointId, clusterId, dataVersion }) => ({
220
- path: { endpointId, clusterId },
221
- dataVersion
222
- })),
223
- eventRequests,
224
- eventFilters,
225
- isFabricFiltered,
226
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION
227
- },
228
- attributeChangeListener
229
- );
230
- }, executeQueued);
231
- if (dataVersionFilters !== void 0 && dataVersionFilters.length > 0 && enrichCachedAttributeData) {
232
- this.#enrichCachedAttributeData(result.attributeReports, dataVersionFilters);
233
- }
234
- return result;
235
- }
236
- async getAttribute(options) {
237
- const { requestFromRemote } = options;
238
- const response = await this.getAttributeWithVersion({
239
- ...options,
240
- requestFromRemote
241
- });
242
- return response?.value;
243
- }
244
- getStoredAttribute(options) {
245
- return this.getStoredAttributeWithVersion(options)?.value;
246
- }
247
- getStoredAttributeWithVersion(options) {
248
- if (this.isGroupAddress) {
249
- throw new import_general.ImplementationError("Reading data from group addresses is not supported.");
250
- }
251
- const { endpointId, clusterId, attribute } = options;
252
- const { id: attributeId } = attribute;
253
- if (this.#nodeStore !== void 0) {
254
- const { value, version } = this.#nodeStore.retrieveAttribute(endpointId, clusterId, attributeId) ?? {};
255
- if (value !== void 0 && version !== void 0) {
256
- return { value, version };
257
- }
258
- }
259
- return void 0;
260
- }
261
- async getAttributeWithVersion(options) {
262
- if (this.isGroupAddress) {
263
- throw new import_general.ImplementationError("Reading data from group addresses is not supported.");
264
- }
265
- const {
266
- endpointId,
267
- clusterId,
268
- attribute,
269
- requestFromRemote,
270
- isFabricFiltered,
271
- executeQueued,
272
- attributeChangeListener
273
- } = options;
274
- const { id: attributeId } = attribute;
275
- if (this.#nodeStore !== void 0) {
276
- if (!requestFromRemote) {
277
- const { value, version } = this.#nodeStore.retrieveAttribute(endpointId, clusterId, attributeId) ?? {};
278
- if (value !== void 0 && version !== void 0) {
279
- return { value, version };
280
- }
281
- }
282
- if (requestFromRemote === false) {
283
- return void 0;
284
- }
285
- }
286
- const { attributeReports } = await this.getMultipleAttributesAndEvents({
287
- attributes: [{ endpointId, clusterId, attributeId }],
288
- isFabricFiltered,
289
- executeQueued,
290
- attributeChangeListener
291
- });
292
- if (attributeReports.length === 0) {
293
- return void 0;
294
- }
295
- if (attributeReports.length > 1) {
296
- throw new import_general.UnexpectedDataError("Unexpected response with more then one attribute");
297
- }
298
- return { value: attributeReports[0].value, version: attributeReports[0].version };
299
- }
300
- async getEvent(options) {
301
- const { endpointId, clusterId, event, minimumEventNumber, isFabricFiltered = true, executeQueued } = options;
302
- const { id: eventId } = event;
303
- const response = await this.getMultipleAttributesAndEvents({
304
- events: [{ endpointId, clusterId, eventId }],
305
- eventFilters: minimumEventNumber !== void 0 ? [{ eventMin: minimumEventNumber }] : void 0,
306
- isFabricFiltered,
307
- executeQueued
308
- });
309
- return response?.eventReports[0]?.events;
310
- }
311
- async processReadRequest(messenger, request, attributeChangeListener) {
312
- const { attributeRequests, eventRequests, dataVersionFilters, eventFilters, isFabricFiltered } = request;
313
- logger.debug(() => [
314
- "Read",
315
- import_Mark.Mark.OUTBOUND,
316
- messenger.exchange.via,
317
- import_general.Diagnostic.dict({
318
- attributes: attributeRequests?.length ? attributeRequests?.map((path) => (0, import_types.resolveAttributeName)(path)).join(", ") : void 0,
319
- events: eventRequests?.length ? eventRequests?.map((path) => (0, import_types.resolveEventName)(path)).join(", ") : void 0,
320
- dataVersionFilters: dataVersionFilters?.length ? dataVersionFilters.map(
321
- ({ path: { endpointId, clusterId }, dataVersion }) => `${endpointId}/${clusterId}=${dataVersion}`
322
- ).join(", ") : void 0,
323
- eventFilters: eventFilters?.length ? eventFilters.map(({ nodeId, eventMin }) => `${nodeId}=${eventMin}`).join(", ") : void 0,
324
- fabricFiltered: isFabricFiltered
325
- })
326
- ]);
327
- await messenger.sendReadRequest(request);
328
- const scope = (0, import_ReadScope.ReadScope)(request);
329
- const response = await messenger.readAggregateDataReport(
330
- (chunk) => this.processAttributeUpdates(scope, chunk, attributeChangeListener)
331
- );
332
- const { attributeReports, attributeStatus, eventReports, eventStatus } = response;
333
- if (attributeReports.length || eventReports.length || attributeStatus?.length || eventStatus?.length) {
334
- logger.debug(() => [
335
- "Read",
336
- import_Mark.Mark.INBOUND,
337
- messenger.exchange.via,
338
- import_general.Diagnostic.dict({
339
- attributes: attributeReports.length ? attributeReports.map(({ path, value }) => `${(0, import_types.resolveAttributeName)(path)}=${(0, import_general.serialize)(value)}`).join(", ") : void 0,
340
- events: eventReports.length ? eventReports.map(({ path }) => (0, import_types.resolveEventName)(path)).join(", ") : void 0,
341
- attributeStatus: attributeStatus?.length ? attributeStatus.map(({ path }) => (0, import_types.resolveAttributeName)(path)).join(", ") : void 0,
342
- eventStatus: eventStatus?.length ? eventStatus.map(({ path }) => (0, import_types.resolveEventName)(path)).join(", ") : void 0,
343
- fabricFiltered: isFabricFiltered
344
- })
345
- ]);
346
- } else {
347
- logger.debug("Read", import_Mark.Mark.INBOUND, messenger.exchange.via, "empty response");
348
- }
349
- return response;
350
- }
351
- async setAttribute(options) {
352
- const { attributeData, asTimedRequest, timedRequestTimeout, suppressResponse, executeQueued, chunkLists } = options;
353
- const { endpointId, clusterId, attribute, value, dataVersion } = attributeData;
354
- const response = await this.setMultipleAttributes({
355
- attributes: [{ endpointId, clusterId, attribute, value, dataVersion }],
356
- asTimedRequest,
357
- timedRequestTimeout,
358
- suppressResponse,
359
- executeQueued,
360
- chunkLists
361
- });
362
- if (response.length) {
363
- const {
364
- path: { endpointId: endpointId2, clusterId: clusterId2, attributeId },
365
- status
366
- } = response[0];
367
- if (status !== void 0 && status !== import_types.StatusCode.Success) {
368
- throw new import_types.StatusResponseError(
369
- `Error setting attribute ${endpointId2}/${clusterId2}/${attributeId}`,
370
- status
371
- );
372
- }
373
- }
374
- }
375
- async setMultipleAttributes(options) {
376
- const { executeQueued } = options;
377
- const {
378
- attributes,
379
- asTimedRequest,
380
- timedRequestTimeout = DEFAULT_TIMED_REQUEST_TIMEOUT,
381
- suppressResponse = this.isGroupAddress,
382
- chunkLists = true
383
- // Should be true currently to stay in sync with chip sdk
384
- } = options;
385
- if (this.isGroupAddress) {
386
- if (!suppressResponse) {
387
- throw new import_general.ImplementationError("Writing attributes on a group address can not return a response.");
388
- }
389
- if (attributes.some(
390
- ({ endpointId, clusterId, attribute }) => endpointId !== void 0 || clusterId === void 0 || attribute.id === void 0
391
- )) {
392
- throw new import_general.ImplementationError("Not all attribute write paths are valid for group address writes.");
393
- }
394
- }
395
- const writeRequests = attributes.flatMap(
396
- ({ endpointId, clusterId, attribute: { id, schema }, value, dataVersion }) => {
397
- if (chunkLists && Array.isArray(value) && schema instanceof import_types.ArraySchema && // As implemented for Matter 1.4.2 in https://github.com/project-chip/connectedhomeip/pull/38263
398
- // Acl writes will no longer be chunked by default, all others still
399
- // Will be streamlined later ... see https://github.com/project-chip/connectedhomeip/issues/38270
400
- !isAclOrExtensionPath({ clusterId, attributeId: id })) {
401
- return schema.encodeAsChunkedArray(value, { forWriteInteraction: true }).map(({ element: data, listIndex }) => ({
402
- path: { endpointId, clusterId, attributeId: id, listIndex },
403
- data,
404
- dataVersion
405
- }));
406
- }
407
- return [
408
- {
409
- path: { endpointId, clusterId, attributeId: id },
410
- data: schema.encodeTlv(value, { forWriteInteraction: true }),
411
- dataVersion
412
- }
413
- ];
414
- }
415
- );
416
- const timedRequest = attributes.some(({ attribute: { timed } }) => timed) || asTimedRequest === true || options.timedRequestTimeout !== void 0;
417
- if (this.isGroupAddress && timedRequest) {
418
- throw new import_general.ImplementationError("Timed requests are not supported for group address writes.");
419
- }
420
- const response = await this.withMessenger(
421
- async (messenger) => {
422
- if (timedRequest) {
423
- await messenger.sendTimedRequest(timedRequestTimeout);
424
- }
425
- logger.debug(() => [
426
- "Write",
427
- import_Mark.Mark.OUTBOUND,
428
- messenger.exchange.via,
429
- import_general.Diagnostic.dict({
430
- attributes: attributes.map(
431
- ({ endpointId, clusterId, attribute: { id }, value, dataVersion }) => `${(0, import_types.resolveAttributeName)({ endpointId, clusterId, attributeId: id })} = ${import_general.Diagnostic.json(
432
- value
433
- )} (version=${dataVersion})`
434
- ).join(", ")
435
- })
436
- ]);
437
- return await messenger.sendWriteCommand({
438
- suppressResponse,
439
- timedRequest,
440
- writeRequests,
441
- moreChunkedMessages: false,
442
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION
443
- });
444
- },
445
- executeQueued
446
- );
447
- if (response === void 0) {
448
- if (!suppressResponse) {
449
- throw new import_general.MatterFlowError(`No response received from write interaction but expected.`);
450
- }
451
- return [];
452
- }
453
- return response.writeResponses.flatMap(({ status: { status, clusterStatus }, path: { nodeId, endpointId, clusterId, attributeId } }) => {
454
- return {
455
- path: { nodeId, endpointId, clusterId, attributeId },
456
- status: status ?? clusterStatus ?? import_types.StatusCode.Failure
457
- };
458
- }).filter(({ status }) => status !== import_types.StatusCode.Success);
459
- }
460
- async subscribeAttribute(options) {
461
- if (this.isGroupAddress) {
462
- throw new import_general.ImplementationError("Subscribing to attributes on a group address is not supported.");
463
- }
464
- const {
465
- endpointId,
466
- clusterId,
467
- attribute,
468
- minIntervalFloorSeconds,
469
- maxIntervalCeilingSeconds,
470
- isFabricFiltered = true,
471
- listener,
472
- knownDataVersion,
473
- keepSubscriptions = true,
474
- updateTimeoutHandler,
475
- updateReceived,
476
- executeQueued
477
- } = options;
478
- const { id: attributeId } = attribute;
479
- if (!keepSubscriptions) {
480
- for (const subscriptionId2 of this.#ownSubscriptionIds) {
481
- logger.debug(
482
- `Removing subscription ${import_Subscription.Subscription.idStrOf(subscriptionId2)} from InteractionClient because new subscription replaces it`
483
- );
484
- this.removeSubscription(subscriptionId2);
485
- }
486
- }
487
- const request = {
488
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION,
489
- attributeRequests: [{ endpointId, clusterId, attributeId }],
490
- dataVersionFilters: knownDataVersion !== void 0 ? [{ path: { endpointId, clusterId }, dataVersion: knownDataVersion }] : void 0,
491
- keepSubscriptions,
492
- minIntervalFloorSeconds,
493
- maxIntervalCeilingSeconds,
494
- isFabricFiltered
495
- };
496
- const scope = (0, import_ReadScope.ReadScope)(request);
497
- const {
498
- subscribeResponse: { subscriptionId, maxInterval },
499
- report,
500
- maximumPeerResponseTime
501
- } = await this.withMessenger(async (messenger) => {
502
- logger.debug(() => [
503
- "Subscribe",
504
- import_Mark.Mark.OUTBOUND,
505
- messenger.exchange.via,
506
- import_general.Diagnostic.dict({
507
- attributes: (0, import_types.resolveAttributeName)({ endpointId, clusterId, attributeId }),
508
- dataVersionFilter: knownDataVersion,
509
- fabricFiltered: isFabricFiltered,
510
- minInterval: import_general.Duration.format((0, import_general.Seconds)(minIntervalFloorSeconds)),
511
- maxInterval: import_general.Duration.format((0, import_general.Seconds)(maxIntervalCeilingSeconds))
512
- })
513
- ]);
514
- await messenger.sendSubscribeRequest(request);
515
- const { subscribeResponse, report: report2 } = await messenger.readAggregateSubscribeResponse();
516
- return {
517
- subscribeResponse,
518
- report: report2,
519
- maximumPeerResponseTime: this.maximumPeerResponseTime()
520
- };
521
- }, executeQueued);
522
- const subscriptionListener = async (dataReport) => {
523
- const { attributeReports } = dataReport;
524
- if (attributeReports.length === 0) {
525
- throw new import_general.MatterFlowError("Subscription result reporting undefined/no value not specified");
526
- }
527
- if (attributeReports.length > 1) {
528
- throw new import_general.UnexpectedDataError("Unexpected response with more then one attribute");
529
- }
530
- const { value, version } = attributeReports[0];
531
- if (value === void 0)
532
- throw new import_general.MatterFlowError("Subscription result reporting undefined value not specified.");
533
- await this.#nodeStore?.persistAttributes(attributeReports, scope);
534
- listener?.(value, version);
535
- updateReceived?.();
536
- };
537
- await this.#registerSubscription(
538
- {
539
- id: subscriptionId,
540
- maximumPeerResponseTime,
541
- maxInterval: (0, import_general.Seconds)(maxInterval),
542
- onData: subscriptionListener,
543
- onTimeout: updateTimeoutHandler
544
- },
545
- report
546
- );
547
- return { maxInterval };
548
- }
549
- async #registerSubscription(subscription, initialReport) {
550
- this.#ownSubscriptionIds.add(subscription.id);
551
- this.#subscriptionClient?.add(subscription);
552
- await subscription.onData(initialReport);
553
- }
554
- async subscribeEvent(options) {
555
- if (this.isGroupAddress) {
556
- throw new import_general.ImplementationError("Subscribing to events on a group address is not supported.");
557
- }
558
- const {
559
- endpointId,
560
- clusterId,
561
- event,
562
- minIntervalFloor,
563
- maxIntervalCeiling,
564
- isUrgent,
565
- minimumEventNumber,
566
- isFabricFiltered = true,
567
- listener,
568
- updateTimeoutHandler,
569
- updateReceived,
570
- executeQueued
571
- } = options;
572
- const { id: eventId } = event;
573
- const {
574
- report,
575
- subscribeResponse: { subscriptionId, maxInterval },
576
- maximumPeerResponseTime
577
- } = await this.withMessenger(async (messenger) => {
578
- logger.debug(() => [
579
- "Subscribe",
580
- import_Mark.Mark.OUTBOUND,
581
- messenger.exchange.via,
582
- import_general.Diagnostic.dict({
583
- events: (0, import_types.resolveEventName)({ endpointId, clusterId, eventId }),
584
- fabricFiltered: isFabricFiltered,
585
- minInterval: import_general.Duration.format(minIntervalFloor),
586
- maxInterval: import_general.Duration.format(maxIntervalCeiling)
587
- })
588
- ]);
589
- await messenger.sendSubscribeRequest({
590
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION,
591
- eventRequests: [{ endpointId, clusterId, eventId, isUrgent }],
592
- eventFilters: minimumEventNumber !== void 0 ? [{ eventMin: minimumEventNumber }] : void 0,
593
- keepSubscriptions: true,
594
- minIntervalFloorSeconds: import_general.Seconds.of(minIntervalFloor),
595
- maxIntervalCeilingSeconds: import_general.Seconds.of(maxIntervalCeiling),
596
- isFabricFiltered
597
- });
598
- const { subscribeResponse, report: report2 } = await messenger.readAggregateSubscribeResponse();
599
- return {
600
- subscribeResponse,
601
- report: report2,
602
- maximumPeerResponseTime: this.maximumPeerResponseTime()
603
- };
604
- }, executeQueued);
605
- const subscriptionListener = (dataReport) => {
606
- const { eventReports } = dataReport;
607
- if (eventReports.length === 0) {
608
- throw new import_general.MatterFlowError("Received empty subscription result value.");
609
- }
610
- if (eventReports.length > 1) {
611
- throw new import_general.UnexpectedDataError("Unexpected response with more then one attribute.");
612
- }
613
- const { events } = eventReports[0];
614
- if (events === void 0)
615
- throw new import_general.MatterFlowError("Subscription result reporting undefined value not specified.");
616
- events.forEach((event2) => listener?.(event2));
617
- updateReceived?.();
618
- };
619
- await this.#registerSubscription(
620
- {
621
- id: subscriptionId,
622
- maximumPeerResponseTime,
623
- maxInterval: (0, import_general.Seconds)(maxInterval),
624
- onData: subscriptionListener,
625
- onTimeout: updateTimeoutHandler
626
- },
627
- report
628
- );
629
- return { maxInterval };
630
- }
631
- async subscribeAllAttributesAndEvents(options) {
632
- const { isUrgent } = options;
633
- return this.subscribeMultipleAttributesAndEvents({
634
- ...options,
635
- attributes: REQUEST_ALL,
636
- events: [{ isUrgent }]
637
- });
638
- }
639
- async subscribeMultipleAttributesAndEvents(options) {
640
- if (this.isGroupAddress) {
641
- throw new import_general.ImplementationError("Subscribing to attributes or events on a group address is not supported.");
642
- }
643
- const {
644
- attributes: attributeRequests = [],
645
- events: eventRequests = [],
646
- executeQueued,
647
- minIntervalFloorSeconds,
648
- maxIntervalCeilingSeconds,
649
- keepSubscriptions = true,
650
- isFabricFiltered = true,
651
- attributeListener,
652
- eventListener,
653
- eventFilters,
654
- dataVersionFilters,
655
- updateTimeoutHandler,
656
- updateReceived,
657
- enrichCachedAttributeData
658
- } = options;
659
- const subscriptionPathsCount = (attributeRequests?.length ?? 0) + (eventRequests?.length ?? 0);
660
- if (subscriptionPathsCount > 3) {
661
- logger.debug("Subscribe interactions with more then 3 paths might be not allowed by the device.");
662
- }
663
- if (!keepSubscriptions) {
664
- for (const subscriptionId2 of this.#ownSubscriptionIds) {
665
- logger.debug(
666
- `Removing subscription with ID ${import_Subscription.Subscription.idStrOf(subscriptionId2)} from InteractionClient because new subscription replaces it`
667
- );
668
- this.removeSubscription(subscriptionId2);
669
- }
670
- }
671
- const request = {
672
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION,
673
- attributeRequests,
674
- eventRequests,
675
- keepSubscriptions,
676
- minIntervalFloorSeconds,
677
- maxIntervalCeilingSeconds,
678
- isFabricFiltered,
679
- eventFilters,
680
- dataVersionFilters: dataVersionFilters?.map(({ endpointId, clusterId, dataVersion }) => ({
681
- path: { endpointId, clusterId },
682
- dataVersion
683
- }))
684
- };
685
- const scope = (0, import_ReadScope.ReadScope)(request);
686
- let processNewAttributeChangesInListener = false;
687
- const {
688
- report,
689
- subscribeResponse: { subscriptionId, maxInterval },
690
- maximumPeerResponseTime
691
- } = await this.withMessenger(async (messenger) => {
692
- logger.debug(() => [
693
- "Subscribe",
694
- import_Mark.Mark.OUTBOUND,
695
- messenger.exchange.via,
696
- import_general.Diagnostic.dict({
697
- attributes: attributeRequests.length ? attributeRequests.map((path) => (0, import_types.resolveAttributeName)(path)).join(", ") : void 0,
698
- events: eventRequests.length ? eventRequests.map((path) => (0, import_types.resolveEventName)(path)).join(", ") : void 0,
699
- dataVersionFilter: dataVersionFilters?.length ? dataVersionFilters.map(
700
- ({ endpointId, clusterId, dataVersion }) => `${endpointId}/${clusterId}=${dataVersion}`
701
- ).join(", ") : void 0,
702
- eventFilters: eventFilters?.length ? eventFilters.map(({ nodeId, eventMin }) => `${nodeId}=${eventMin}`).join(", ") : void 0,
703
- fabricFiltered: isFabricFiltered,
704
- keepSubscriptions,
705
- minInterval: import_general.Duration.format((0, import_general.Seconds)(minIntervalFloorSeconds)),
706
- maxInterval: import_general.Duration.format((0, import_general.Seconds)(maxIntervalCeilingSeconds))
707
- })
708
- ]);
709
- await messenger.sendSubscribeRequest(request);
710
- const { subscribeResponse, report: report2 } = await messenger.readAggregateSubscribeResponse(
711
- (attributeReports) => this.processAttributeUpdates(scope, attributeReports, attributeListener)
712
- );
713
- logger.info(
714
- "Subscription successful",
715
- import_Mark.Mark.INBOUND,
716
- messenger.exchange.via,
717
- import_general.Diagnostic.dict({
718
- ...import_Subscription.Subscription.diagnosticOf(subscribeResponse.subscriptionId),
719
- maxInterval: import_general.Duration.format((0, import_general.Seconds)(subscribeResponse.maxInterval))
720
- })
721
- );
722
- return {
723
- subscribeResponse,
724
- report: report2,
725
- maximumPeerResponseTime: this.maximumPeerResponseTime()
726
- };
727
- }, executeQueued);
728
- const subscriptionListener = async (dataReport) => {
729
- if ((!Array.isArray(dataReport.attributeReports) || !dataReport.attributeReports.length) && (!Array.isArray(dataReport.eventReports) || !dataReport.eventReports.length)) {
730
- updateReceived?.();
731
- return;
732
- }
733
- const { attributeReports, eventReports } = dataReport;
734
- if (eventReports?.length) {
735
- let maxEventNumber = this.#nodeStore?.maxEventNumber ?? eventReports[0].events[0].eventNumber;
736
- eventReports.forEach((data) => {
737
- logger.debug(
738
- `Event update ${import_Mark.Mark.INBOUND} ${(0, import_types.resolveEventName)(data.path)}: ${import_general.Diagnostic.json(data.events)}`
739
- );
740
- const { events } = data;
741
- maxEventNumber = events.length === 1 ? events[0].eventNumber : events.reduce(
742
- (max, { eventNumber }) => max < eventNumber ? eventNumber : max,
743
- maxEventNumber
744
- );
745
- eventListener?.(data);
746
- });
747
- await this.#nodeStore?.updateLastEventNumber(maxEventNumber);
748
- }
749
- if (processNewAttributeChangesInListener && attributeReports !== void 0) {
750
- await this.processAttributeUpdates(scope, attributeReports, attributeListener);
751
- }
752
- updateReceived?.();
753
- };
754
- await this.#registerSubscription(
755
- {
756
- id: subscriptionId,
757
- maximumPeerResponseTime,
758
- maxInterval: (0, import_general.Seconds)(maxInterval),
759
- onData: (dataReport) => subscriptionListener(dataReport),
760
- onTimeout: updateTimeoutHandler
761
- },
762
- report
763
- );
764
- processNewAttributeChangesInListener = true;
765
- if (dataVersionFilters !== void 0 && dataVersionFilters.length > 0 && enrichCachedAttributeData) {
766
- this.#enrichCachedAttributeData(report.attributeReports, dataVersionFilters);
767
- }
768
- return {
769
- ...report,
770
- maxInterval
771
- };
772
- }
773
- /**
774
- * Process changed attributes, detect changes and persist them to the node store
775
- */
776
- async processAttributeUpdates(scope, attributeReports, attributeListener) {
777
- for (const data of attributeReports) {
778
- const {
779
- path: { endpointId, clusterId, attributeId },
780
- value,
781
- version
782
- } = data;
783
- if (value === void 0) {
784
- throw new import_general.MatterFlowError("Received empty subscription result value.");
785
- }
786
- const { value: oldValue, version: oldVersion } = this.#nodeStore?.retrieveAttribute(endpointId, clusterId, attributeId) ?? {};
787
- const changed = oldValue !== void 0 ? !(0, import_general.isDeepEqual)(oldValue, value) : void 0;
788
- if (changed !== false || version !== oldVersion) {
789
- await this.#nodeStore?.persistAttributes([data], scope);
790
- }
791
- logger.debug(
792
- `Attribute update ${import_Mark.Mark.INBOUND}${changed ? " (value changed)" : ""}: ${(0, import_types.resolveAttributeName)({
793
- endpointId,
794
- clusterId,
795
- attributeId
796
- })} = ${(0, import_general.serialize)(value)} (version=${version})`
797
- );
798
- attributeListener?.(data, changed, oldValue);
799
- }
800
- }
801
- async invoke(options) {
802
- const { executeQueued } = options;
803
- const {
804
- endpointId,
805
- clusterId,
806
- command: { requestId, requestSchema, responseId, responseSchema, optional, timed },
807
- asTimedRequest,
808
- timedRequestTimeout: timedRequestTimeoutMs = DEFAULT_TIMED_REQUEST_TIMEOUT,
809
- expectedProcessingTime,
810
- useExtendedFailSafeMessageResponseTimeout = false,
811
- skipValidation
812
- } = options;
813
- let { request } = options;
814
- const timedRequest = timed && !skipValidation || asTimedRequest === true || options.timedRequestTimeout !== void 0;
815
- if (this.isGroupAddress) {
816
- if (endpointId !== void 0) {
817
- throw new import_general.ImplementationError("Invoking a concrete command on a group address is not supported.");
818
- }
819
- if (timedRequest) {
820
- throw new import_general.ImplementationError("Timed requests are not supported for group address invokes.");
821
- }
822
- }
823
- if (requestSchema instanceof import_types.ObjectSchema) {
824
- if (request === void 0) {
825
- request = {};
826
- }
827
- if (requestSchema.isFabricScoped && request.fabricIndex === void 0) {
828
- request.fabricIndex = import_types.FabricIndex.NO_FABRIC;
829
- }
830
- }
831
- logger.debug(
832
- `Invoking command: ${(0, import_types.resolveCommandName)({
833
- endpointId,
834
- clusterId,
835
- commandId: requestId
836
- })} with ${import_general.Diagnostic.json(request)}`
837
- );
838
- if (!skipValidation) {
839
- requestSchema.validate(request);
840
- }
841
- const commandFields = requestSchema.encodeTlv(request);
842
- const invokeResponse = await this.withMessenger(async (messenger) => {
843
- if (timedRequest) {
844
- await messenger.sendTimedRequest(timedRequestTimeoutMs);
845
- }
846
- const response = await messenger.sendInvokeCommand(
847
- {
848
- invokeRequests: [{ commandPath: { endpointId, clusterId, commandId: requestId }, commandFields }],
849
- timedRequest,
850
- suppressResponse: false,
851
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION
852
- },
853
- expectedProcessingTime ?? (useExtendedFailSafeMessageResponseTimeout ? DEFAULT_MINIMUM_RESPONSE_TIMEOUT_WITH_FAILSAFE : void 0)
854
- );
855
- if (response === void 0) {
856
- throw new import_general.MatterFlowError("No response received from invoke interaction but expected.");
857
- }
858
- return response;
859
- }, executeQueued);
860
- const { invokeResponses } = invokeResponse;
861
- if (invokeResponses.length === 0) {
862
- throw new import_general.MatterFlowError("Received invoke response with no invoke results.");
863
- }
864
- const { command, status } = invokeResponses[0];
865
- if (status !== void 0) {
866
- const resultCode = status.status.status;
867
- if (resultCode !== import_types.StatusCode.Success)
868
- throw new import_types.StatusResponseError(
869
- `Received non-success result: ${resultCode}`,
870
- resultCode ?? import_types.StatusCode.Failure,
871
- status.status.clusterStatus
872
- );
873
- if (responseSchema !== import_types.TlvNoResponse)
874
- throw new import_general.MatterFlowError("A response was expected for this command.");
875
- return void 0;
876
- }
877
- if (command !== void 0) {
878
- const {
879
- commandPath: { commandId },
880
- commandFields: commandFields2
881
- } = command;
882
- if (commandId !== responseId) {
883
- throw new import_general.MatterFlowError(
884
- `Received invoke response with unexpected command ID ${commandId}, expected ${responseId}.`
885
- );
886
- }
887
- if (commandFields2 === void 0) {
888
- if (responseSchema !== import_types.TlvNoResponse)
889
- throw new import_general.MatterFlowError(`A response was expected for command ${requestId}.`);
890
- return void 0;
891
- }
892
- const response = responseSchema.decodeTlv(commandFields2);
893
- logger.debug(
894
- "Invoke",
895
- import_Mark.Mark.INBOUND,
896
- (0, import_types.resolveCommandName)({
897
- endpointId,
898
- clusterId,
899
- commandId: requestId
900
- }),
901
- "with",
902
- import_general.Diagnostic.json(response)
903
- );
904
- return response;
905
- }
906
- if (optional) {
907
- return void 0;
908
- }
909
- throw new import_general.MatterFlowError("Received invoke response with no result nor response.");
910
- }
911
- // TODO Add to ClusterClient when needed/when Group communication is implemented
912
- // TODO Additionally support it without endpoint
913
- async invokeWithSuppressedResponse(options) {
914
- const { executeQueued } = options;
915
- const {
916
- endpointId,
917
- clusterId,
918
- request,
919
- command: { requestId, requestSchema, timed },
920
- asTimedRequest,
921
- timedRequestTimeout = DEFAULT_TIMED_REQUEST_TIMEOUT
922
- } = options;
923
- const timedRequest = timed || asTimedRequest === true || options.timedRequestTimeout !== void 0;
924
- if (this.isGroupAddress) {
925
- if (timed) {
926
- throw new import_general.ImplementationError("Timed requests are not supported for group address invokes.");
927
- }
928
- if (endpointId !== void 0) {
929
- throw new import_general.ImplementationError("Invoking a concrete command on a group address is not supported.");
930
- }
931
- }
932
- logger.debug(
933
- `Invoking command with suppressedResponse: ${(0, import_types.resolveCommandName)({
934
- endpointId,
935
- clusterId,
936
- commandId: requestId
937
- })} with ${import_general.Diagnostic.json(request)}`
938
- );
939
- const commandFields = requestSchema.encodeTlv(request);
940
- await this.withMessenger(async (messenger) => {
941
- if (timedRequest) {
942
- await messenger.sendTimedRequest(timedRequestTimeout);
943
- }
944
- const response = await messenger.sendInvokeCommand({
945
- invokeRequests: [{ commandPath: { endpointId, clusterId, commandId: requestId }, commandFields }],
946
- timedRequest,
947
- suppressResponse: true,
948
- interactionModelRevision: import_model.Specification.INTERACTION_MODEL_REVISION
949
- });
950
- if (response !== void 0) {
951
- throw new import_general.MatterFlowError(
952
- "Response received from invoke interaction but none expected because response is suppressed."
953
- );
954
- }
955
- }, executeQueued);
956
- logger.debug(
957
- "Invoke successful",
958
- import_Mark.Mark.INBOUND,
959
- (0, import_types.resolveCommandName)({
960
- endpointId,
961
- clusterId,
962
- commandId: requestId
963
- })
964
- );
965
- }
966
- async withMessenger(invoke, executeQueued = false) {
967
- const messenger = await import_InteractionMessenger.InteractionClientMessenger.create(this.#exchangeProvider);
968
- let result;
969
- try {
970
- if (executeQueued) {
971
- if (this.#queue === void 0) {
972
- throw new import_general.ImplementationError("Cannot execute queued operation without a queue.");
973
- }
974
- return await this.#queue.add(() => invoke(messenger));
975
- }
976
- result = await invoke(messenger);
977
- } finally {
978
- messenger.close().catch((error) => logger.info(`Error closing messenger: ${error}`));
979
- }
980
- return result;
981
- }
982
- removeAllSubscriptions() {
983
- for (const subscriptionId of this.#ownSubscriptionIds) {
984
- this.removeSubscription(subscriptionId);
985
- }
986
- }
987
- close() {
988
- this.removeAllSubscriptions();
989
- }
990
- get session() {
991
- return this.#exchangeProvider.session;
992
- }
993
- get channelType() {
994
- return this.#exchangeProvider.channelType;
995
- }
996
- /** Enrich cached data to get complete responses when data version filters were used. */
997
- #enrichCachedAttributeData(attributeReports, dataVersionFilters) {
998
- if (this.#nodeStore === void 0) {
999
- return;
1000
- }
1001
- const candidates = /* @__PURE__ */ new Map();
1002
- for (const { endpointId, clusterId, dataVersion } of dataVersionFilters) {
1003
- if (!candidates.has(endpointId)) {
1004
- candidates.set(endpointId, /* @__PURE__ */ new Map());
1005
- }
1006
- candidates.get(endpointId)?.set(clusterId, this.#nodeStore.getClusterDataVersion(endpointId, clusterId) ?? dataVersion);
1007
- }
1008
- attributeReports.forEach(({ path: { endpointId, clusterId } }) => {
1009
- if (candidates.has(endpointId)) {
1010
- candidates.get(endpointId)?.delete(clusterId);
1011
- }
1012
- });
1013
- for (const [endpointId, clusters] of candidates) {
1014
- for (const [clusterId, version] of clusters) {
1015
- const clusterValues = this.#nodeStore.retrieveAttributes(endpointId, clusterId);
1016
- logger.debug(
1017
- `Enriching cached data (${clusterValues.length} attributes) for ${endpointId}/${clusterId} with version=${version}`
1018
- );
1019
- attributeReports.push(...clusterValues);
1020
- }
1021
- }
1022
- }
1023
- /**
1024
- * Returns the list (optionally filtered by endpointId and/or clusterId) of the dataVersions of the currently cached
1025
- * values to use them as knownDataVersion for read or subscription requests.
1026
- */
1027
- getCachedClusterDataVersions(filter) {
1028
- if (this.#nodeStore === void 0) {
1029
- return [];
1030
- }
1031
- const { endpointId, clusterId } = filter ?? {};
1032
- return this.#nodeStore.getClusterDataVersions(endpointId, clusterId);
1033
- }
1034
- get maxKnownEventNumber() {
1035
- return this.#nodeStore?.maxEventNumber;
1036
- }
1037
- cleanupAttributeData(endpointId, clusterIds) {
1038
- return this.#nodeStore?.cleanupAttributeData(endpointId, clusterIds);
1039
- }
1040
- getAllCachedClusterData() {
1041
- const result = new Array();
1042
- this.#enrichCachedAttributeData(result, this.getCachedClusterDataVersions());
1043
- return result;
1044
- }
1045
- }
1046
- //# sourceMappingURL=InteractionClient.js.map