@@ -76,9 +76,10 @@ class ConsumedThing implements scripting_api.ConsumedThing {
7676 List <Form > forms,
7777 OperationType operationType,
7878 _AffordanceType affordanceType,
79- InteractionOptions ? options,
80- InteractionAffordance interactionAffordance,
81- ) {
79+ InteractionAffordance interactionAffordance, {
80+ required int ? formIndex,
81+ required Map <String , Object >? uriVariables,
82+ }) {
8283 if (forms.isEmpty) {
8384 throw StateError (
8485 'ConsumedThing "$title " has no links for this interaction' ,
@@ -88,8 +89,6 @@ class ConsumedThing implements scripting_api.ConsumedThing {
8889 final ProtocolClient client;
8990 final Form foundForm;
9091
91- final formIndex = options? .formIndex;
92-
9392 if (formIndex != null ) {
9493 if (formIndex >= 0 && formIndex < forms.length) {
9594 foundForm = forms[formIndex];
@@ -114,17 +113,18 @@ class ConsumedThing implements scripting_api.ConsumedThing {
114113 client = servient.clientFor (scheme);
115114 }
116115
117- final form =
118- foundForm.resolveUriVariables (options? .uriVariables) ?? foundForm;
116+ final form = foundForm.resolveUriVariables (uriVariables) ?? foundForm;
119117
120118 return (client: client, form: form);
121119 }
122120
123121 @override
124122 Future <InteractionOutput > readProperty (
125- String propertyName, [
126- InteractionOptions ? options,
127- ]) async {
123+ String propertyName, {
124+ int ? formIndex,
125+ Map <String , Object >? uriVariables,
126+ Object ? data,
127+ }) async {
128128 final property = thingDescription.properties[propertyName];
129129
130130 if (property == null ) {
@@ -138,8 +138,9 @@ class ConsumedThing implements scripting_api.ConsumedThing {
138138 property.forms,
139139 OperationType .readproperty,
140140 _AffordanceType .property,
141- options,
142141 property,
142+ formIndex: formIndex,
143+ uriVariables: uriVariables,
143144 );
144145
145146 final form = clientAndForm.form;
@@ -152,9 +153,11 @@ class ConsumedThing implements scripting_api.ConsumedThing {
152153 @override
153154 Future <void > writeProperty (
154155 String propertyName,
155- Object ? interactionInput, [
156- InteractionOptions ? options,
157- ]) async {
156+ InteractionInput input, {
157+ int ? formIndex,
158+ Map <String , Object >? uriVariables,
159+ Object ? data,
160+ }) async {
158161 // TODO(JKRhb): Refactor
159162 final property = thingDescription.properties[propertyName];
160163
@@ -169,23 +172,26 @@ class ConsumedThing implements scripting_api.ConsumedThing {
169172 property.forms,
170173 OperationType .writeproperty,
171174 _AffordanceType .property,
172- options,
173175 property,
176+ formIndex: formIndex,
177+ uriVariables: uriVariables,
174178 );
175179
176180 final form = clientAndForm.form;
177181 final client = clientAndForm.client;
178182 final content = servient.contentSerdes
179- .valueToContent (interactionInput , property, form.contentType);
183+ .valueToContent (input , property, form.contentType);
180184 await client.writeResource (form, content);
181185 }
182186
183187 @override
184188 Future <InteractionOutput > invokeAction (
185- String actionName, [
186- Object ? interactionInput,
187- InteractionOptions ? options,
188- ]) async {
189+ String actionName, {
190+ InteractionInput input,
191+ Object ? data,
192+ int ? formIndex,
193+ Map <String , Object >? uriVariables,
194+ }) async {
189195 // TODO(JKRhb): Refactor
190196 final action = thingDescription.actions[actionName];
191197
@@ -200,26 +206,27 @@ class ConsumedThing implements scripting_api.ConsumedThing {
200206 action.forms,
201207 OperationType .invokeaction,
202208 _AffordanceType .action,
203- options,
204209 action,
210+ uriVariables: uriVariables,
211+ formIndex: formIndex,
205212 );
206213
207214 final form = clientAndForm.form;
208215 final client = clientAndForm.client;
209- final input = servient.contentSerdes
210- .valueToContent (interactionInput , action.input, form.contentType);
216+ final content = servient.contentSerdes
217+ .valueToContent (input , action.input, form.contentType);
211218
212- final content = await client.invokeResource (form, input );
219+ final output = await client.invokeResource (form, content );
213220
214221 final response = form.response;
215222 if (response != null ) {
216- if (content .type != response.contentType) {
223+ if (output .type != response.contentType) {
217224 throw UnexpectedReponseException ('Unexpected type in response' );
218225 }
219226 }
220227
221228 return InteractionOutput (
222- content ,
229+ output ,
223230 servient.contentSerdes,
224231 form,
225232 action.output,
@@ -229,10 +236,12 @@ class ConsumedThing implements scripting_api.ConsumedThing {
229236 @override
230237 Future <Subscription > observeProperty (
231238 String propertyName,
232- scripting_api.InteractionListener listener, [
239+ scripting_api.InteractionListener listener, {
233240 scripting_api.ErrorListener ? onError,
234- InteractionOptions ? options,
235- ]) async {
241+ Object ? data,
242+ int ? formIndex,
243+ Map <String , Object >? uriVariables,
244+ }) async {
236245 final property = thingDescription.properties[propertyName];
237246
238247 if (property == null ) {
@@ -251,24 +260,26 @@ class ConsumedThing implements scripting_api.ConsumedThing {
251260
252261 return _createSubscription (
253262 property,
254- options,
255263 listener,
256264 onError,
257265 propertyName,
258266 property,
259267 SubscriptionType .property,
268+ formIndex: formIndex,
269+ uriVariables: uriVariables,
260270 );
261271 }
262272
263273 Future <Subscription > _createSubscription (
264274 InteractionAffordance affordance,
265- scripting_api.InteractionOptions ? options,
266275 scripting_api.InteractionListener listener,
267276 scripting_api.ErrorListener ? onError,
268277 String affordanceName,
269278 DataSchema ? dataSchema,
270- SubscriptionType subscriptionType,
271- ) async {
279+ SubscriptionType subscriptionType, {
280+ required int ? formIndex,
281+ required Map <String , Object >? uriVariables,
282+ }) async {
272283 final OperationType operationType;
273284 final _AffordanceType affordanceType;
274285 final Map <String , Subscription > subscriptions;
@@ -287,8 +298,9 @@ class ConsumedThing implements scripting_api.ConsumedThing {
287298 affordance.forms,
288299 operationType,
289300 affordanceType,
290- options,
291301 affordance,
302+ uriVariables: uriVariables,
303+ formIndex: formIndex,
292304 );
293305
294306 final form = clientAndForm.form;
@@ -318,13 +330,20 @@ class ConsumedThing implements scripting_api.ConsumedThing {
318330 }
319331
320332 Future <PropertyReadMap > _readProperties (
321- List <String > propertyNames,
322- InteractionOptions ? options,
323- ) async {
333+ List <String > propertyNames, {
334+ Object ? data,
335+ int ? formIndex,
336+ Map <String , Object >? uriVariables,
337+ }) async {
324338 final Map <String , Future <InteractionOutput >> outputs = {};
325339
326340 for (final propertyName in propertyNames) {
327- outputs[propertyName] = readProperty (propertyName, options);
341+ outputs[propertyName] = readProperty (
342+ propertyName,
343+ data: data,
344+ formIndex: formIndex,
345+ uriVariables: uriVariables,
346+ );
328347 }
329348
330349 final outputList = await Future .wait (outputs.values);
@@ -333,28 +352,46 @@ class ConsumedThing implements scripting_api.ConsumedThing {
333352 }
334353
335354 @override
336- Future <PropertyReadMap > readAllProperties ([InteractionOptions ? options]) {
355+ Future <PropertyReadMap > readAllProperties ({
356+ Object ? data,
357+ int ? formIndex,
358+ Map <String , Object >? uriVariables,
359+ }) {
337360 final propertyNames =
338361 thingDescription.properties.keys.toList (growable: false );
339362
340- return _readProperties (propertyNames, options);
363+ return _readProperties (
364+ propertyNames,
365+ data: data,
366+ formIndex: formIndex,
367+ uriVariables: uriVariables,
368+ );
341369 }
342370
343371 @override
344372 Future <PropertyReadMap > readMultipleProperties (
345- List <String > propertyNames, [
346- InteractionOptions ? options,
347- ]) {
348- return _readProperties (propertyNames, options);
373+ List <String > propertyNames, {
374+ Object ? data,
375+ int ? formIndex,
376+ Map <String , Object >? uriVariables,
377+ }) {
378+ return _readProperties (
379+ propertyNames,
380+ data: data,
381+ formIndex: formIndex,
382+ uriVariables: uriVariables,
383+ );
349384 }
350385
351386 @override
352387 Future <Subscription > subscribeEvent (
353388 String eventName,
354- scripting_api.InteractionListener listener, [
389+ scripting_api.InteractionListener listener, {
355390 scripting_api.ErrorListener ? onError,
356- InteractionOptions ? options,
357- ]) {
391+ Object ? data,
392+ int ? formIndex,
393+ Map <String , Object >? uriVariables,
394+ }) {
358395 // TODO(JKRhb): Handle subscription and cancellation data.
359396 final event = thingDescription.events[eventName];
360397
@@ -374,20 +411,23 @@ class ConsumedThing implements scripting_api.ConsumedThing {
374411
375412 return _createSubscription (
376413 event,
377- options,
378414 listener,
379415 onError,
380416 eventName,
381417 event.data,
382418 SubscriptionType .event,
419+ formIndex: formIndex,
420+ uriVariables: uriVariables,
383421 );
384422 }
385423
386424 @override
387425 Future <void > writeMultipleProperties (
388- PropertyWriteMap valueMap, [
389- InteractionOptions ? options,
390- ]) async {
426+ PropertyWriteMap valueMap, {
427+ Object ? data,
428+ int ? formIndex,
429+ Map <String , Object >? uriVariables,
430+ }) async {
391431 await Future .wait (
392432 valueMap.keys.map ((key) => writeProperty (key, valueMap[key])),
393433 );
0 commit comments