aboutsummaryrefslogtreecommitdiffstats
path: root/bluetooth.py
diff options
context:
space:
mode:
Diffstat (limited to 'bluetooth.py')
-rw-r--r--bluetooth.py42
1 files changed, 34 insertions, 8 deletions
diff --git a/bluetooth.py b/bluetooth.py
index a4bbac3..658d2e7 100644
--- a/bluetooth.py
+++ b/bluetooth.py
@@ -1,14 +1,29 @@
-from aglbaseservice import AGLBaseService
+from aglbaseservice import AGLBaseService, AFBResponse
import asyncio
import os
Verbs = ['subscribe', 'unsubscribe', 'managed_objects', 'adapter_state', 'default_adapter', 'avrcp_controls',
'connect', 'disconnect', 'pair', 'cancel_pairing', 'confirm_pairing', 'remove_device']
AdapterStateParams = ['discovery', 'discoverable', 'powered', ]
+
BTEventType = ['adapter_changes', 'device_changes', 'media', 'agent']
class BluetoothService(AGLBaseService):
+ service = 'agl-service-bluetooth'
+ parser = AGLBaseService.getparser()
+ parser.add_argument('--default_adapter', help='Get default bluetooth adapter', action='store_true')
+ parser.add_argument('--managed_objects', help='Get managed objects', action='store_true')
+ parser.add_argument('--adapter', help='Select remote adapter', required=False, default='hci0')
+ parser.add_argument('--adapter_state')
+ parser.add_argument('--connect', help='Connect to device', metavar='dev_88_0F_10_96_D3_20')
+ parser.add_argument('--disconnect', help='Disconnect from device', metavar='dev_88_0F_10_96_D3_20')
+ parser.add_argument('--pair', help='Pair with a device', metavar='dev_88_0F_10_96_D3_20')
+ parser.add_argument('--cancel_pairing', help='Cancel ongoing pairing')
+ parser.add_argument('--confirm_pairing', metavar='pincode')
+ parser.add_argument('--remove_device', metavar='dev_88_0F_10_96_D3_20', help='Remove paired device')
+
+
def __init__(self, ip, port=None, service='agl-service-bluetooth'):
super().__init__(api='Bluetooth-Manager', ip=ip, port=port, service=service)
@@ -53,13 +68,24 @@ class BluetoothService(AGLBaseService):
pass
async def main(loop):
- addr = os.environ.get('AGL_TGT_IP', 'localhost')
- port = os.environ.get('AGL_TGT_PORT', None)
- BTS = await BluetoothService(ip=addr, service='agl-service-bluetooth', port=port)
- listener = loop.create_task(BTS.listener())
- await BTS.subscribe()
- BTS.logger.debug(await BTS.adapter_state('hci0', {'uuids': ['0000110e-0000-1000-8000-00805f9b34fb']}))
- await listener
+ args = BluetoothService.parser.parse_args()
+ bts = await BluetoothService(ip=args.ipaddr, port=args.port)
+
+ if args.default_adapter:
+ id = await bts.default_adapter()
+ print(f'Requesting default adapter with id {id}')
+ r = AFBResponse(await bts.response())
+ print(r)
+
+ if args.adapter_state:
+ pass
+
+ if args.listener:
+ for response in bts.listener():
+ print(response)
+
+ bts.logger.debug(await bts.adapter_state('hci0', {'uuids': ['0000110e-0000-1000-8000-00805f9b34fb']}))
+
if __name__ == '__main__':