Skip to content

Commit

Permalink
RSDK-6463: Add updateRobotPart (#174)
Browse files Browse the repository at this point in the history
* add updateRobotPart
  • Loading branch information
mcvella authored Jan 26, 2024
1 parent f9276a6 commit 4665b24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/src/app/app.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:async';

import 'package:viam_sdk/src/gen/google/protobuf/struct.pb.dart';

import '../gen/app/v1/app.pbgrpc.dart';
import 'permissions.dart';

Expand Down Expand Up @@ -69,6 +71,16 @@ class AppClient {
return response.part;
}

/// Update a specific [RobotPart] by ID
Future<RobotPart> updateRobotPart(String partId, String name, Struct robotConfig) async {
final updateRobotPartRequest = UpdateRobotPartRequest()
..id = partId
..name = name
..robotConfig = robotConfig;
final response = await _client.updateRobotPart(updateRobotPartRequest);
return response.part;
}

/// Get a page of [LogEntry] for a specific [RobotPart]. Logs are sorted by descending time (newest first)
Future<RobotPartLogPage> getLogs(RobotPart part, {bool errorsOnly = false, String pageToken = ''}) async {
final request = GetRobotPartLogsRequest()
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension NullableStringUtils on String? {
extension ValueUtils on Value {
dynamic toPrimitive() {
if (hasBoolValue()) return boolValue;
if (hasListValue()) return listValue.values.map((e) => e.toPrimitive());
if (hasListValue()) return listValue.values.map((e) => e.toPrimitive()).toList();
if (hasNullValue()) return null;
if (hasNumberValue()) return numberValue;
if (hasStringValue()) return stringValue;
Expand Down
11 changes: 11 additions & 0 deletions test/unit_test/app/app_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:mockito/mockito.dart';
import 'package:viam_sdk/protos/app/app.dart';
import 'package:viam_sdk/src/app/app.dart';
import 'package:viam_sdk/src/gen/app/v1/app.pbgrpc.dart';
import 'package:viam_sdk/src/gen/google/protobuf/struct.pb.dart';
import 'package:viam_sdk/src/gen/google/protobuf/timestamp.pb.dart';

import '../mocks/mock_response_future.dart';
Expand Down Expand Up @@ -105,6 +106,16 @@ void main() {
expect(response, equals(expected));
});

test('updateRobotPart', () async {
final expected = RobotPart()
..id = 'id'
..name = 'name2';
when(serviceClient.updateRobotPart(any)).thenAnswer((_) => MockResponseFuture.value(UpdateRobotPartResponse()..part = expected));
final rc = Struct();
final response = await appClient.updateRobotPart('robot part', 'name2', rc);
expect(response, equals(expected));
});

test('listOrganizationMembers', () async {
final expected = [OrganizationMember()..userId = 'userId'];
when(serviceClient.listOrganizationMembers(any))
Expand Down

0 comments on commit 4665b24

Please sign in to comment.