CarPi/main.py
minecraftchest1@outlook.com ee442e01b2 Add argparse
2025-04-01 10:15:07 -05:00

31 lines
No EOL
898 B
Python

import argparse
import sys
import bluetooth #PyBluez
version = '0.0.0'
def bluetooth_scan():
print('Discovering Bluetooth Devices...')
nearby_devices = bluetooth.discover_devices(duration=10, lookup_names=True, flush_cache=True, lookup_class=False)
print('Discovered {} devices:'.format(len(nearby_devices)))
for device in nearby_devices:
print(f'{device[0]}\t{device[1]}')
def main():
argparser = argparse.ArgumentParser(description='CarPI CLI.')
# Create actions
actions = argparser.add_subparsers(title='actions', required=True)
action_list = actions.add_parser('list', help='list nearby bluetooth devices')
action_list.set_defaults(func=bluetooth_scan)
action_connect = actions.add_parser('connect', help='connect to a bluetooth device')
args = argparser.parse_args()
print(args)
args.func()
if (__name__ == "__main__"):
sys.exit(main())