From 1a31ef3e65f1d7c112e101e06704dd2dd4a3259e Mon Sep 17 00:00:00 2001 From: VR Date: Tue, 1 Dec 2020 16:21:59 -0800 Subject: [PATCH 1/2] updating field names for 'Group' --- protocol/protocol.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/protocol/protocol.go b/protocol/protocol.go index c666c53..bbdf7c5 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -48,6 +48,7 @@ package protocol import ( "errors" "fmt" + "golang.org/x/net/context" ) @@ -202,9 +203,10 @@ type FlashLightsResponse struct { } type Group struct { - GroupNumber uint8 - Intensity uint8 - Name string + Name string `json:"Name"` + GroupNumber uint8 `json:"Grp"` + Intensity uint8 `json:"Inten"` + Color uint8 `json:"Colr"` } type GroupListAddRequest struct { From 195b8990c566bf88e09e9f078296cbe359299b0d Mon Sep 17 00:00:00 2001 From: VR Date: Tue, 1 Dec 2020 18:01:49 -0800 Subject: [PATCH 2/2] Adding the interface for editing the Group number and Color (name is the key) --- client/client.go | 13 +++++++++++-- protocol/protocol.go | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index 5d00408..60e3bb4 100644 --- a/client/client.go +++ b/client/client.go @@ -6,11 +6,12 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/scottlamb/luxor/protocol" - "golang.org/x/net/context" "io/ioutil" "net/http" "time" + + "github.com/scottlamb/luxor/protocol" + "golang.org/x/net/context" ) // *Controller implements protocol.Controller @@ -172,6 +173,14 @@ func (c *Controller) GroupListRename(ctx context.Context, req *protocol.GroupLis return resp, protocol.ErrorForStatus(resp.Status) } +func (c *Controller) GroupListEdit(ctx context.Context, req *protocol.GroupListEditRequest) (*protocol.GroupListEditResponse, error) { + resp := &protocol.GroupListEditResponse{} + if err := c.request(ctx, "GroupListEdit", req, resp); err != nil { + return nil, err + } + return resp, protocol.ErrorForStatus(resp.Status) +} + func (c *Controller) GroupListReorder(ctx context.Context, req *protocol.GroupListReorderRequest) (*protocol.GroupListReorderResponse, error) { resp := &protocol.GroupListReorderResponse{} if err := c.request(ctx, "GroupListReorder", req, resp); err != nil { diff --git a/protocol/protocol.go b/protocol/protocol.go index bbdf7c5..be38b18 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -89,6 +89,9 @@ type Controller interface { // GroupListRename renames a group. GroupListRename(ctx context.Context, request *GroupListRenameRequest) (response *GroupListRenameResponse, err error) + // GroupListEdit updates a group values (intensity, color). + GroupListEdit(ctx context.Context, request *GroupListEditRequest) (response *GroupListEditResponse, err error) + // GroupListReorder reorders groups. GroupListReorder(ctx context.Context, request *GroupListReorderRequest) (response *GroupListReorderResponse, err error) @@ -260,6 +263,22 @@ type GroupListRenameResponse struct { Status int } +// GroupListEditRequest allows editing/saving of Group number and color assignments +// For updating only the name, use GroupListRename +// For updating all at the same time, call Rename first and (on success), +// use the Name key to then call Edit. +type GroupListEditRequest struct { + Name string + GroupNumber uint8 + Color uint8 +} + +// GroupListEditResponse -- response counterpart +type GroupListEditResponse struct { + // Status will be StatusPreconditionFailed if the name does not exist. + Status int +} + type GroupListReorderRequest struct { // GroupNumbers should be a new order that includes all existing // groups exactly once.