aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyagl/services/bluetooth.py73
1 files changed, 67 insertions, 6 deletions
diff --git a/pyagl/services/bluetooth.py b/pyagl/services/bluetooth.py
index a5785df..1755cba 100644
--- a/pyagl/services/bluetooth.py
+++ b/pyagl/services/bluetooth.py
@@ -16,6 +16,8 @@
from pyagl.services.base import AGLBaseService, AFBResponse
import asyncio
import os
+import json
+
Verbs = ['subscribe', 'unsubscribe', 'managed_objects', 'adapter_state', 'default_adapter', 'avrcp_controls',
'connect', 'disconnect', 'pair', 'cancel_pairing', 'confirm_pairing', 'remove_device']
@@ -27,16 +29,18 @@ 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('--get_default_adapter', help='Get default bluetooth adapter', action='store_true')
+ parser.add_argument('--set_default_adapter', help='Set default bluetooth adapter')
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('--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('--confirm_pairing',metavar='pincode')
parser.add_argument('--remove_device', metavar='dev_88_0F_10_96_D3_20', help='Remove paired device')
+ parser.add_argument('--avrcp_controls')
def __init__(self, ip, port=None, service='agl-service-bluetooth'):
super().__init__(api='Bluetooth-Manager', ip=ip, port=port, service=service)
@@ -90,14 +94,71 @@ async def main(loop):
args = BluetoothService.parser.parse_args()
bts = await BluetoothService(ip=args.ipaddr, port=args.port)
- if args.default_adapter:
+ if args.get_default_adapter:
msgid = await bts.default_adapter()
- print(f'Requesting default adapter with id {msgid}')
+ print(f'Requesting get default adapter with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.set_default_adapter:
+ msgid = await bts.default_adapter(args.set_default_adapter)
+ print(f'Requesting set default adapter with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.managed_objects:
+ msgid = await bts.managed_objects()
+ print(f'Requesting managed objects with id {msgid}')
r = await bts.afbresponse()
print(r)
if args.adapter_state:
- pass
+ msgid = await bts.adapter_state(args.adapter_state)
+ print(f'Requesting adapter state with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.connect:
+ msgid = await bts.connect(args.connect)
+ print(f'Requesting connect with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.disconnect:
+ msgid = await bts.disconnect(args.disconnect)
+ print(f'Requesting disconnect with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.pair:
+ msgid = await bts.pair(args.pair)
+ print(f'Requesting pair with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.cancel_pairing:
+ msgid = await bts.cancel_pairing()
+ print(f'Requesting cancel pairing with id {msgid}')
+ r = await bts.afbresponse()
+
+ if args.confirm_pairing:
+ msgid = await bts.confirm_pairing(args.confirm_pairing)
+ print(f'Requesting confirm pairing with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.remove_device:
+ msgid = await bts.remove_device(args.remove_device)
+ print(f'Requesting remove device with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
+ if args.avrcp_controls:
+ msgid = await bts.avrcp_controls(args.avrcp_controls)
+ print(f'Requesting avrcp controls with id {msgid}')
+ r = await bts.afbresponse()
+ print(r)
+
if args.listener:
for response in bts.listener():