Skip to content

Commit

Permalink
fixup! feat: improve DataSchemaValue handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 30, 2023
1 parent 4629449 commit 1916a0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions lib/src/core/interaction_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ class InteractionOutput implements scripting_api.InteractionOutput {
return _value.internalValue;
}

final schema = this.schema;
if (schema == null) {
// TODO: Throw NotReadableError
throw Exception();
}
// TODO(JKRhb): Should a NotReadableError be thrown if schema is null?
// C.f. https://w3c.github.io/wot-scripting-api/#the-value-function

final value = await _contentSerdes.contentToValue(
_content,
schema,
);
_dataUsed = true;

_value = (read: true, internalValue: value);
return value;
_value = (read: true, internalValue: value?.value);
return value?.value;
}

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/wot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ class WoT implements scripting_api.WoT {
await consumedDirectoryThing.readProperty('things');
final rawThingDescriptions = await interactionOutput.value();

if (rawThingDescriptions is! scripting_api.DataSchemaValue<List<Object?>>) {
if (rawThingDescriptions is! List<Object?>) {
throw DiscoveryException(
'Expected an array of Thing Descriptions but received an '
'invalid output instead.',
);
}

final thingDescriptionStream = Stream.fromIterable(
rawThingDescriptions.value.whereType<Map<String, Object?>>(),
rawThingDescriptions.whereType<Map<String, Object?>>(),
).toThingDescriptionStream();

return ThingDiscoveryProcess(thingDescriptionStream, filter);
Expand Down

0 comments on commit 1916a0e

Please sign in to comment.