summaryrefslogtreecommitdiff
path: root/test/test-manager
blob: 3fa7205a04b6a1dcd430abd1fdbcab21dd8b4e96 (plain)
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
37
38
39
40
41
42
#!/usr/bin/python
# SPDX-License-Identifier: LGPL-2.1-or-later

from __future__ import absolute_import, print_function, unicode_literals

import dbus
import dbus.mainloop.glib
try:
  from gi.repository import GObject
except ImportError:
  import gobject as GObject
import bluezutils

def interfaces_added(path, interfaces):
	if interfaces.get("org.bluez.Adapter1") != None:
		print("Adapter with path %s added" % (path))

def interfaces_removed(path, interfaces):
	if "org.bluez.Adapter1" in interfaces:
		print("Adapter with path %s removed" % (path))

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")

	bus.add_signal_receiver(interfaces_removed, bus_name="org.bluez",
			dbus_interface="org.freedesktop.DBus.ObjectManager",
			signal_name="InterfacesRemoved")

	try:
		path = bluezutils.find_adapter().object_path
		print("Adapter found at path %s" % (path))
	except:
		print("No adapter found")

	mainloop = GObject.MainLoop()
	mainloop.run()