Skip to content
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