Skip to content

Commit 824688c

Browse files
authored
Merge pull request #974 from cloudxxx8/issue-870
refactor!: Clean up command client lib
2 parents 658ac86 + ebecdaf commit 824688c

File tree

4 files changed

+49
-55
lines changed

4 files changed

+49
-55
lines changed

clients/http/command.go

+1-16
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,7 @@ func (client *CommandClient) IssueGetCommandByNameWithQueryParams(ctx context.Co
114114
}
115115

116116
// IssueSetCommandByName issues the specified write command referenced by the command name to the device/sensor that is also referenced by name.
117-
func (client *CommandClient) IssueSetCommandByName(ctx context.Context, deviceName string, commandName string, settings map[string]string) (res dtoCommon.BaseResponse, err errors.EdgeX) {
118-
requestPath := common.NewPathBuilder().EnableNameFieldEscape(client.enableNameFieldEscape).
119-
SetPath(common.ApiDeviceRoute).SetPath(common.Name).SetNameFieldPath(deviceName).SetNameFieldPath(commandName).BuildPath()
120-
baseUrl, goErr := clients.GetBaseUrl(client.baseUrlFunc)
121-
if goErr != nil {
122-
return res, errors.NewCommonEdgeXWrapper(goErr)
123-
}
124-
err = utils.PutRequest(ctx, &res, baseUrl, requestPath, nil, settings, client.authInjector)
125-
if err != nil {
126-
return res, errors.NewCommonEdgeXWrapper(err)
127-
}
128-
return res, nil
129-
}
130-
131-
// IssueSetCommandByNameWithObject issues the specified write command and the settings supports object value type
132-
func (client *CommandClient) IssueSetCommandByNameWithObject(ctx context.Context, deviceName string, commandName string, settings map[string]interface{}) (res dtoCommon.BaseResponse, err errors.EdgeX) {
117+
func (client *CommandClient) IssueSetCommandByName(ctx context.Context, deviceName string, commandName string, settings map[string]any) (res dtoCommon.BaseResponse, err errors.EdgeX) {
133118
requestPath := common.NewPathBuilder().EnableNameFieldEscape(client.enableNameFieldEscape).
134119
SetPath(common.ApiDeviceRoute).SetPath(common.Name).SetNameFieldPath(deviceName).SetNameFieldPath(commandName).BuildPath()
135120
baseUrl, goErr := clients.GetBaseUrl(client.baseUrlFunc)

clients/http/command_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestIssueGetCommandByNameWithQueryParams(t *testing.T) {
8585
func TestIssueIssueSetCommandByName(t *testing.T) {
8686
deviceName := "Simple-Device01"
8787
cmdName := "SwitchButton"
88-
settings := map[string]string{
88+
settings := map[string]any{
8989
"SwitchButton": "true",
9090
}
9191
path := common.NewPathBuilder().EnableNameFieldEscape(false).
@@ -101,8 +101,8 @@ func TestIssueIssueSetCommandByName(t *testing.T) {
101101
func TestIssueIssueSetCommandByNameWithObject(t *testing.T) {
102102
deviceName := "Simple-Device01"
103103
cmdName := "SwitchButton"
104-
settings := map[string]interface{}{
105-
"SwitchButton": map[string]interface{}{
104+
settings := map[string]any{
105+
"SwitchButton": map[string]any{
106106
"kind": "button",
107107
"value": "on",
108108
},
@@ -112,7 +112,7 @@ func TestIssueIssueSetCommandByNameWithObject(t *testing.T) {
112112
ts := newTestServer(http.MethodPut, path, dtoCommon.BaseResponse{})
113113
defer ts.Close()
114114
client := NewCommandClient(ts.URL, NewNullAuthenticationInjector(), false)
115-
res, err := client.IssueSetCommandByNameWithObject(context.Background(), deviceName, cmdName, settings)
115+
res, err := client.IssueSetCommandByName(context.Background(), deviceName, cmdName, settings)
116116
require.NoError(t, err)
117117
require.IsType(t, dtoCommon.BaseResponse{}, res)
118118
}

clients/interfaces/command.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,5 @@ type CommandClient interface {
2929
// IssueGetCommandByNameWithQueryParams issues the specified read command by deviceName and commandName with additional query parameters.
3030
IssueGetCommandByNameWithQueryParams(ctx context.Context, deviceName string, commandName string, queryParams map[string]string) (*responses.EventResponse, errors.EdgeX)
3131
// IssueSetCommandByName issues the specified write command referenced by the command name to the device/sensor that is also referenced by name.
32-
IssueSetCommandByName(ctx context.Context, deviceName string, commandName string, settings map[string]string) (common.BaseResponse, errors.EdgeX)
33-
// IssueSetCommandByNameWithObject issues the specified write command and the settings supports object value type
34-
IssueSetCommandByNameWithObject(ctx context.Context, deviceName string, commandName string, settings map[string]interface{}) (common.BaseResponse, errors.EdgeX)
32+
IssueSetCommandByName(ctx context.Context, deviceName string, commandName string, settings map[string]any) (common.BaseResponse, errors.EdgeX)
3533
}

clients/interfaces/mocks/CommandClient.go

+43-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)