Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit 8e1574c

Browse files
committed
google-assistant-sdk/pushtotalk: improve registration messages
- print device id - better error handling - proper exit code on error Bug: 70396802 Change-Id: I1eda9d3195c036383b6ec88b4dcf99a045713914
1 parent fd15f15 commit 8e1574c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

google-assistant-sdk/googlesamples/assistant/grpc/pushtotalk.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import logging
2020
import os
2121
import os.path
22+
import sys
2223
import uuid
2324

2425
import click
@@ -307,7 +308,7 @@ def main(api_endpoint, credentials, project,
307308
logging.error('Error loading credentials: %s', e)
308309
logging.error('Run google-oauthlib-tool to initialize '
309310
'new OAuth 2.0 credentials.')
310-
return
311+
sys.exit(-1)
311312

312313
# Create an authorized gRPC channel.
313314
grpc_channel = google.auth.transport.grpc.secure_authorized_channel(
@@ -370,12 +371,16 @@ def onoff(on):
370371
device_id = device['id']
371372
device_model_id = device['model_id']
372373
except Exception as e:
373-
logging.error('Error loading device config: %s' % e)
374+
logging.warning('Device config not found: %s' % e)
374375
logging.info('Registering device')
375376
if not device_model_id:
376-
logging.error('--device-model-id parameter required '
377+
logging.error('Option --device-model-id required '
377378
'when registrering a model.')
378-
return
379+
sys.exit(-1)
380+
if not project:
381+
logging.error('Option --project required '
382+
'when registrering a model.')
383+
sys.exit(-1)
379384
device_base_url = (
380385
'https://%s/v1alpha2/projects/%s/devices' % (api_endpoint,
381386
project)
@@ -391,7 +396,8 @@ def onoff(on):
391396
r = session.post(device_base_url, data=json.dumps(payload))
392397
if r.status_code != 200:
393398
logging.error('Failed to register device: %s', r.text)
394-
return
399+
sys.exit(-1)
400+
logging.info('Device registered: %s', device_id)
395401
os.makedirs(os.path.dirname(device_config), exist_ok=True)
396402
with open(device_config, 'w') as f:
397403
json.dump(payload, f)

0 commit comments

Comments
 (0)