Python Forum
QtDBus: how to call GetManagedObjects from bluez - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: GUI (
+--- Thread: QtDBus: how to call GetManagedObjects from bluez (/Thread-QtDBus-how-to-call-GetManagedObjects-from-bluez)

QtDBus: how to call GetManagedObjects from bluez - Alfalfa - Jul-15-2018

I want to list and extract all trusted bluetooth device by using QtDbus. With the qdbusviewer tool, I can see and call the method GetManagedObjects() just fine. Then I tried to do it in python, but the method cannot be found. The script below output ['Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn\'t exist']. What am I doing wrong?

import sys
from PyQt5 import QtWidgets, QtDBus

class Main(QtWidgets.QMainWindow):
    def __init__(self):
        bus = QtDBus.QDBusConnection.systemBus()
        interface = QtDBus.QDBusInterface("org.bluez", "/org/bluez", "org.freedesktop.DBus.ObjectManager", bus)
        result ="GetManagedObjects")

if __name__== '__main__':
    app = QtWidgets.QApplication([])
    gui = Main()

RE: QtDBus: how to call GetManagedObjects from bluez - Alfalfa - Sep-16-2018

In case anyone would like to do something similar, here is how I've done it. It list all bluetooth nodes and it's trusted devices. As read here, the trick was to use freedesktop interface to use the Get method on org.bluez.Device1.

import sys
import xml.etree.ElementTree as ET
from PyQt5 import QtCore, QtGui, QtWidgets, QtDBus

class Main(QtCore.QObject):
    def __init__(self):

    def _bluezEnumerate(self):
        service = "org.bluez"
        root = "/org/bluez"
        interface = "org.freedesktop.DBus.Properties"
        bus = QtDBus.QDBusConnection.systemBus()
        nodes = self._bluezNodes()
        for hci in nodes:
            for node in nodes[hci]:
                path = f"{root}/{hci}/{node}"
                connection = QtDBus.QDBusInterface(service, path, interface, bus)
                name ="Get", "org.bluez.Device1", "Name").arguments()[0]
                address ="Get", "org.bluez.Device1", "Address").arguments()[0]
                print(f"{address} {name}")

    def _bluezNodes(self):
        service = "org.bluez"
        path = "/org/bluez"
        interface = "org.freedesktop.DBus.Introspectable"
        bus = QtDBus.QDBusConnection.systemBus()
        connection = QtDBus.QDBusInterface(service, path, interface, bus)
        hciNodes = ET.fromstring("Introspect").arguments()[0])

        nodes = {}
        for node in hciNodes.iter("node"):
            if node.attrib:
                hci = node.attrib["name"]
                connection = QtDBus.QDBusInterface(service, f"{path}/{hci}", interface, bus)
                devNodes = ET.fromstring("Introspect").arguments()[0])
                nodes[hci] = []
                for device in devNodes.iter("node"):
                    if device.attrib:
        return nodes

if __name__== '__main__':
    app = QtWidgets.QApplication([])
    daemon = Main()
hci0 00:1B:XX:DF:XX:A4 PLAYSTATION(R)3 Controller 04:FE:XX:86:XX:16 JBL Flip 4 05:21:XX:8E:XX:25 PLAYSTATION(R)3 Controller 98:D3:XX:40:XX:2C HC05