-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsync_interfaces.py
More file actions
executable file
·36 lines (27 loc) · 967 Bytes
/
sync_interfaces.py
File metadata and controls
executable file
·36 lines (27 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python2
import gobject
import dbus
import dbus.mainloop.glib
import os
from systemd import journal
def extract_br_add_as_mac(path):
return ":".join(path.split('/')[-1].split('_')[1:])
def interfaces_added(path, interfaces):
try:
bt_mac = extract_br_add_as_mac(path)
os.system('echo "default-agent\n pair %s\n quit" | bluetoothctl' % bt_mac)
os.system('echo "default-agent\n connect %s\n quit" | bluetoothctl' % bt_mac)
os.system('echo "default-agent\n trust %s\n quit" | bluetoothctl' % bt_mac)
except Exception as e:
journal.write(str(e))
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(
interfaces_added,
bus_name="org.bluez",
dbus_interface="org.freedesktop.DBus.ObjectManager",
signal_name="InterfacesAdded"
)
mainloop = gobject.MainLoop()
mainloop.run()