@@ -69,7 +69,7 @@ def get_client(service_account_json, api_key):
69
69
provided API key and creating a service object using the service account
70
70
credentials JSON."""
71
71
api_scopes = ['https://www.googleapis.com/auth/cloud-platform' ]
72
- api_version = 'v1beta1 '
72
+ api_version = 'v1 '
73
73
discovery_api = 'https://cloudiot.googleapis.com/$discovery/rest'
74
74
service_name = 'cloudiotcore'
75
75
@@ -216,6 +216,23 @@ def get_device(
216
216
return device
217
217
218
218
219
+ def get_state (
220
+ service_account_json , api_key , project_id , cloud_region , registry_id ,
221
+ device_id ):
222
+ """Retrieve a device's state blobs."""
223
+ client = get_client (service_account_json , api_key )
224
+ registry_name = 'projects/{}/locations/{}/registries/{}' .format (
225
+ project_id , cloud_region , registry_id )
226
+
227
+ device_name = '{}/devices/{}' .format (registry_name , device_id )
228
+ devices = client .projects ().locations ().registries ().devices ()
229
+ state = devices .states ().list (name = device_name , numStates = 5 ).execute ()
230
+
231
+ print ('State: {}\n ' .format (state ))
232
+
233
+ return state
234
+
235
+
219
236
def list_devices (
220
237
service_account_json , api_key , project_id , cloud_region , registry_id ):
221
238
"""List all devices in the registry."""
@@ -274,6 +291,8 @@ def create_registry(
274
291
print ('Created registry' )
275
292
return response
276
293
except HttpError :
294
+ print (dir (HttpError ))
295
+ print ('Error {}' .format (HttpError ))
277
296
return ""
278
297
279
298
@@ -425,7 +444,8 @@ def parse_command_line_args():
425
444
command .add_parser ('delete-device' , help = delete_device .__doc__ )
426
445
command .add_parser ('delete-registry' , help = delete_registry .__doc__ )
427
446
command .add_parser ('get' , help = get_device .__doc__ )
428
- command .add_parser ('get-registry' , help = get_device .__doc__ )
447
+ command .add_parser ('get-registry' , help = get_registry .__doc__ )
448
+ command .add_parser ('get-state' , help = get_state .__doc__ )
429
449
command .add_parser ('list' , help = list_devices .__doc__ )
430
450
command .add_parser ('list-registries' , help = list_registries .__doc__ )
431
451
command .add_parser ('patch-es256' , help = patch_es256_auth .__doc__ )
@@ -436,6 +456,10 @@ def parse_command_line_args():
436
456
437
457
def run_command (args ):
438
458
"""Calls the program using the specified command."""
459
+ if args .project_id is None :
460
+ print ("You must specify a project ID or set the environment variable." )
461
+ return
462
+
439
463
if args .command == 'create-rsa256' :
440
464
create_rs256_device (
441
465
args .service_account_json , args .api_key , args .project_id ,
@@ -476,6 +500,11 @@ def run_command(args):
476
500
args .service_account_json , args .api_key , args .project_id ,
477
501
args .cloud_region , args .registry_id , args .device_id )
478
502
503
+ elif args .command == 'get-state' :
504
+ get_state (
505
+ args .service_account_json , args .api_key , args .project_id ,
506
+ args .cloud_region , args .registry_id , args .device_id )
507
+
479
508
elif args .command == 'list' :
480
509
list_devices (
481
510
args .service_account_json , args .api_key , args .project_id ,
0 commit comments