@@ -29,45 +29,79 @@ module.exports = function (RED) {
29
29
}
30
30
}
31
31
32
- function ValueAPI ( msg , send ) {
32
+ let _AwaiterResolver ;
33
+ const Awaiter = ( ) => {
34
+ return new Promise ( ( Resolve ) => {
35
+ _AwaiterResolver = Resolve ;
36
+ } ) ;
37
+ } ;
38
+
39
+ async function ValueAPI ( msg , send ) {
33
40
let NodeID = undefined ;
34
41
let Endpoint = undefined ;
35
42
let Value = undefined ;
36
43
let ValueID = undefined ;
37
44
let Options = undefined ;
38
45
46
+ let Waiter ;
47
+
39
48
if ( config . node !== undefined && config . node . length > 0 ) {
49
+ Waiter = Awaiter ( ) ;
40
50
const EXP = RED . util . prepareJSONataExpression ( config . node , RedNode ) ;
41
- NodeID = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
51
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
52
+ NodeID = Res ;
53
+ _AwaiterResolver ( ) ;
54
+ } ) ;
55
+ await Promise . all ( [ Waiter ] ) ;
42
56
}
43
57
44
58
if ( config . endpoint !== undefined && config . endpoint . length > 0 ) {
59
+ Waiter = Awaiter ( ) ;
45
60
const EXP = RED . util . prepareJSONataExpression ( config . endpoint , RedNode ) ;
46
- Endpoint = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
61
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
62
+ Endpoint = Res ;
63
+ _AwaiterResolver ( ) ;
64
+ } ) ;
65
+ await Promise . all ( [ Waiter ] ) ;
47
66
}
48
67
49
68
if ( config . vapiValueId !== undefined && config . vapiValueId . length > 0 ) {
69
+ Waiter = Awaiter ( ) ;
50
70
const EXP = RED . util . prepareJSONataExpression (
51
71
config . vapiValueId ,
52
72
RedNode
53
73
) ;
54
- ValueID = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
74
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
75
+ ValueID = Res ;
76
+ _AwaiterResolver ( ) ;
77
+ } ) ;
78
+ await Promise . all ( [ Waiter ] ) ;
55
79
}
56
80
57
81
if ( config . vapiOptions !== undefined && config . vapiOptions . length > 0 ) {
82
+ Waiter = Awaiter ( ) ;
58
83
const EXP = RED . util . prepareJSONataExpression (
59
84
config . vapiOptions ,
60
85
RedNode
61
86
) ;
62
- Options = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
87
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
88
+ Options = Res ;
89
+ _AwaiterResolver ( ) ;
90
+ } ) ;
91
+ await Promise . all ( [ Waiter ] ) ;
63
92
}
64
93
65
94
if ( config . vapiValue !== undefined && config . vapiValue . length > 0 ) {
95
+ Waiter = Awaiter ( ) ;
66
96
const EXP = RED . util . prepareJSONataExpression (
67
97
config . vapiValue ,
68
98
RedNode
69
99
) ;
70
- Value = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
100
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
101
+ Value = Res ;
102
+ _AwaiterResolver ( ) ;
103
+ } ) ;
104
+ await Promise . all ( [ Waiter ] ) ;
71
105
}
72
106
73
107
if ( ValueID === undefined ) {
@@ -120,34 +154,56 @@ module.exports = function (RED) {
120
154
}
121
155
}
122
156
123
- function CCAPI ( msg , send ) {
157
+ async function CCAPI ( msg , send ) {
124
158
let NodeID = undefined ;
125
159
let Endpoint = undefined ;
126
160
let Params = undefined ;
127
161
const NoEvent = config . noEvent || false ;
128
162
let ForceUpdate = undefined ;
129
163
164
+ let Waiter ;
165
+
130
166
if ( config . node !== undefined && config . node . length > 0 ) {
167
+ Waiter = Awaiter ( ) ;
131
168
const EXP = RED . util . prepareJSONataExpression ( config . node , RedNode ) ;
132
- NodeID = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
169
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
170
+ NodeID = Res ;
171
+ _AwaiterResolver ( ) ;
172
+ } ) ;
173
+ await Promise . all ( [ Waiter ] ) ;
133
174
}
134
175
135
176
if ( config . endpoint !== undefined && config . endpoint . length > 0 ) {
177
+ Waiter = Awaiter ( ) ;
136
178
const EXP = RED . util . prepareJSONataExpression ( config . endpoint , RedNode ) ;
137
- Endpoint = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
179
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
180
+ Endpoint = Res ;
181
+ _AwaiterResolver ( ) ;
182
+ } ) ;
183
+ await Promise . all ( [ Waiter ] ) ;
138
184
}
139
185
140
186
if ( config . params !== undefined && config . params . length > 0 ) {
187
+ Waiter = Awaiter ( ) ;
141
188
const EXP = RED . util . prepareJSONataExpression ( config . params , RedNode ) ;
142
- Params = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
189
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
190
+ Params = Res ;
191
+ _AwaiterResolver ( ) ;
192
+ } ) ;
193
+ await Promise . all ( [ Waiter ] ) ;
143
194
}
144
195
145
196
if ( config . forceUpdate !== undefined && config . forceUpdate . length > 0 ) {
197
+ Waiter = Awaiter ( ) ;
146
198
const EXP = RED . util . prepareJSONataExpression (
147
199
config . forceUpdate ,
148
200
RedNode
149
201
) ;
150
- ForceUpdate = RED . util . evaluateJSONataExpression ( EXP , msg ) ;
202
+ RED . util . evaluateJSONataExpression ( EXP , msg , ( Err , Res ) => {
203
+ ForceUpdate = Res ;
204
+ _AwaiterResolver ( ) ;
205
+ } ) ;
206
+ await Promise . all ( [ Waiter ] ) ;
151
207
}
152
208
153
209
if ( Params !== undefined ) {
0 commit comments