def main():
  parser = get_parser()
  options = parser.parse_args()[0]
  host = options.host
  port = options.port
  cert = options.cert
  if not os.path.isfile(cert):
    generate_cert(cert)

  print 'Initiating pairing...'
  with googletv.PairingProtocol(host, cert, port=port) as gtv:
    client_name = raw_input('Client name: ')
    gtv.send_pairing_request(client_name)
    gtv.recv_pairing_request_ack()
    gtv.send_options()
    gtv.recv_options()
    gtv.send_configuration()
    gtv.recv_configuration_ack()
    code = raw_input('Code from Google TV: ')
    gtv.send_secret(code)

    to_hex = lambda byte_str: ''.join(['%02X' % ord(x) for x in byte_str])
    try:
      secret = to_hex(gtv.recv_secret_ack().secret)
      print 'Success! Received secret (hash) from Google TV: %s' % secret
    except:
      print 'Pairing failed'
dataset/ETHPy150Open stevenle/googletv-anymote/scripts/pair.py/main/original