Skip to content

Commit

Permalink
feat(core): implement missing write and read methods
Browse files Browse the repository at this point in the history
This commit adds implementations for readAllProperties,
readMultipleProperties, and writeMultipleProperties.
This implementation is currently based on node-wot and
will probably not be the way this is going to be handled
in the future where a Thing should indicate itself which
properties are being able to read or written to.
  • Loading branch information
JKRhb committed Jan 18, 2022
1 parent e8418b4 commit 9961973
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/src/binding_coap/coap_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,11 @@ CoapRequestMethod _requestMethodFromOperationType(OperationType operationType) {
// TODO(JKRhb): Handle observe/subscribe case
switch (operationType) {
case OperationType.readproperty:
case OperationType.readmultipleproperties:
case OperationType.readallproperties:
return CoapRequestMethod.get;
case OperationType.writeproperty:
case OperationType.writemultipleproperties:
return CoapRequestMethod.put;
case OperationType.invokeaction:
return CoapRequestMethod.post;
Expand Down
3 changes: 3 additions & 0 deletions lib/src/binding_http/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,11 @@ HttpRequestMethod _requestMethodFromOperationType(OperationType operationType) {
// TODO(JKRhb): Handle observe/subscribe case
switch (operationType) {
case OperationType.readproperty:
case OperationType.readmultipleproperties:
case OperationType.readallproperties:
return HttpRequestMethod.get;
case OperationType.writeproperty:
case OperationType.writemultipleproperties:
return HttpRequestMethod.put;
case OperationType.invokeaction:
return HttpRequestMethod.post;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/core/consumed_thing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ class ConsumedThing implements scripting_api.ConsumedThing {

@override
Future<PropertyReadMap> readAllProperties([InteractionOptions? options]) {
// TODO(JKRhb): implement readAllProperties
throw UnimplementedError();
final propertyNames = thingDescription.properties.keys.toList();

return _readProperties(propertyNames, options);
}

@override
Future<PropertyReadMap> readMultipleProperties(List<String> propertyNames,
[InteractionOptions? options]) {
// TODO(JKRhb): implement readMultipleProperties
throw UnimplementedError();
return _readProperties(propertyNames, options);
}

@override
Expand Down
9 changes: 9 additions & 0 deletions lib/src/core/operation_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ enum OperationType {
/// Corresponds with the `unobserveproperty` operation type.
unobserveproperty,

/// Corresponds with the `readmultipleproperties` operation type.
readmultipleproperties,

/// Corresponds with the `readallproperties` operation type.
readallproperties,

/// Corresponds with the `writemultipleproperties` operation type.
writemultipleproperties,

/// Corresponds with the `invokeaction` operation type.
invokeaction,

Expand Down

0 comments on commit 9961973

Please sign in to comment.