Skip to content

Commit

Permalink
DOCS 3123: Fix all service automated methods go (#3667)
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel authored Nov 11, 2024
1 parent e4e9adf commit 84b611a
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 36 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/update_sdk_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@ def parse(type, names):
code_sample = resource_soup.find_all(lambda code_sample_tag: code_sample_tag.name == 'p' and "DoCommand example:" in code_sample_tag.text)
if code_sample:
if type == "component":
go_methods[type][resource]['DoCommand']['code_sample'] = 'my' + resource.title().replace("_", "")+ ', err := ' + resource + '.FromRobot(machine, "my_' + resource.title().replace("_", "") + '")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + '.DoCommand(context.Background(), command)\n'
go_methods[type][resource]['DoCommand']['code_sample'] = 'my' + resource.title().replace("_", "")+ ', err := ' + resource + '.FromRobot(machine, "my_' + resource + '")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + '.DoCommand(context.Background(), command)\n'
if resource == "generic_component":
go_methods[type][resource]['DoCommand']['code_sample'] = 'myGenericComponent, err := generic.FromRobot(machine, "my_generic_component")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := myGenericComponent.DoCommand(context.Background(), command)\n'
else:
go_methods[type][resource]['DoCommand']['code_sample'] = 'my' + resource.title().replace("_", "")+ 'Svc, err := ' + resource + '.FromRobot(machine, "my_' + resource + '_svc")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + 'Svc.DoCommand(context.Background(), command)\n'
go_methods[type][resource]['DoCommand']['code_sample'] = 'my' + resource.title().replace("_", "")+ 'Svc, err := ' + resource.replace("_","") + '.FromRobot(machine, "my_' + resource + '_svc")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + 'Svc.DoCommand(context.Background(), command)\n'
if resource == "slam":
go_methods[type][resource]['DoCommand']['code_sample'] = 'mySLAMService, err := slam.FromRobot(machine, "my_slam_svc")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := mySLAMService.DoCommand(context.Background(), command)\n'

Expand Down Expand Up @@ -949,14 +949,6 @@ def parse(type, names):
go_methods[type][resource]['InternalStateFull']['usage'] = str(internalstatefull_method_raw[0].pre).removeprefix('<pre>func ').removesuffix('</pre>')
go_methods[type][resource]['InternalStateFull']['method_link'] = 'https://pkg.go.dev/go.viam.com/rdk/services/slam#InternalStateFull'


go_methods[type][resource]['DoCommand'] = {}
go_methods[type][resource]['DoCommand'] = {'proto': 'DoCommand', \
'description': 'DoCommand sends/receives arbitrary data.', \
'usage': 'DoCommand(ctx <a href="/context">context</a>.<a href="/context#Context">Context</a>, cmd map[<a href="/builtin#string">string</a>]interface{}) (map[<a href="/builtin#string">string</a>]interface{}, <a href="/builtin#error">error</a>)', \
'method_link': 'https://pkg.go.dev/go.viam.com/rdk/resource#Resource', \
'code_sample': 'my' + resource.title().replace("_", "") + ', err := ' + resource + '.FromRobot(machine, "my_' + resource + '")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + '.DoCommand(context.Background(), command)\n'}

## We have finished looping through all scraped Go methods. Write the go_methods dictionary
## in its entirety to the all_methods dictionary using "go" as the key:
all_methods["go"] = go_methods
Expand All @@ -971,7 +963,7 @@ def parse(type, names):
'description': 'DoCommand sends/receives arbitrary data.', \
'usage': 'DoCommand(ctx <a href="/context">context</a>.<a href="/context#Context">Context</a>, cmd map[<a href="/builtin#string">string</a>]interface{}) (map[<a href="/builtin#string">string</a>]interface{}, <a href="/builtin#error">error</a>)', \
'method_link': 'https://pkg.go.dev/go.viam.com/rdk/resource#Resource', \
'code_sample': 'my' + resource.title().replace("_", "") + ', err := ' + resource + '.FromRobot(machine, "my_' + resource + '")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + '.DoCommand(context.Background(), command)\n'}
'code_sample': 'my' + resource.title().replace("_", "") + ', err := generic.FromRobot(machine, "my_' + resource.lower() + '")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := my' + resource.title().replace("_", "") + '.DoCommand(context.Background(), command)\n'}
if resource == "generic_service":
go_methods[type][resource]['DoCommand']['code_sample'] = 'myGenericService, err := generic.FromRobot(machine, "my_generic_service")\n\ncommand := map[string]interface{}{"cmd": "test", "data1": 500}\nresult, err := myGenericService.DoCommand(context.Background(), command)\n'

Expand Down
12 changes: 6 additions & 6 deletions static/include/components/apis/generated/camera.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ If the server does not know how to return the specified MIME type, the server re
```python {class="line-numbers linkable-line-numbers"}
from viam.media.video import CameraMimeType

my_camera = Camera.from_robot(robot=machine, name="my_camera")
my_camera = Camera.from_robot(robot=machine, name="my_camera")

# Assume "frame" has a mime_type of "image/vnd.viam.dep"
frame = await my_camera.get_image(mime_type = CameraMimeType.VIAM_RAW_DEPTH)
# Assume "frame" has a mime_type of "image/vnd.viam.dep"
frame = await my_camera.get_image(mime_type = CameraMimeType.VIAM_RAW_DEPTH)

# Convert "frame" to a standard 2D image representation.
# Remove the 1st 3x8 bytes and reshape the raw bytes to List[List[Int]].
standard_frame = frame.bytes_to_depth_array()
# Convert "frame" to a standard 2D image representation.
# Remove the 1st 3x8 bytes and reshape the raw bytes to List[List[Int]].
standard_frame = frame.bytes_to_depth_array()
```

If the `mime_type` of your image is `image/vnd.viam.dep`, pass the returned image data to the Viam Python SDK's [`ViamImage.bytes_to_depth_array()`](https://python.viam.dev/autoapi/viam/media/video/index.html#viam.media.video.ViamImage.bytes_to_depth_array) method to decode the raw image data to a standard 2D image representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myGenericComponent, err := generic_component.FromRobot(machine, "my_generic_component")
myGenericComponent, err := generic.FromRobot(machine, "my_generic_component")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myGenericComponent.DoCommand(context.Background(), command)
Expand Down
8 changes: 4 additions & 4 deletions static/include/components/apis/generated/input_controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Get a list of the [Controls](/appendix/apis/components/input-controller/#control
```python {class="line-numbers linkable-line-numbers"}
# Get the controller from the machine.
my_controller = Controller.from_robot(
robot=myRobotWithController, name="my_controller")
robot=machine, "my_controller")

# Get the list of Controls provided by the controller.
controls = await my_controller.get_controls()
Expand Down Expand Up @@ -78,7 +78,7 @@ This method returns the current state of the controller as a map of [Event Objec
```python {class="line-numbers linkable-line-numbers"}
# Get the controller from the machine.
my_controller = Controller.from_robot(
myRobotWithController, "my_controller")
robot=machine, "my_controller")

# Get the most recent Event for each Control.
recent_events = await my_controller.get_events()
Expand Down Expand Up @@ -142,7 +142,7 @@ This method is currently only supported for input controllers of model `webgamep
```python {class="line-numbers linkable-line-numbers"}
# Get your controller from the machine.
my_controller = Controller.from_robot(
myRobotWithController, "my_controller")
robot=machine, "my_controller")

