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

APP-7497: Add Button and Switch APIs #619

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions proto/viam/component/button/v1/button.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package viam.component.button.v1;

import "common/v1/common.proto";
import "google/api/annotations.proto";
import "google/protobuf/struct.proto";

option go_package = "go.viam.com/api/component/button/v1";
option java_package = "com.viam.component.button.v1";

// A ButtonService services buttons associated with a machine
service ButtonService {
// Pushes a button
rpc Push(PushRequest) returns (PushResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/button/{name}/push"};
}

// DoCommand sends/receives arbitrary commands
rpc DoCommand(common.v1.DoCommandRequest) returns (common.v1.DoCommandResponse) {
option (google.api.http) = {post: "/viam/api/v1/component/button/{name}/do_command"};
}
}

message PushRequest {
string name = 1;
google.protobuf.Struct extra = 99;
}

message PushResponse {}
61 changes: 61 additions & 0 deletions proto/viam/component/switch/v1/switch.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
syntax = "proto3";

package viam.component.switch.v1;

import "common/v1/common.proto";
import "google/api/annotations.proto";
import "google/protobuf/struct.proto";

option go_package = "go.viam.com/api/component/switch/v1";
option java_package = "com.viam.component.switch.v1";

// A SwitchService services switches associated with a machine.
// Switches can have multiple discrete positions - e.g. a simple
// switch has 2 positions, but a knob could have 10 positions.
service SwitchService {
stevebriskin marked this conversation as resolved.
Show resolved Hide resolved
// Set the position of the switch
rpc SetPosition(SetPositionRequest) returns (SetPositionResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/set_position"};
}

// Get the position of the switch
rpc GetPosition(GetPositionRequest) returns (GetPositionResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/get_position"};
}
Comment on lines +17 to +24
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 love these API names, since it's more ambiguous than ToggleTo and ToggleActive but I don't care about this API enough to argue this, and I hope fleet enjoys owning their two new component APIs 😈

Copy link
Member Author

Choose a reason for hiding this comment

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

Like we chatted about, I'm happy to change the names but don't feel strongly. Will leave as-is.

Copy link
Member

Choose a reason for hiding this comment

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

@stevebriskin we'll defer to you here.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, all names are good enough and not worth debating in the interest of speed.


// Get the number of positions that the switch supports
rpc GetNumberOfPositions(GetNumberOfPositionsRequest) returns (GetNumberOfPositionsResponse) {
option (google.api.http) = {put: "/viam/api/v1/component/switch/{name}/get_number_of_positions"};
}

stevebriskin marked this conversation as resolved.
Show resolved Hide resolved
// DoCommand sends/receives arbitrary commands
rpc DoCommand(common.v1.DoCommandRequest) returns (common.v1.DoCommandResponse) {
option (google.api.http) = {post: "/viam/api/v1/component/switch/{name}/do_command"};
}
}

message SetPositionRequest {
string name = 1;
uint32 position = 2;
Copy link
Member

Choose a reason for hiding this comment

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

hmm, do we want to allow negatives too?

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 don't see a reason to - position should just be a non-negative index representing the possible positions. The only case I can think of is if we wanted a negative position to be an error state, but I don't see that being useful. In error cases, the handlers should return errors.

Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking of the most common toggle switch to me - the power drill direction - where that switch makes sense to me as a -1, 0, 1 switch. But meh 🤷🏼‍♀️

google.protobuf.Struct extra = 99;
}

message SetPositionResponse {}

message GetPositionRequest {
string name = 1;
google.protobuf.Struct extra = 99;
}

message GetPositionResponse {
uint32 position = 1;
}

message GetNumberOfPositionsRequest {
string name = 1;
google.protobuf.Struct extra = 99;
}

message GetNumberOfPositionsResponse {
uint32 number_of_positions = 1;
}
Loading