zwave-js 11.0.0 → 11.2.0

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 (158) hide show
  1. package/build/lib/controller/Controller.d.ts +86 -3
  2. package/build/lib/controller/Controller.d.ts.map +1 -1
  3. package/build/lib/controller/Controller.js +391 -164
  4. package/build/lib/controller/Controller.js.map +1 -1
  5. package/build/lib/controller/Features.js +1 -1
  6. package/build/lib/controller/Features.js.map +1 -1
  7. package/build/lib/controller/Inclusion.js +6 -6
  8. package/build/lib/controller/Inclusion.js.map +1 -1
  9. package/build/lib/controller/MockControllerBehaviors.d.ts.map +1 -1
  10. package/build/lib/controller/MockControllerBehaviors.js +3 -2
  11. package/build/lib/controller/MockControllerBehaviors.js.map +1 -1
  12. package/build/lib/controller/MockControllerState.js +2 -2
  13. package/build/lib/controller/MockControllerState.js.map +1 -1
  14. package/build/lib/controller/NodeInformationFrame.d.ts.map +1 -1
  15. package/build/lib/controller/NodeInformationFrame.js +6 -1
  16. package/build/lib/controller/NodeInformationFrame.js.map +1 -1
  17. package/build/lib/controller/ZWaveSDKVersions.js +1 -1
  18. package/build/lib/controller/ZWaveSDKVersions.js.map +1 -1
  19. package/build/lib/controller/_Types.js +1 -1
  20. package/build/lib/controller/_Types.js.map +1 -1
  21. package/build/lib/driver/Bootloader.js +1 -1
  22. package/build/lib/driver/Bootloader.js.map +1 -1
  23. package/build/lib/driver/Driver.d.ts +44 -12
  24. package/build/lib/driver/Driver.d.ts.map +1 -1
  25. package/build/lib/driver/Driver.js +495 -207
  26. package/build/lib/driver/Driver.js.map +1 -1
  27. package/build/lib/driver/MessageGenerators.d.ts.map +1 -1
  28. package/build/lib/driver/MessageGenerators.js +4 -11
  29. package/build/lib/driver/MessageGenerators.js.map +1 -1
  30. package/build/lib/driver/NetworkCache.d.ts +5 -0
  31. package/build/lib/driver/NetworkCache.d.ts.map +1 -1
  32. package/build/lib/driver/NetworkCache.js +5 -0
  33. package/build/lib/driver/NetworkCache.js.map +1 -1
  34. package/build/lib/driver/SerialAPICommandMachine.d.ts +17 -11
  35. package/build/lib/driver/SerialAPICommandMachine.d.ts.map +1 -1
  36. package/build/lib/driver/SerialAPICommandMachine.js +16 -6
  37. package/build/lib/driver/SerialAPICommandMachine.js.map +1 -1
  38. package/build/lib/driver/StateMachineShared.d.ts +27 -52
  39. package/build/lib/driver/StateMachineShared.d.ts.map +1 -1
  40. package/build/lib/driver/StateMachineShared.js +16 -48
  41. package/build/lib/driver/StateMachineShared.js.map +1 -1
  42. package/build/lib/node/Node.d.ts +11 -0
  43. package/build/lib/node/Node.d.ts.map +1 -1
  44. package/build/lib/node/Node.js +223 -8
  45. package/build/lib/node/Node.js.map +1 -1
  46. package/build/lib/node/NodeReadyMachine.d.ts +2 -2
  47. package/build/lib/node/NodeReadyMachine.d.ts.map +1 -1
  48. package/build/lib/node/NodeReadyMachine.js.map +1 -1
  49. package/build/lib/node/NodeStatusMachine.d.ts +2 -2
  50. package/build/lib/node/NodeStatusMachine.d.ts.map +1 -1
  51. package/build/lib/node/NodeStatusMachine.js.map +1 -1
  52. package/build/lib/serialapi/_Types.js +1 -1
  53. package/build/lib/serialapi/_Types.js.map +1 -1
  54. package/build/lib/serialapi/application/ApplicationCommandRequest.js +3 -4
  55. package/build/lib/serialapi/application/ApplicationCommandRequest.js.map +1 -1
  56. package/build/lib/serialapi/application/ApplicationUpdateRequest.js +13 -21
  57. package/build/lib/serialapi/application/ApplicationUpdateRequest.js.map +1 -1
  58. package/build/lib/serialapi/application/BridgeApplicationCommandRequest.js +2 -3
  59. package/build/lib/serialapi/application/BridgeApplicationCommandRequest.js.map +1 -1
  60. package/build/lib/serialapi/application/SerialAPIStartedRequest.js +3 -4
  61. package/build/lib/serialapi/application/SerialAPIStartedRequest.js.map +1 -1
  62. package/build/lib/serialapi/application/ShutdownMessages.js +4 -6
  63. package/build/lib/serialapi/application/ShutdownMessages.js.map +1 -1
  64. package/build/lib/serialapi/capability/GetControllerCapabilitiesMessages.js +4 -6
  65. package/build/lib/serialapi/capability/GetControllerCapabilitiesMessages.js.map +1 -1
  66. package/build/lib/serialapi/capability/GetControllerVersionMessages.js +4 -6
  67. package/build/lib/serialapi/capability/GetControllerVersionMessages.js.map +1 -1
  68. package/build/lib/serialapi/capability/GetProtocolVersionMessages.js +4 -6
  69. package/build/lib/serialapi/capability/GetProtocolVersionMessages.js.map +1 -1
  70. package/build/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.js +4 -6
  71. package/build/lib/serialapi/capability/GetSerialApiCapabilitiesMessages.js.map +1 -1
  72. package/build/lib/serialapi/capability/GetSerialApiInitDataMessages.js +4 -6
  73. package/build/lib/serialapi/capability/GetSerialApiInitDataMessages.js.map +1 -1
  74. package/build/lib/serialapi/capability/HardResetRequest.js +4 -6
  75. package/build/lib/serialapi/capability/HardResetRequest.js.map +1 -1
  76. package/build/lib/serialapi/capability/SerialAPISetupMessages.js +59 -88
  77. package/build/lib/serialapi/capability/SerialAPISetupMessages.js.map +1 -1
  78. package/build/lib/serialapi/capability/SetApplicationNodeInformationRequest.js +2 -3
  79. package/build/lib/serialapi/capability/SetApplicationNodeInformationRequest.js.map +1 -1
  80. package/build/lib/serialapi/memory/GetControllerIdMessages.js +4 -6
  81. package/build/lib/serialapi/memory/GetControllerIdMessages.js.map +1 -1
  82. package/build/lib/serialapi/misc/GetBackgroundRSSIMessages.js +4 -6
  83. package/build/lib/serialapi/misc/GetBackgroundRSSIMessages.js.map +1 -1
  84. package/build/lib/serialapi/misc/SetRFReceiveModeMessages.js +4 -6
  85. package/build/lib/serialapi/misc/SetRFReceiveModeMessages.js.map +1 -1
  86. package/build/lib/serialapi/misc/SetSerialApiTimeoutsMessages.js +4 -6
  87. package/build/lib/serialapi/misc/SetSerialApiTimeoutsMessages.js.map +1 -1
  88. package/build/lib/serialapi/misc/SoftResetRequest.js +2 -3
  89. package/build/lib/serialapi/misc/SoftResetRequest.js.map +1 -1
  90. package/build/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.js +6 -8
  91. package/build/lib/serialapi/network-mgmt/AddNodeToNetworkRequest.js.map +1 -1
  92. package/build/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.js +6 -9
  93. package/build/lib/serialapi/network-mgmt/AssignPriorityReturnRouteMessages.js.map +1 -1
  94. package/build/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.js +6 -9
  95. package/build/lib/serialapi/network-mgmt/AssignPrioritySUCReturnRouteMessages.js.map +1 -1
  96. package/build/lib/serialapi/network-mgmt/AssignReturnRouteMessages.js +6 -9
  97. package/build/lib/serialapi/network-mgmt/AssignReturnRouteMessages.js.map +1 -1
  98. package/build/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.js +6 -9
  99. package/build/lib/serialapi/network-mgmt/AssignSUCReturnRouteMessages.js.map +1 -1
  100. package/build/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.js +6 -9
  101. package/build/lib/serialapi/network-mgmt/DeleteReturnRouteMessages.js.map +1 -1
  102. package/build/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.js +6 -9
  103. package/build/lib/serialapi/network-mgmt/DeleteSUCReturnRouteMessages.js.map +1 -1
  104. package/build/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.js +4 -6
  105. package/build/lib/serialapi/network-mgmt/GetNodeProtocolInfoMessages.js.map +1 -1
  106. package/build/lib/serialapi/network-mgmt/GetPriorityRouteMessages.js +4 -6
  107. package/build/lib/serialapi/network-mgmt/GetPriorityRouteMessages.js.map +1 -1
  108. package/build/lib/serialapi/network-mgmt/GetRoutingInfoMessages.js +4 -6
  109. package/build/lib/serialapi/network-mgmt/GetRoutingInfoMessages.js.map +1 -1
  110. package/build/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.js +4 -6
  111. package/build/lib/serialapi/network-mgmt/GetSUCNodeIdMessages.js.map +1 -1
  112. package/build/lib/serialapi/network-mgmt/IsFailedNodeMessages.js +4 -6
  113. package/build/lib/serialapi/network-mgmt/IsFailedNodeMessages.js.map +1 -1
  114. package/build/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.js +8 -11
  115. package/build/lib/serialapi/network-mgmt/RemoveFailedNodeMessages.js.map +1 -1
  116. package/build/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.js +6 -8
  117. package/build/lib/serialapi/network-mgmt/RemoveNodeFromNetworkRequest.js.map +1 -1
  118. package/build/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.js +8 -11
  119. package/build/lib/serialapi/network-mgmt/ReplaceFailedNodeRequest.js.map +1 -1
  120. package/build/lib/serialapi/network-mgmt/RequestNodeInfoMessages.js +4 -6
  121. package/build/lib/serialapi/network-mgmt/RequestNodeInfoMessages.js.map +1 -1
  122. package/build/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.js +5 -7
  123. package/build/lib/serialapi/network-mgmt/RequestNodeNeighborUpdateMessages.js.map +1 -1
  124. package/build/lib/serialapi/network-mgmt/SetPriorityRouteMessages.js +4 -6
  125. package/build/lib/serialapi/network-mgmt/SetPriorityRouteMessages.js.map +1 -1
  126. package/build/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.js +7 -10
  127. package/build/lib/serialapi/network-mgmt/SetSUCNodeIDMessages.js.map +1 -1
  128. package/build/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.js +4 -6
  129. package/build/lib/serialapi/nvm/ExtNVMReadLongBufferMessages.js.map +1 -1
  130. package/build/lib/serialapi/nvm/ExtNVMReadLongByteMessages.js +4 -6
  131. package/build/lib/serialapi/nvm/ExtNVMReadLongByteMessages.js.map +1 -1
  132. package/build/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.js +4 -6
  133. package/build/lib/serialapi/nvm/ExtNVMWriteLongBufferMessages.js.map +1 -1
  134. package/build/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.js +4 -6
  135. package/build/lib/serialapi/nvm/ExtNVMWriteLongByteMessages.js.map +1 -1
  136. package/build/lib/serialapi/nvm/FirmwareUpdateNVMMessages.js +29 -43
  137. package/build/lib/serialapi/nvm/FirmwareUpdateNVMMessages.js.map +1 -1
  138. package/build/lib/serialapi/nvm/GetNVMIdMessages.js +6 -8
  139. package/build/lib/serialapi/nvm/GetNVMIdMessages.js.map +1 -1
  140. package/build/lib/serialapi/nvm/NVMOperationsMessages.js +6 -8
  141. package/build/lib/serialapi/nvm/NVMOperationsMessages.js.map +1 -1
  142. package/build/lib/serialapi/transport/SendDataBridgeMessages.js +12 -18
  143. package/build/lib/serialapi/transport/SendDataBridgeMessages.js.map +1 -1
  144. package/build/lib/serialapi/transport/SendDataMessages.js +14 -21
  145. package/build/lib/serialapi/transport/SendDataMessages.js.map +1 -1
  146. package/package.json +17 -16
  147. package/build/lib/driver/CommandQueueMachine.d.ts +0 -60
  148. package/build/lib/driver/CommandQueueMachine.d.ts.map +0 -1
  149. package/build/lib/driver/CommandQueueMachine.js +0 -259
  150. package/build/lib/driver/CommandQueueMachine.js.map +0 -1
  151. package/build/lib/driver/SendThreadMachine.d.ts +0 -97
  152. package/build/lib/driver/SendThreadMachine.d.ts.map +0 -1
  153. package/build/lib/driver/SendThreadMachine.js +0 -286
  154. package/build/lib/driver/SendThreadMachine.js.map +0 -1
  155. package/build/lib/driver/TransactionMachine.d.ts +0 -30
  156. package/build/lib/driver/TransactionMachine.d.ts.map +0 -1
  157. package/build/lib/driver/TransactionMachine.js +0 -250
  158. package/build/lib/driver/TransactionMachine.js.map +0 -1
