@@ -142,22 +142,22 @@ def create_device(
142142 service_account_json , project_id , cloud_region , registry_id ,
143143 device_id ):
144144 """Create a device to bind to a gateway if it does not exist."""
145- # [START create_device ]
145+ # [START iot_create_device ]
146146 # Check that the device doesn't already exist
147147 exists = False
148148
149149 client = get_client (service_account_json )
150150 registry_path = 'projects/{}/locations/{}/registries/{}' .format (
151- project_id , cloud_region , registry_id )
151+ project_id , cloud_region , registry_id )
152152
153153 devices = client .projects ().locations ().registries ().devices (
154- ).list (
155- parent = registry_path , fieldMask = 'config,gatewayConfig'
156- ).execute ().get ('devices' , [])
154+ ).list (
155+ parent = registry_path , fieldMask = 'config,gatewayConfig'
156+ ).execute ().get ('devices' , [])
157157
158158 for device in devices :
159- if device .get ('id' ) == device_id :
160- exists = True
159+ if device .get ('id' ) == device_id :
160+ exists = True
161161
162162 # Create the device
163163 registry_name = 'projects/{}/locations/{}/registries/{}' .format (
@@ -178,7 +178,7 @@ def create_device(
178178 print ('Created Device {}' .format (res ))
179179 else :
180180 print ('Device exists, skipping' )
181- # [END create_device ]
181+ # [END iot_create_device ]
182182
183183
184184def create_unauth_device (
@@ -295,9 +295,9 @@ def list_devices(
295295 ).list (parent = registry_path ).execute ().get ('devices' , [])
296296
297297 for device in devices :
298- print ('Device: {} : {}' .format (
299- device .get ('numId' ),
300- device .get ('id' )))
298+ print ('Device: {} : {}' .format (
299+ device .get ('numId' ),
300+ device .get ('id' )))
301301
302302 return devices
303303 # [END iot_list_devices]
@@ -314,9 +314,9 @@ def list_registries(service_account_json, project_id, cloud_region):
314314 parent = registry_path ).execute ().get ('deviceRegistries' , [])
315315
316316 for registry in registries :
317- print ('id: {}\n \t name: {}' .format (
318- registry .get ('id' ),
319- registry .get ('name' )))
317+ print ('id: {}\n \t name: {}' .format (
318+ registry .get ('id' ),
319+ registry .get ('name' )))
320320
321321 return registries
322322 # [END iot_list_registries]
@@ -375,7 +375,7 @@ def open_registry(
375375 service_account_json , project_id , cloud_region ,
376376 pubsub_topic , registry_id )
377377
378- if ( response is "" ) :
378+ if response == "" :
379379 # Device registry already exists
380380 print (
381381 'Registry {} already exists - looking it up instead.' .format (
@@ -559,7 +559,7 @@ def create_gateway(
559559 service_account_json , project_id , cloud_region , registry_id , device_id ,
560560 gateway_id , certificate_file , algorithm ):
561561 """Create a gateway to bind devices to."""
562- # [START create_gateway ]
562+ # [START iot_create_gateway ]
563563 # Check that the gateway doesn't already exist
564564 exists = False
565565 client = get_client (service_account_json )
@@ -572,14 +572,14 @@ def create_gateway(
572572 ).execute ().get ('devices' , [])
573573
574574 for device in devices :
575- if device .get ('id' ) == gateway_id :
576- exists = True
577- print ('Device: {} : {} : {} : {}' .format (
578- device .get ('id' ),
579- device .get ('numId' ),
580- device .get ('config' ),
581- device .get ('gatewayConfig' )
582- ))
575+ if device .get ('id' ) == gateway_id :
576+ exists = True
577+ print ('Device: {} : {} : {} : {}' .format (
578+ device .get ('id' ),
579+ device .get ('numId' ),
580+ device .get ('config' ),
581+ device .get ('gatewayConfig' )
582+ ))
583583
584584 # Create the gateway
585585 registry_name = 'projects/{}/locations/{}/registries/{}' .format (
@@ -615,14 +615,14 @@ def create_gateway(
615615 print ('Created gateway {}' .format (res ))
616616 else :
617617 print ('Gateway exists, skipping' )
618- # [END create_gateway ]
618+ # [END iot_create_gateway ]
619619
620620
621621def bind_device_to_gateway (
622622 service_account_json , project_id , cloud_region , registry_id , device_id ,
623623 gateway_id ):
624624 """Binds a device to a gateway."""
625- # [START bind_device_to_gateway ]
625+ # [START iot_bind_device_to_gateway ]
626626 client = get_client (service_account_json )
627627
628628 create_device (
@@ -638,14 +638,14 @@ def bind_device_to_gateway(
638638 client .projects ().locations ().registries ().bindDeviceToGateway (
639639 parent = registry_name , body = bind_request ).execute ()
640640 print ('Device Bound!' )
641- # [END bind_device_to_gateway ]
641+ # [END iot_bind_device_to_gateway ]
642642
643643
644644def unbind_device_from_gateway (
645645 service_account_json , project_id , cloud_region , registry_id , device_id ,
646646 gateway_id ):
647647 """Unbinds a device to a gateway."""
648- # [START unbind_device_from_gateway ]
648+ # [START iot_unbind_device_from_gateway ]
649649 client = get_client (service_account_json )
650650
651651 registry_name = 'projects/{}/locations/{}/registries/{}' .format (
@@ -658,13 +658,13 @@ def unbind_device_from_gateway(
658658 res = client .projects ().locations ().registries ().unbindDeviceFromGateway (
659659 parent = registry_name , body = bind_request ).execute ()
660660 print ('Device unbound: {}' .format (res ))
661- # [END unbind_device_from_gateway ]
661+ # [END iot_unbind_device_from_gateway ]
662662
663663
664664def list_gateways (
665665 service_account_json , project_id , cloud_region , registry_id ):
666666 """Lists gateways in a registry"""
667- # [START list_gateways ]
667+ # [START iot_list_gateways ]
668668 client = get_client (service_account_json )
669669 registry_path = 'projects/{}/locations/{}/registries/{}' .format (
670670 project_id , cloud_region , registry_id )
@@ -678,14 +678,14 @@ def list_gateways(
678678 if device .get ('gatewayConfig' ) is not None :
679679 if device .get ('gatewayConfig' ).get ('gatewayType' ) == 'GATEWAY' :
680680 print ('Gateway ID: {}\n \t {}' .format (device .get ('id' ), device ))
681- # [END list_gateways ]
681+ # [END iot_list_gateways ]
682682
683683
684684def list_devices_for_gateway (
685685 service_account_json , project_id , cloud_region , registry_id ,
686686 gateway_id ):
687687 """List devices bound to a gateway"""
688- # [START list_devices_for_gateway ]
688+ # [START iot_list_devices_for_gateway ]
689689 client = get_client (service_account_json )
690690
691691 registry_name = 'projects/{}/locations/{}/registries/{}' .format (
@@ -715,7 +715,7 @@ def list_devices_for_gateway(
715715 else :
716716 if not found :
717717 print ('No devices bound to gateway {}' .format (gateway_id ))
718- # [END list_devices_for_gateway ]
718+ # [END iot_list_devices_for_gateway ]
719719
720720
721721def parse_command_line_args ():
0 commit comments