@@ -30,7 +30,7 @@ import (
30
30
type Client interface {
31
31
DeviceCreate (fqbn , name , serial , devType string ) (* iotclient.ArduinoDevicev2 , error )
32
32
DeviceDelete (id string ) error
33
- DeviceList () ([]iotclient.ArduinoDevicev2 , error )
33
+ DeviceList (tags map [ string ] string ) ([]iotclient.ArduinoDevicev2 , error )
34
34
DeviceShow (id string ) (* iotclient.ArduinoDevicev2 , error )
35
35
DeviceOTA (id string , file * os.File , expireMins int ) error
36
36
DeviceTagsCreate (id string , tags map [string ]string ) error
@@ -40,7 +40,7 @@ type Client interface {
40
40
ThingUpdate (id string , thing * iotclient.Thing , force bool ) error
41
41
ThingDelete (id string ) error
42
42
ThingShow (id string ) (* iotclient.ArduinoThing , error )
43
- ThingList (ids []string , device * string , props bool ) ([]iotclient.ArduinoThing , error )
43
+ ThingList (ids []string , device * string , props bool , tags map [ string ] string ) ([]iotclient.ArduinoThing , error )
44
44
ThingTagsCreate (id string , tags map [string ]string ) error
45
45
ThingTagsDelete (id string , keys []string ) error
46
46
DashboardCreate (dashboard * iotclient.Dashboardv2 ) (* iotclient.ArduinoDashboardv2 , error )
@@ -96,8 +96,18 @@ func (cl *client) DeviceDelete(id string) error {
96
96
97
97
// DeviceList retrieves and returns a list of all Arduino IoT Cloud devices
98
98
// belonging to the user performing the request.
99
- func (cl * client ) DeviceList () ([]iotclient.ArduinoDevicev2 , error ) {
100
- devices , _ , err := cl .api .DevicesV2Api .DevicesV2List (cl .ctx , nil )
99
+ func (cl * client ) DeviceList (tags map [string ]string ) ([]iotclient.ArduinoDevicev2 , error ) {
100
+ opts := & iotclient.DevicesV2ListOpts {}
101
+ if tags != nil {
102
+ t := make ([]string , 0 , len (tags ))
103
+ for key , val := range tags {
104
+ // Use the 'key:value' format required from the backend
105
+ t = append (t , key + ":" + val )
106
+ }
107
+ opts .Tags = optional .NewInterface (t )
108
+ }
109
+
110
+ devices , _ , err := cl .api .DevicesV2Api .DevicesV2List (cl .ctx , opts )
101
111
if err != nil {
102
112
err = fmt .Errorf ("listing devices: %w" , errorDetail (err ))
103
113
return nil , err
@@ -216,7 +226,7 @@ func (cl *client) ThingShow(id string) (*iotclient.ArduinoThing, error) {
216
226
}
217
227
218
228
// ThingList returns a list of things on Arduino IoT Cloud.
219
- func (cl * client ) ThingList (ids []string , device * string , props bool ) ([]iotclient.ArduinoThing , error ) {
229
+ func (cl * client ) ThingList (ids []string , device * string , props bool , tags map [ string ] string ) ([]iotclient.ArduinoThing , error ) {
220
230
opts := & iotclient.ThingsV2ListOpts {}
221
231
opts .ShowProperties = optional .NewBool (props )
222
232
@@ -228,6 +238,15 @@ func (cl *client) ThingList(ids []string, device *string, props bool) ([]iotclie
228
238
opts .DeviceId = optional .NewString (* device )
229
239
}
230
240
241
+ if tags != nil {
242
+ t := make ([]string , 0 , len (tags ))
243
+ for key , val := range tags {
244
+ // Use the 'key:value' format required from the backend
245
+ t = append (t , key + ":" + val )
246
+ }
247
+ opts .Tags = optional .NewInterface (t )
248
+ }
249
+
231
250
things , _ , err := cl .api .ThingsV2Api .ThingsV2List (cl .ctx , opts )
232
251
if err != nil {
233
252
err = fmt .Errorf ("retrieving things, %w" , errorDetail (err ))
0 commit comments