@@ -1,259 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCommandQueueMachine = void 0;
4
- const shared_1 = require("@zwave-js/shared");
5
- const sorted_list_1 = require("alcalzone-shared/sorted-list");
6
- const xstate_1 = require("xstate");
7
- const actions_1 = require("xstate/lib/actions");
8
- const SendDataShared_1 = require("../serialapi/transport/SendDataShared");
9
- const SerialAPICommandMachine_1 = require("./SerialAPICommandMachine");
10
- const StateMachineShared_1 = require("./StateMachineShared");
11
- const setCurrentTransaction = (0, xstate_1.assign)((ctx) => ({
12
- ...ctx,
13
- currentTransaction: ctx.queue.shift(),
14
- }));
15
- const deleteCurrentTransaction = (0, xstate_1.assign)((ctx) => {
16
- ctx.callbackIDs.delete(ctx.currentTransaction);
17
- return {
18
- ...ctx,
19
- currentTransaction: undefined,
20
- };
21
- });
22
- const stopTransaction = (0, actions_1.sendParent)((ctx, evt) => ({
23
- type: "forward",
24
- from: "QUEUE",
25
- to: ctx.callbackIDs.get(evt.transaction),
26
- payload: {
27
- type: "stop",
28
- },
29
- }));
30
- const removeFromQueue = (0, xstate_1.assign)((ctx, evt) => {
31
- ctx.queue.remove(evt.transaction);
32
- ctx.callbackIDs.delete(evt.transaction);
33
- return ctx;
34
- });
35
- const stopAbortMachine = (0, actions_1.pure)((ctx) => {
36
- const ret = [];
37
- if (ctx.abortActor) {
38
- ret.push((0, actions_1.stop)(ctx.abortActor.id));
39
- }
40
- ret.push((0, xstate_1.assign)({ abortActor: (_) => undefined }));
41
- return ret;
42
- });
43
- const notifyResult = (0, actions_1.sendParent)((ctx, evt) => ({
44
- type: "forward",
45
- from: "QUEUE",
46
- to: ctx.callbackIDs.get(ctx.currentTransaction),
47
- payload: {
48
- ...evt.data,
49
- type: evt.data.type === "success" ? "command_success" : "command_failure",
50
- },
51
- }));
52
- const notifyError = (0, actions_1.sendParent)((ctx, evt) => ({
53
- type: "forward",
54
- from: "QUEUE",
55
- to: ctx.callbackIDs.get(ctx.currentTransaction),
56
- payload: {
57
- type: "command_error",
58
- error: evt.data,
59
- transaction: ctx.currentTransaction,
60
- },
61
- }));
62
- function createCommandQueueMachine(implementations, params) {
63
- const spawnAbortMachine = (0, xstate_1.assign)({
64
- abortActor: (_) => (0, xstate_1.spawn)((0, SerialAPICommandMachine_1.createSerialAPICommandMachine)(implementations.createSendDataAbort(), implementations, params)),
65
- });
66
- return (0, xstate_1.Machine)({
67
- preserveActionOrder: true,
68
- id: "CommandQueue",
69
- initial: "idle",
70
- context: {
71
- queue: new sorted_list_1.SortedList(),
72
- callbackIDs: new WeakMap(),
73
- // currentTransaction: undefined,
74
- },
75
- on: {
76
- add: {
77
- actions: [
78
- (0, xstate_1.assign)((ctx, evt) => {
79
- ctx.queue.add(evt.transaction);
80
- ctx.callbackIDs.set(evt.transaction, evt.from);
81
- return ctx;
82
- }),
83
- (0, actions_1.raise)("trigger"),
84
- ],
85
- },
86
- // What to do when removing transactions depends on their state
87
- remove: [
88
- // Abort ongoing SendData commands when the transaction is removed. The transaction machine will
89
- // stop on its own
90
- {
91
- cond: "isCurrentTransactionAndSendData",
92
- actions: [spawnAbortMachine, stopTransaction],
93
- },
94
- // If the transaction to remove is the current transaction, but not SendData
95
- // we can't just end it because it would risk putting the driver and stick out of sync
96
- {
97
- cond: "isNotCurrentTransaction",
98
- actions: [stopTransaction, removeFromQueue],
99
- },
100
- ],
101
- // Then a serial API machine is active, forward the message. Otherwise, return all messages as unsolicited.
102
- message: [
103
- {
104
- cond: "isExecuting",
105
- actions: (0, actions_1.forwardTo)("execute"),
106
- },
107
- { actions: StateMachineShared_1.notifyUnsolicited },
108
- ],
109
- unsolicited: [
110
- // The Serial API has determined this message to be unsolicited
111
- // Forward it to the SendThreadMachine
112
- { actions: StateMachineShared_1.notifyUnsolicited },
113
- ],
114
- // Forward low-level messages to the correct actor
115
- ACK: [
116
- {
117
- cond: "isAbortingInFlight",
118
- actions: (0, actions_1.forwardTo)((ctx) => ctx.abortActor),
119
- },
120
- {
121
- cond: "isAbortingWithTimeout",
122
- actions: (0, actions_1.forwardTo)("executeSendDataAbort"),
123
- },
124
- {
125
- cond: "isExecuting",
126
- actions: (0, actions_1.forwardTo)("execute"),
127
- },
128
- ],
129
- CAN: [
130
- {
131
- cond: "isAbortingInFlight",
132
- actions: (0, actions_1.forwardTo)((ctx) => ctx.abortActor),
133
- },
134
- {
135
- cond: "isAbortingWithTimeout",
136
- actions: (0, actions_1.forwardTo)("executeSendDataAbort"),
137
- },
138
- {
139
- cond: "isExecuting",
140
- actions: (0, actions_1.forwardTo)("execute"),
141
- },
142
- ],
143
- NAK: [
144
- {
145
- cond: "isAbortingInFlight",
146
- actions: (0, actions_1.forwardTo)((ctx) => ctx.abortActor),
147
- },
148
- {
149
- cond: "isAbortingWithTimeout",
150
- actions: (0, actions_1.forwardTo)("executeSendDataAbort"),
151
- },
152
- {
153
- cond: "isExecuting",
154
- actions: (0, actions_1.forwardTo)("execute"),
155
- },
156
- ],
157
- },
158
- states: {
159
- idle: {
160
- entry: deleteCurrentTransaction,
161
- on: {
162
- trigger: "idle",
163
- },
164
- always: {
165
- target: "execute",
166
- actions: setCurrentTransaction,
167
- cond: "queueNotEmpty",
168
- },
169
- },
170
- execute: {
171
- invoke: {
172
- id: "execute",
173
- src: "executeSerialAPICommand",
174
- onDone: [
175
- // If the transition was aborted in flight, just silently ignore
176
- // the result. The transaction was meant to be dropped or will be
177
- // rejected anyways.
178
- {
179
- cond: "isAbortingInFlight",
180
- target: "executeDone",
181
- },
182
- // On success, forward the response to our parent machine
183
- {
184
- cond: "executeSuccessful",
185
- actions: notifyResult,
186
- target: "executeDone",
187
- },
188
- // On failure, abort timed out send attempts
189
- {
190
- cond: "isSendDataWithCallbackTimeout",
191
- target: "abortSendData",
192
- actions: notifyResult,
193
- },
194
- // And just notify the parent about other failures
195
- {
196
- target: "executeDone",
197
- actions: notifyResult,
198
- },
199
- ],
200
- onError: {
201
- target: "executeDone",
202
- actions: notifyError,
203
- },
204
- },
205
- },
206
- abortSendData: {
207
- invoke: {
208
- id: "executeSendDataAbort",
209
- src: "executeSendDataAbort",
210
- onDone: "executeDone",
211
- },
212
- },
213
- executeDone: {
214
- always: {
215
- target: "idle",
216
- actions: [
217
- // Delete the current transaction after we're done
218
- deleteCurrentTransaction,
219
- stopAbortMachine,
220
- ],
221
- },
222
- },
223
- },
224
- }, {
225
- services: {
226
- executeSerialAPICommand: (ctx) => {
227
- try {
228
- return (0, SerialAPICommandMachine_1.createSerialAPICommandMachine)(ctx.currentTransaction.parts.current, implementations, params);
229
- }
230
- catch (e) {
231
- // If there is an error while creating the command machine (e.g. during message serialization)
232
- // wrap it in a rejected promise, so xstate can handle it
233
- implementations.log(`Unexpected error during SerialAPI command: ${(0, shared_1.getErrorMessage)(e, true)}`, "error");
234
- return Promise.reject(e);
235
- }
236
- },
237
- executeSendDataAbort: (_) => (0, SerialAPICommandMachine_1.createSerialAPICommandMachine)(implementations.createSendDataAbort(), implementations, params),
238
- },
239
- guards: {
240
- executeSuccessful: (_, evt) => evt.data?.type === "success",
241
- queueNotEmpty: (ctx) => ctx.queue.length > 0,
242
- isNotCurrentTransaction: (ctx, evt) => ctx.currentTransaction !== evt.transaction,
243
- isCurrentTransactionAndSendData: (ctx, evt) => ctx.currentTransaction === evt.transaction &&
244
- (0, SendDataShared_1.isSendData)(evt.transaction.message),
245
- currentTransactionIsSendData: (ctx) => (0, SendDataShared_1.isSendData)(ctx.currentTransaction?.parts.current),
246
- isSendDataWithCallbackTimeout: (ctx, evt) => {
247
- return ((0, SendDataShared_1.isSendData)(ctx.currentTransaction?.parts.current) &&
248
- evt.data?.type === "failure" &&
249
- evt.data?.reason === "callback timeout");
250
- },
251
- isExecuting: (ctx, evt, meta) => meta.state.matches("execute"),
252
- isAbortingWithTimeout: (ctx, evt, meta) => meta.state.matches("abortSendData"),
253
- isAbortingInFlight: (ctx) => ctx.abortActor != undefined,
254
- },
255
- delays: {},
256
- });
257
- }
258
- exports.createCommandQueueMachine = createCommandQueueMachine;
259
- //# sourceMappingURL=CommandQueueMachine.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CommandQueueMachine.js","sourceRoot":"","sources":["../../../src/lib/driver/CommandQueueMachine.ts"],"names":[],"mappings":";;;AACA,6CAAmD;AACnD,8DAA0D;AAC1D,mCASgB;AAChB,gDAA8E;AAC9E,0EAAmE;AACnE,uEAKmC;AACnC,6DAG8B;AAoE9B,MAAM,qBAAqB,GAA2C,IAAA,eAAM,EAC3E,CAAC,GAAG,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AAE,CAAC,GAAG,CAAC,UAAU,IAAI,SAAS;SACxD;QACD,MAAM,EAAE,EAAE;KACV,CACD,CAAC;AACH,CAAC;AA7OD,8DA6OC"}
@@ -1,97 +0,0 @@
1
- import { MessagePriority, type ZWaveErrorCodes } from "@zwave-js/core";
2
- import type { Message } from "@zwave-js/serial";
3
- import { SortedList } from "alcalzone-shared/sorted-list";
4
- import { type ActorRef, type ActorRefFrom, type Interpreter, type StateMachine } from "xstate";
5
- import { type CommandQueueEvent } from "./CommandQueueMachine";
6
- import type { SerialAPICommandDoneData, SerialAPICommandMachineParams } from "./SerialAPICommandMachine";
7
- import type { ServiceImplementations } from "./StateMachineShared";
8
- import type { Transaction } from "./Transaction";
9
- import { type TransactionMachine } from "./TransactionMachine";
10
- import type { ZWaveOptions } from "./ZWaveOptions";
11
- export type SendDataErrorData = (SerialAPICommandDoneData & {
12
- type: "failure";
13
- }) | {
14
- type: "failure";
15
- reason: "node timeout";
16
- result?: undefined;
17
- };
18
- export interface ActiveTransaction {
19
- transaction: Transaction;
20
- machine: ActorRefFrom<TransactionMachine>;
21
- }
22
- export interface SendThreadContext {
23
- queue: SortedList<Transaction>;
24
- commandQueue: ActorRef<any, any>;
25
- activeTransactions: Map<string, ActiveTransaction>;
26
- counter: number;
27
- paused: boolean;
28
- }
29
- export type SendThreadEvent = {
30
- type: "add";
31
- transaction: Transaction;
32
- } | {
33
- type: "trigger";
34
- } | {
35
- type: "unsolicited";
36
- message: Message;
37
- } | {
38
- type: "sortQueue";
39
- } | {
40
- type: "NIF";
41
- nodeId: number;
42
- } | {
43
- type: "reduce";
44
- reducer: TransactionReducer;
45
- } | {
46
- type: "resend";
47
- } | {
48
- type: "ACK";
49
- } | {
50
- type: "CAN";
51
- } | {
52
- type: "NAK";
53
- } | {
54
- type: "message";
55
- message: Message;
56
- } | (CommandQueueEvent & ({
57
- type: "command_success";
58
- } | {
59
- type: "command_failure";
60
- } | {
61
- type: "command_error";
62
- })) | {
63
- type: "pause" | "unpause";
64
- } | {
65
- type: "forward";
66
- from: string;
67
- to: string;
68
- payload: any;
69
- } | {
70
- type: "transaction_done";
71
- id: string;
72
- };
73
- export type SendThreadMachine = StateMachine<SendThreadContext, any, SendThreadEvent, any, any, any, any>;
74
- export type SendThreadInterpreter = Interpreter<SendThreadContext, any, SendThreadEvent>;
75
- export type TransactionReducerResult = {
76
- type: "drop";
77
- } | {
78
- type: "keep";
79
- } | {
80
- type: "reject";
81
- message: string;
82
- code: ZWaveErrorCodes;
83
- } | {
84
- type: "resolve";
85
- message?: Message;
86
- } | {
87
- type: "requeue";
88
- priority?: MessagePriority;
89
- tag?: any;
90
- };
91
- export type TransactionReducer = (transaction: Transaction, source: "queue" | "active") => TransactionReducerResult;
92
- export type SendThreadMachineParams = {
93
- timeouts: SerialAPICommandMachineParams["timeouts"] & Pick<ZWaveOptions["timeouts"], "report">;
94
- attempts: SerialAPICommandMachineParams["attempts"];
95
- };
96
- export declare function createSendThreadMachine(implementations: ServiceImplementations, params: SendThreadMachineParams): SendThreadMachine;
97
- //# sourceMappingURL=SendThreadMachine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SendThreadMachine.d.ts","sourceRoot":"","sources":["../../../src/lib/driver/SendThreadMachine.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,eAAe,EAEf,KAAK,eAAe,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAMN,KAAK,QAAQ,EACb,KAAK,YAAY,EAEjB,KAAK,WAAW,EAGhB,KAAK,YAAY,EACjB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAEN,KAAK,iBAAiB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACX,wBAAwB,EACxB,6BAA6B,EAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,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,EAAE,GAAG,CAAC;CACT,CAAC;AAEL,MAAM,MAAM,kBAAkB,GAAG,CAChC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,OAAO,GAAG,QAAQ,KACtB,wBAAwB,CAAC;AAE9B,MAAM,MAAM,uBAAuB,GAAG;IACrC,QAAQ,EAAE,6BAA6B,CAAC,UAAU,CAAC,GAClD,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC1C,QAAQ,EAAE,6BAA6B,CAAC,UAAU,CAAC,CAAC;CACpD,CAAC;AAsFF,wBAAgB,uBAAuB,CACtC,eAAe,EAAE,sBAAsB,EACvC,MAAM,EAAE,uBAAuB,GAC7B,iBAAiB,CAkRnB"}
@@ -1,286 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSendThreadMachine = void 0;
4
- const NoOperationCC_1 = require("@zwave-js/cc/NoOperationCC");
5
- const core_1 = require("@zwave-js/core");
6
- const sorted_list_1 = require("alcalzone-shared/sorted-list");
7
- const xstate_1 = require("xstate");
8
- const actions_1 = require("xstate/lib/actions");
9
- const _Types_1 = require("../node/_Types");
10
- const CommandQueueMachine_1 = require("./CommandQueueMachine");
11
- const TransactionMachine_1 = require("./TransactionMachine");
12
- const finalizeTransaction = (0, actions_1.pure)((ctx, evt) => [
13
- (0, actions_1.stop)(evt.id),
14
- (0, xstate_1.assign)((ctx) => {
15
- // Pause the send thread if necessary
16
- const transaction = ctx.activeTransactions.get(evt.id)?.transaction;
17
- if (transaction?.pauseSendThread)
18
- ctx.paused = true;
19
- // Remove the last reference to the actor
20
- ctx.activeTransactions.delete(evt.id);
21
- return ctx;
22
- }),
23
- ]);
24
- const forwardToCommandQueue = (0, xstate_1.forwardTo)((ctx) => ctx.commandQueue);
25
- const sortQueue = (0, xstate_1.assign)({
26
- queue: (ctx) => {
27
- const queue = ctx.queue;
28
- const items = [...queue];
29
- queue.clear();
30
- // Since the send queue is a sorted list, sorting is done on insert/add
31
- queue.add(...items);
32
- return queue;
33
- },
34
- });
35
- const guards = {
36
- mayStartTransaction: (ctx, evt, meta) => {
37
- // We may not send anything if the send thread is paused
38
- if (ctx.paused)
39
- return false;
40
- const nextTransaction = ctx.queue.peekStart();
41
- // We can't send anything if the queue is empty
42
- if (!nextTransaction)
43
- return false;
44
- const message = nextTransaction.message;
45
- const targetNode = message.getNodeUnsafe(nextTransaction.driver);
46
- // The send queue is sorted automatically. If the first message is for a sleeping node, all messages in the queue are.
47
- // There are a few exceptions:
48
- // 1. Pings may be used to determine whether a node is really asleep.
49
- // 2. Responses to nonce requests must be sent independent of the node status, because some sleeping nodes may try to send us encrypted messages.
50
- // If we don't send them, they block the send queue
51
- // 3. Nodes that can sleep but do not support wakeup: https://github.com/zwave-js/node-zwave-js/discussions/1537
52
- // We need to try and send messages to them even if they are asleep, because we might never hear from them
53
- // While the queue is busy, we may not start any transaction, except nonce responses to the node we're currently communicating with
54
- if (meta.state.matches("busy")) {
55
- if (nextTransaction.priority === core_1.MessagePriority.Nonce) {
56
- for (const active of ctx.activeTransactions.values()) {
57
- if (active.transaction.message.getNodeId() ===
58
- nextTransaction.message.getNodeId()) {
59
- return true;
60
- }
61
- }
62
- }
63
- return false;
64
- }
65
- // While not busy, always reply to nonce requests and Supervision Get requests
66
- if (nextTransaction.priority === core_1.MessagePriority.Nonce ||
67
- nextTransaction.priority === core_1.MessagePriority.Supervision) {
68
- return true;
69
- }
70
- // And send pings
71
- if ((0, NoOperationCC_1.messageIsPing)(message))
72
- return true;
73
- // Or controller messages
74
- if (!targetNode)
75
- return true;
76
- return (targetNode.status !== _Types_1.NodeStatus.Asleep ||
77
- (!targetNode.supportsCC(core_1.CommandClasses["Wake Up"]) &&
78
- targetNode.interviewStage >= _Types_1.InterviewStage.NodeInfo));
79
- },
80
- hasNoActiveTransactions: (ctx) => ctx.activeTransactions.size === 0,
81
- };
82
- function createSendThreadMachine(implementations, params) {
83
- const notifyUnsolicited = (_, evt) => {
84
- implementations.notifyUnsolicited(evt.message);
85
- };
86
- const reduce = (0, actions_1.pure)((ctx, evt) => {
87
- const dropQueued = [];
88
- const stopActive = [];
89
- const requeue = [];
90
- const reduceTransaction = (transaction, source) => {
91
- const reducerResult = evt.reducer(transaction, source);
92
- switch (reducerResult.type) {
93
- case "drop":
94
- (source === "queue" ? dropQueued : stopActive).push(transaction);
95
- break;
96
- case "requeue":
97
- if (reducerResult.priority != undefined) {
98
- transaction.priority = reducerResult.priority;
99
- }
100
- if (reducerResult.tag != undefined) {
101
- transaction.tag = reducerResult.tag;
102
- }
103
- if (source === "active")
104
- stopActive.push(transaction);
105
- requeue.push(transaction);
106
- break;
107
- case "resolve":
108
- implementations.resolveTransaction(transaction, reducerResult.message);
109
- (source === "queue" ? dropQueued : stopActive).push(transaction);
110
- break;
111
- case "reject":
112
- implementations.rejectTransaction(transaction, new core_1.ZWaveError(reducerResult.message, reducerResult.code, undefined, transaction.stack));
113
- (source === "queue" ? dropQueued : stopActive).push(transaction);
114
- break;
115
- }
116
- };
117
- const { queue, activeTransactions } = ctx;
118
- for (const transaction of queue) {
119
- reduceTransaction(transaction, "queue");
120
- }
121
- for (const { transaction } of activeTransactions.values()) {
122
- reduceTransaction(transaction, "active");
123
- }
124
- // Now we know what to do with the transactions
125
- queue.remove(...dropQueued, ...requeue);
126
- queue.add(...requeue.map((t) => t.clone()));
127
- return [
128
- (0, xstate_1.assign)((ctx) => ({
129
- ...ctx,
130
- queue,
131
- })),
132
- ...stopActive.map((t) => (0, actions_1.send)({ type: "remove", transaction: t }, { to: ctx.commandQueue })),
133
- ];
134
- });
135
- const spawnTransaction = (0, xstate_1.assign)((ctx) => {
136
- const newCounter = (ctx.counter + 1) % 0xffffffff;
137
- const id = "T" + newCounter.toString(16).padStart(8, "0");
138
- const transaction = ctx.queue.shift();
139
- const machine = (0, xstate_1.spawn)((0, TransactionMachine_1.createTransactionMachine)(id, transaction, implementations), {
140
- name: id,
141
- });
142
- ctx.activeTransactions.set(id, { machine, transaction });
143
- return {
144
- ...ctx,
145
- counter: newCounter,
146
- };
147
- });
148
- const ret = (0, xstate_1.createMachine)({
149
- id: "SendThread",
150
- initial: "init",
151
- preserveActionOrder: true,
152
- context: {
153
- commandQueue: undefined,
154
- queue: new sorted_list_1.SortedList(),
155
- activeTransactions: new Map(),
156
- counter: 0,
157
- paused: false,
158
- },
159
- on: {
160
- // Forward low-level events and unidentified messages to the command queue
161
- ACK: { actions: forwardToCommandQueue },
162
- CAN: { actions: forwardToCommandQueue },
163
- NAK: { actions: forwardToCommandQueue },
164
- // messages may come back as "unsolicited", these might be expected updates
165
- // we need to run them through the serial API machine to avoid mismatches
166
- message: { actions: forwardToCommandQueue },
167
- // Forward NIFs to each transaction machine to resolve potential waiting pings
168
- NIF: {
169
- actions: (0, actions_1.pure)((ctx, evt) => {
170
- const activeTransactionMachinesForNode = [
171
- ...ctx.activeTransactions.values(),
172
- ]
173
- .filter(({ transaction }) => transaction.message.getNodeId() ===
174
- evt.nodeId)
175
- .map((a) => a.machine.id);
176
- return [
177
- ...activeTransactionMachinesForNode.map((id) => (0, actions_1.send)(evt, { to: id })),
178
- // Sort the send queue and evaluate again whether the next message may be sent
179
- sortQueue,
180
- (0, actions_1.raise)("trigger"),
181
- ];
182
- }),
183
- },
184
- // handle newly added messages
185
- add: {
186
- actions: [
187
- (0, xstate_1.assign)({
188
- queue: (ctx, evt) => {
189
- ctx.queue.add(evt.transaction);
190
- return ctx.queue;
191
- },
192
- }),
193
- (0, actions_1.raise)("trigger"),
194
- ],
195
- },
196
- reduce: {
197
- // Reducing may reorder the queue, so raise a trigger afterwards
198
- actions: [reduce, (0, actions_1.raise)("trigger")],
199
- },
200
- // Return unsolicited messages to the driver
201
- unsolicited: {
202
- actions: notifyUnsolicited,
203
- },
204
- // Accept external commands to sort the queue
205
- sortQueue: {
206
- actions: [sortQueue, (0, actions_1.raise)("trigger")],
207
- },
208
- // Accept external commands to pause/unpause the send queue
209
- pause: {
210
- actions: [(0, xstate_1.assign)({ paused: () => true })],
211
- },
212
- unpause: {
213
- actions: [
214
- (0, xstate_1.assign)({ paused: () => false }),
215
- (0, actions_1.raise)("trigger"),
216
- ],
217
- },
218
- // forward events between child machinies
219
- forward: {
220
- actions: (0, actions_1.send)((_, evt) => ({ ...evt.payload, from: evt.from }), {
221
- to: (_, evt) => evt.to,
222
- }),
223
- },
224
- // Stop transactions when they are done
225
- transaction_done: {
226
- actions: [finalizeTransaction, (0, actions_1.raise)("trigger")],
227
- },
228
- },
229
- states: {
230
- init: {
231
- entry: (0, xstate_1.assign)({
232
- commandQueue: () => (0, xstate_1.spawn)((0, CommandQueueMachine_1.createCommandQueueMachine)(implementations, params), {
233
- name: "QUEUE",
234
- }),
235
- }),
236
- // Spawn the command queue when starting the send thread
237
- always: "idle",
238
- },
239
- // While idle, any transaction may be started
240
- idle: {
241
- id: "idle",
242
- always: {
243
- cond: "mayStartTransaction",
244
- // Use the first transaction in the queue as the current one
245
- actions: spawnTransaction,
246
- target: "busy",
247
- },
248
- on: {
249
- // On trigger, re-evaluate the conditions to enter "busy"
250
- trigger: { target: "idle" },
251
- },
252
- },
253
- // While busy, only nonces may be sent
254
- busy: {
255
- id: "busy",
256
- always: [
257
- {
258
- cond: "hasNoActiveTransactions",
259
- target: "idle",
260
- },
261
- {
262
- cond: "mayStartTransaction",
263
- // Use the first transaction in the queue as the current one
264
- actions: spawnTransaction,
265
- target: "busy",
266
- },
267
- ],
268
- on: {
269
- // On trigger, re-evaluate the conditions to go spawn transactions or back to idle
270
- trigger: { target: "busy" },
271
- },
272
- },
273
- },
274
- }, {
275
- guards: {
276
- ...guards,
277
- every: (ctx, event, { cond }) => {
278
- const keys = cond.guards;
279
- return keys.every((guardKey) => guards[guardKey]?.(ctx, event, undefined));
280
- },
281
- },
282
- });
283
- return ret;
284
- }
285
- exports.createSendThreadMachine = createSendThreadMachine;
286
- //# sourceMappingURL=SendThreadMachine.js.map