# Define a "Button is Pressed" event for the control BUTTON_START.
button_is_pressed_event = Event(
Expand Down Expand Up @@ -270,7 +270,7 @@ async def main():

# Get your controller from the machine.
my_controller = Controller.from_robot(
myRobotWithController, "my_controller")
robot=machine, "my_controller")

# Run the handleController function.
await handle_controller(my_controller)
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/base_remote_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ If you are implementing your own base remote control service and add features th
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myBaseRemoteControl, err := base_remote_control.FromRobot(machine, "my_base_remote_control")
myBaseRemoteControlSvc, err := baseremotecontrol.FromRobot(machine, "my_base_remote_control_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myBaseRemoteControl.DoCommand(context.Background(), command)
result, err := myBaseRemoteControlSvc.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/data_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ If you are implementing your own data manager service and add features that have
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myDataManager, err := data_manager.FromRobot(machine, "my_data_manager")
myDataManagerSvc, err := datamanager.FromRobot(machine, "my_data_manager_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myDataManager.DoCommand(context.Background(), command)
result, err := myDataManagerSvc.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/mlmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myMlmodel, err := mlmodel.FromRobot(machine, "my_mlmodel")
myMlmodelSvc, err := mlmodel.FromRobot(machine, "my_mlmodel_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myMlmodel.DoCommand(context.Background(), command)
result, err := myMlmodelSvc.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myMotion, err := motion.FromRobot(machine, "my_motion")
myMotionSvc, err := motion.FromRobot(machine, "my_motion_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myMotion.DoCommand(context.Background(), command)
result, err := myMotionSvc.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myNavigation, err := navigation.FromRobot(machine, "my_navigation")
myNavigationSvc, err := navigation.FromRobot(machine, "my_navigation_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myNavigation.DoCommand(context.Background(), command)
result, err := myNavigationSvc.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/slam.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
mySlam, err := slam.FromRobot(machine, "my_slam")
mySLAMService, err := slam.FromRobot(machine, "my_slam_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := mySlam.DoCommand(context.Background(), command)
result, err := mySLAMService.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down
4 changes: 2 additions & 2 deletions static/include/services/apis/generated/vision.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
**Example:**

```go {class="line-numbers linkable-line-numbers"}
myVision, err := vision.FromRobot(machine, "my_vision")
myVisionSvc, err := vision.FromRobot(machine, "my_vision_svc")

command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myVision.DoCommand(context.Background(), command)
result, err := myVisionSvc.DoCommand(context.Background(), command)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).
Expand Down

0 comments on commit 84b611a

Please sign in to comment.