From 83050a52f535aac8d993b3af24fcd2f82d38185e Mon Sep 17 00:00:00 2001 From: randhid Date: Thu, 17 Oct 2024 21:50:25 -0400 Subject: [PATCH] remove servo status --- components/servo/servo.go | 14 -------- components/servo/servo_test.go | 59 ---------------------------------- 2 files changed, 73 deletions(-) delete mode 100644 components/servo/servo_test.go diff --git a/components/servo/servo.go b/components/servo/servo.go index 392dc61fe28..eece69d8f2a 100644 --- a/components/servo/servo.go +++ b/components/servo/servo.go @@ -16,7 +16,6 @@ import ( func init() { resource.RegisterAPI(API, resource.APIRegistration[Servo]{ - Status: resource.StatusFunc(CreateStatus), RPCServiceServerConstructor: NewRPCServiceServer, RPCServiceHandler: pb.RegisterServoServiceHandlerFromEndpoint, RPCServiceDesc: &pb.ServoService_ServiceDesc, @@ -83,16 +82,3 @@ func FromRobot(r robot.Robot, name string) (Servo, error) { func NamesFromRobot(r robot.Robot) []string { return robot.NamesByAPI(r, API) } - -// CreateStatus creates a status from the servo. -func CreateStatus(ctx context.Context, s Servo) (*pb.Status, error) { - position, err := s.Position(ctx, nil) - if err != nil { - return nil, err - } - isMoving, err := s.IsMoving(ctx) - if err != nil { - return nil, err - } - return &pb.Status{PositionDeg: position, IsMoving: isMoving}, nil -} diff --git a/components/servo/servo_test.go b/components/servo/servo_test.go deleted file mode 100644 index 7bbfeeb70f1..00000000000 --- a/components/servo/servo_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package servo_test - -import ( - "context" - "testing" - - "github.com/pkg/errors" - pb "go.viam.com/api/component/servo/v1" - "go.viam.com/test" - - "go.viam.com/rdk/components/servo" - "go.viam.com/rdk/resource" - "go.viam.com/rdk/testutils/inject" -) - -func TestCreateStatus(t *testing.T) { - status := &pb.Status{PositionDeg: uint32(8), IsMoving: true} - - injectServo := &inject.Servo{} - injectServo.PositionFunc = func(ctx context.Context, extra map[string]interface{}) (uint32, error) { - return status.PositionDeg, nil - } - injectServo.IsMovingFunc = func(context.Context) (bool, error) { - return true, nil - } - - t.Run("working", func(t *testing.T) { - status1, err := servo.CreateStatus(context.Background(), injectServo) - test.That(t, err, test.ShouldBeNil) - test.That(t, status1, test.ShouldResemble, status) - - resourceAPI, ok, err := resource.LookupAPIRegistration[servo.Servo](servo.API) - test.That(t, err, test.ShouldBeNil) - test.That(t, ok, test.ShouldBeTrue) - status2, err := resourceAPI.Status(context.Background(), injectServo) - test.That(t, err, test.ShouldBeNil) - test.That(t, status2, test.ShouldResemble, status) - }) - - t.Run("not moving", func(t *testing.T) { - injectServo.IsMovingFunc = func(context.Context) (bool, error) { - return false, nil - } - - status2 := &pb.Status{PositionDeg: uint32(8), IsMoving: false} - status1, err := servo.CreateStatus(context.Background(), injectServo) - test.That(t, err, test.ShouldBeNil) - test.That(t, status1, test.ShouldResemble, status2) - }) - - t.Run("fail on Position", func(t *testing.T) { - errFail := errors.New("can't get position") - injectServo.PositionFunc = func(ctx context.Context, extra map[string]interface{}) (uint32, error) { - return 0, errFail - } - _, err := servo.CreateStatus(context.Background(), injectServo) - test.That(t, err, test.ShouldBeError, errFail) - }) -}