Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-9281] Add native type return to Flutter SDK DiscoverComponents #299

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions lib/src/robot/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ class DiscoveryQuery {
Struct get extraStruct => extra.toStruct();
}

/// {@category Viam SDK}
/// Represents the result of a discovery query.
class Discovery {
final String subtype;
final String model;
final Map<String, dynamic> results;

Discovery({
required this.subtype,
required this.model,
required this.results,
});

factory Discovery.fromProto(rpb.Discovery proto) {
return Discovery(
subtype: proto.query.subtype,
model: proto.query.model,
results: proto.results.toMap(),
);
}

@override
String toString() {
return 'Discovery(subtype: $subtype, model: $model, results: $results)';
}
}

/// {@category Viam SDK}
/// gRPC client for a Robot. This class should be used for all interactions with a robot.
///
Expand Down Expand Up @@ -287,13 +314,14 @@ class RobotClient {
/// var queries = [DiscoveryQuery(subtype: 'camera', model: 'webcam', extra: {'username': 'admin', 'password': 'admin'})];
/// var discoveredComponents = await machine.discoverComponents(queries);
/// ```
Future<rpb.DiscoverComponentsResponse> discoverComponents([List<DiscoveryQuery> queries = const []]) async {
Future<List<Discovery>> discoverComponents([List<DiscoveryQuery> queries = const []]) async {
final request = rpb.DiscoverComponentsRequest()
..queries.addAll(queries.map((sdkQuery) => rpb.DiscoveryQuery()
..subtype = sdkQuery.subtype
..model = sdkQuery.model
..extra = sdkQuery.extraStruct));

return await _client.discoverComponents(request);
final response = await _client.discoverComponents(request);
return response.discovery.map((d) => Discovery.fromProto(d)).toList();
}
}
Loading