1"""Blueberry Test Client.
2
3Simple gRPC client to test the Blueberry Mock server.
4"""
5
6from absl import app
7from absl import flags
8
9import grpc
10
11# Internal import
12from blueberry.grpc.proto import blueberry_device_controller_pb2
13from blueberry.grpc.proto import blueberry_device_controller_pb2_grpc
14
15FLAGS = flags.FLAGS
16flags.DEFINE_string('server', 'dns:///[::1]:10000', 'server address')
17
18
19def _UpdateDiscoveryMode(stub, request):
20  try:
21    print('try SetDiscoverableMode')
22    response = stub.SetDiscoverableMode(request)
23    print('complete response')
24    print(response)
25    return 0
26  except grpc.RpcError as rpc_error:
27    print(rpc_error)
28    return -1
29
30
31def main(unused_argv):
32  channel_creds = loas2.loas2_channel_credentials()
33  with grpc.secure_channel(FLAGS.server, channel_creds) as channel:
34    grpc.channel_ready_future(channel).result()
35    stub = blueberry_device_controller_pb2_grpc.BlueberryDeviceControllerStub(
36        channel)
37
38    print('request grpc')
39    request = blueberry_device_controller_pb2.DiscoverableMode(
40        mode=True)
41    print('Call _UpdateDiscoveryMode')
42    return _UpdateDiscoveryMode(stub, request)
43
44
45if __name__ == '__main__':
46  app.run(main)
47