Skip to content

Commit

Permalink
Add generic and gripper FromDependencies methods (#4747)
Browse files Browse the repository at this point in the history
  • Loading branch information
randhid authored Jan 27, 2025
1 parent a7916d6 commit c473803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions components/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func Named(name string) resource.Name {
return resource.NewName(API, name)
}

// FromDependencies is a helper for getting the named generic from a collection of
// dependencies.
func FromDependencies(deps resource.Dependencies, name string) (resource.Resource, error) {
return resource.FromDependencies[resource.Resource](deps, Named(name))
}

// FromRobot is a helper for getting the named Generic from the given Robot.
func FromRobot(r robot.Robot, name string) (resource.Resource, error) {
return robot.ResourceFromRobot[resource.Resource](r, Named(name))
Expand Down
6 changes: 6 additions & 0 deletions components/gripper/gripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func FromRobot(r robot.Robot, name string) (Gripper, error) {
return robot.ResourceFromRobot[Gripper](r, Named(name))
}

// FromDependencies is a helper for getting the named gripper from a collection of
// dependencies.
func FromDependencies(deps resource.Dependencies, name string) (Gripper, error) {
return resource.FromDependencies[Gripper](deps, Named(name))
}

// NamesFromRobot is a helper for getting all gripper names from the given Robot.
func NamesFromRobot(r robot.Robot) []string {
return robot.NamesByAPI(r, API)
Expand Down

0 comments on commit c473803

Please sign in to comment.