@@ -279,7 +279,31 @@ def get_device(service_account_json, project_id, cloud_region, registry_id, devi
279
279
client = iot_v1 .DeviceManagerClient ()
280
280
device_path = client .device_path (project_id , cloud_region , registry_id , device_id )
281
281
282
- device = client .get_device (request = {"name" : device_path })
282
+ # See full list of device fields: https://cloud.google.com/iot/docs/reference/cloudiot/rest/v1/projects.locations.registries.devices
283
+ # Warning! Use snake_case field names.
284
+ field_mask = gp_field_mask .FieldMask (
285
+ paths = [
286
+ "id" ,
287
+ "name" ,
288
+ "num_id" ,
289
+ "credentials" ,
290
+ "last_heartbeat_time" ,
291
+ "last_event_time" ,
292
+ "last_state_time" ,
293
+ "last_config_ack_time" ,
294
+ "last_config_send_time" ,
295
+ "blocked" ,
296
+ "last_error_time" ,
297
+ "last_error_status" ,
298
+ "config" ,
299
+ "state" ,
300
+ "log_level" ,
301
+ "metadata" ,
302
+ "gateway_config" ,
303
+ ]
304
+ )
305
+
306
+ device = client .get_device (request = {"name" : device_path , "field_mask" : field_mask })
283
307
284
308
print ("Id : {}" .format (device .id ))
285
309
print ("Name : {}" .format (device .name ))
@@ -345,9 +369,35 @@ def list_devices(service_account_json, project_id, cloud_region, registry_id):
345
369
client = iot_v1 .DeviceManagerClient ()
346
370
registry_path = client .registry_path (project_id , cloud_region , registry_id )
347
371
348
- devices = list (client .list_devices (request = {"parent" : registry_path }))
372
+ # See full list of device fields: https://cloud.google.com/iot/docs/reference/cloudiot/rest/v1/projects.locations.registries.devices
373
+ # Warning! Use snake_case field names.
374
+ field_mask = gp_field_mask .FieldMask (
375
+ paths = [
376
+ "id" ,
377
+ "name" ,
378
+ "num_id" ,
379
+ "credentials" ,
380
+ "last_heartbeat_time" ,
381
+ "last_event_time" ,
382
+ "last_state_time" ,
383
+ "last_config_ack_time" ,
384
+ "last_config_send_time" ,
385
+ "blocked" ,
386
+ "last_error_time" ,
387
+ "last_error_status" ,
388
+ "config" ,
389
+ "state" ,
390
+ "log_level" ,
391
+ "metadata" ,
392
+ "gateway_config" ,
393
+ ]
394
+ )
395
+
396
+ devices = list (
397
+ client .list_devices (request = {"parent" : registry_path , "field_mask" : field_mask })
398
+ )
349
399
for device in devices :
350
- print ("Device: {} : {}" . format ( device . num_id , device . id ) )
400
+ print (device )
351
401
352
402
return devices
353
403
# [END iot_list_devices]
@@ -373,7 +423,7 @@ def list_registries(service_account_json, project_id, cloud_region):
373
423
def create_registry (
374
424
service_account_json , project_id , cloud_region , pubsub_topic , registry_id
375
425
):
376
- """ Creates a registry and returns the result. Returns an empty result if
426
+ """Creates a registry and returns the result. Returns an empty result if
377
427
the registry already exists."""
378
428
# [START iot_create_registry]
379
429
# project_id = 'YOUR_PROJECT_ID'
0 commit comments