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-8920] Add DiscoverComponents to robot client #274

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hexbabe
Copy link
Member

@hexbabe hexbabe commented Oct 8, 2024

https://viam.atlassian.net/browse/RSDK-8920

  • Bump proto version to get new DiscoveryQuery field extra
  • Add method and new class to robot client
  • Test with module that implements Discovery

First PR in Flutter SDK and first time writing code Dart; appreciate tips and best practice comments on top of correctness

@hexbabe hexbabe requested a review from a team as a code owner October 8, 2024 14:42
@hexbabe hexbabe marked this pull request as draft October 8, 2024 14:42
@hexbabe hexbabe marked this pull request as ready for review October 11, 2024 14:30
@@ -5,17 +5,19 @@ import 'package:grpc/grpc_connection_interface.dart';
import 'package:logger/logger.dart';

import '../gen/common/v1/common.pb.dart';
import '../gen/robot/v1/robot.pbgrpc.dart';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Real" non-proto update changes occur in this file

@@ -5,17 +5,19 @@ import 'package:grpc/grpc_connection_interface.dart';
import 'package:logger/logger.dart';

import '../gen/common/v1/common.pb.dart';
import '../gen/robot/v1/robot.pbgrpc.dart';
import '../gen/google/protobuf/struct.pb.dart';
import '../gen/robot/v1/robot.pbgrpc.dart' as rpb;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import aliasing robot pb to avoid identifier collision between the new DiscoveryQuery in the SDK, and the pb DiscoveryQuery

Comment on lines +57 to +68
/// {@category Viam SDK}
/// Represents a discovery query in the SDK to query for discoverable components.
class DiscoveryQuery {
final String subtype;
final String model;
final Map<String, dynamic> extra;

DiscoveryQuery({required this.subtype, required this.model, Map<String, dynamic>? extra}) : extra = extra ?? {};

Struct get extraStruct => extra.toStruct();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this class should exist and that people should just use the DiscoveryQuery proto directly. This doesn't add any additional functionality or ergonomics to the developer IMO

Copy link
Member Author

@hexbabe hexbabe Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't make this class, how do we import rpb's proto DiscoveryQuery in our app? I tried using import 'package:viam_sdk/viam_sdk.dart'; in my test app, and it doesn't seem to import proto methods and classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/main.dart:53:19: Error: The method 'DiscoveryQuery' isn't defined for the class '_MyHomePageState'.
 - '_MyHomePageState' is from 'package:sean_flutter_app/main.dart' ('lib/main.dart').
Try correcting the name to the name of an existing method, or defining a method named 'DiscoveryQuery'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be in favor of DRY-ing this data struct. But is there a convenient way to import proto classes into user apps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import it from viam_sdk/protos/... or you can add it as a typedef here similar to how we do it for CloudMetadata a few lines above (the preferred way IMO)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it let me check out the latter way

Copy link
Member Author

@hexbabe hexbabe Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the latter way, I had a hard time figuring out how to initialize the extra pb struct. Ended up importing import 'package:viam_sdk/src/utils.dart'; for the map toStruct helper logic. This seems like bad practice though since utils.dart seems purposefully excluded as an export from viam_sdk.dart.

Open to ideas on how to make it easier to use extra without the Struct get extraStruct => extra.toStruct(); utility in the DiscoveryQuery first draft.

@hexbabe hexbabe requested a review from njooma October 14, 2024 14:32
Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok given the challenges around protobufs/struct, this is good as is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants