Skip to content

Commit

Permalink
Merge pull request #782 from jinlinGuan/issue-780
Browse files Browse the repository at this point in the history
refactor!: Use true/false for command parameters to be more consistent
  • Loading branch information
cloudxxx8 authored Jan 12, 2023
2 parents 7e0c83d + a2a49d7 commit 8b66e6c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions clients/http/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (client *CommandClient) DeviceCoreCommandsByDeviceName(ctx context.Context,
}

// IssueGetCommandByName issues the specified read command referenced by the command name to the device/sensor that is also referenced by name.
func (client *CommandClient) IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent string, dsReturnEvent string) (res *responses.EventResponse, err errors.EdgeX) {
func (client *CommandClient) IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent bool, dsReturnEvent bool) (res *responses.EventResponse, err errors.EdgeX) {
requestParams := url.Values{}
requestParams.Set(common.PushEvent, dsPushEvent)
requestParams.Set(common.ReturnEvent, dsReturnEvent)
requestParams.Set(common.PushEvent, strconv.FormatBool(dsPushEvent))
requestParams.Set(common.ReturnEvent, strconv.FormatBool(dsReturnEvent))
requestPath := path.Join(common.ApiDeviceRoute, common.Name, deviceName, commandName)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion clients/http/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httptest"
"path"
"strconv"
"testing"

"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
Expand Down Expand Up @@ -47,7 +48,11 @@ func TestIssueGetCommandByName(t *testing.T) {
ts := newTestServer(http.MethodGet, path, &responses.EventResponse{})
defer ts.Close()
client := NewCommandClient(ts.URL)
res, err := client.IssueGetCommandByName(context.Background(), deviceName, cmdName, common.ValueYes, common.ValueNo)
pushEvent, err := strconv.ParseBool(common.ValueTrue)
require.NoError(t, err)
notReturnEvent, err := strconv.ParseBool(common.ValueFalse)
require.NoError(t, err)
res, err := client.IssueGetCommandByName(context.Background(), deviceName, cmdName, pushEvent, notReturnEvent)
require.NoError(t, err)
require.IsType(t, &responses.EventResponse{}, res)
}
Expand Down
6 changes: 3 additions & 3 deletions clients/interfaces/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type CommandClient interface {
// DeviceCoreCommandsByDeviceName returns all commands associated with the specified device name.
DeviceCoreCommandsByDeviceName(ctx context.Context, deviceName string) (responses.DeviceCoreCommandResponse, errors.EdgeX)
// IssueGetCommandByName issues the specified read command referenced by the command name to the device/sensor that is also referenced by name.
// dsPushEvent: If set to yes, a successful GET will result in an event being pushed to the EdgeX system. Default value is no.
// dsReturnEvent: If set to no, there will be no Event returned in the http response. Default value is yes.
IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent string, dsReturnEvent string) (*responses.EventResponse, errors.EdgeX)
// dsPushEvent: If set to true, a successful GET will result in an event being pushed to the EdgeX system. Default value is false.
// dsReturnEvent: If set to false, there will be no Event returned in the http response. Default value is true.
IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent bool, dsReturnEvent bool) (*responses.EventResponse, errors.EdgeX)
// IssueGetCommandByNameWithQueryParams issues the specified read command by deviceName and commandName with additional query parameters.
IssueGetCommandByNameWithQueryParams(ctx context.Context, deviceName string, commandName string, queryParams map[string]string) (*responses.EventResponse, errors.EdgeX)
// IssueSetCommandByName issues the specified write command referenced by the command name to the device/sensor that is also referenced by name.
Expand Down
2 changes: 0 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ const (
DefaultOffset = 0
DefaultLimit = 20
CommaSeparator = ","
ValueYes = "yes"
ValueNo = "no"
ValueTrue = "true"
ValueFalse = "false"
)
Expand Down

0 comments on commit 8b66e6c

Please sign in to comment.