import argparse import subprocess import sys import bluetooth #PyBluez from src.pipewire import Pipewire version = '0.0.0' def bluetooth_scan(args): 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 bluetooth_connect(args): process = subprocess.run(['bluetoothctl', 'connect', args.address], capture_output=True) for line in iter(lambda: process.stdout.read(1), b""): sys.stdout.buffer.write(line); print("%s",process.stderr) def pipewire_list(args): print("ID | Description") print("----------------") sinks = Pipewire.get_sinks() for sink in sinks: print(str(sink['id']) + " | " + sink['info']['props']['node.description']) def pipewire_get_default_sink(args): print("ID | Description") print("----------------") sink = Pipewire.get_default_audio_sink() print(str(sink['id']) + " | " + sink['info']['props']['node.description']) def pipewire_get_volume(args): print(Pipewire.get_volume()) def main(): argparser = argparse.ArgumentParser(description='CarPI CLI.') # Create actions actions = argparser.add_subparsers(title='actions', required=True, dest='action') action_bt_list = actions.add_parser('bluetooth-list', help='list nearby bluetooth devices') action_bt_list.set_defaults(func=bluetooth_scan) action_bt_connect = actions.add_parser('bluetooth-connect', help='connect to a bluetooth device') action_bt_connect.set_defaults(func=bluetooth_connect) action_bt_connect.add_argument('address', help='the bluetooth address of the device to connect to.') action_pw_list = actions.add_parser('pipewire-list', help='list pipewire objects') action_pw_list.set_defaults(func=pipewire_list) action_pw_get_default_sink = actions.add_parser('pipewire-get-default-sink', help='show the default audio sink') action_pw_get_default_sink.set_defaults(func=pipewire_get_default_sink) action_pw_get_volume = actions.add_parser('pipewire-get-volume', help='get volume of the specified device') action_pw_get_volume.set_defaults(func=pipewire_get_volume) args = argparser.parse_args() args.func(args) if (__name__ == "__main__"): sys.exit(main())