diff --git a/README.md b/README.md index 86dbfa3..b2d662c 100644 --- a/README.md +++ b/README.md @@ -143,12 +143,8 @@ org.freedesktop.tuhi1.Device Interface to a device known by tuhi. Each object in Manager.Devices implements this interface. - Property: Name (s) - Human-readable name of the device. - Read-only - - Property: Address (s) - Bluetooth address of the device. + Property: BlueZDevice (o) + Object path to the org.bluez.Device1 device that is this device. Read-only Property: Dimensions (uu) diff --git a/tools/tuhi-kete.py b/tools/tuhi-kete.py index 66b3331..c08d5ed 100755 --- a/tools/tuhi-kete.py +++ b/tools/tuhi-kete.py @@ -67,6 +67,8 @@ ORG_FREEDESKTOP_TUHI1_MANAGER = 'org.freedesktop.tuhi1.Manager' ORG_FREEDESKTOP_TUHI1_DEVICE = 'org.freedesktop.tuhi1.Device' ROOT_PATH = '/org/freedesktop/tuhi1' +ORG_BLUEZ_DEVICE1 = 'org.bluez.Device1' + # remove ':' from the completer delimiters of readline so we can match on # device addresses completer_delims = readline.get_completer_delims() @@ -92,7 +94,7 @@ class _DBusObject(GObject.Object): self.objpath = objpath try: - self.proxy = Gio.DBusProxy.new_sync(_DBusObject._connection, + self.proxy = Gio.DBusProxy.new_sync(self._connection, Gio.DBusProxyFlags.NONE, None, name, objpath, interface, None) except GLib.Error as e: @@ -133,6 +135,30 @@ class _DBusObject(GObject.Object): return p +class _DBusSystemObject(_DBusObject): + ''' + Same as the _DBusObject, but connects to the system bus instead + ''' + def __init__(self, name, interface, objpath): + self._connect_to_system() + super().__init__(name, interface, objpath) + + def _connect_to_system(self): + try: + self._connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + except GLib.Error as e: + if (e.domain == 'g-io-error-quark' and + e.code == Gio.IOErrorEnum.DBUS_ERROR): + raise DBusError(e.message) + else: + raise e + + +class BlueZDevice(_DBusSystemObject): + def __init__(self, objpath): + super().__init__('org.bluez', ORG_BLUEZ_DEVICE1, objpath) + + class TuhiKeteDevice(_DBusObject): def __init__(self, manager, objpath): _DBusObject.__init__(self, TUHI_DBUS_NAME, @@ -140,6 +166,7 @@ class TuhiKeteDevice(_DBusObject): objpath) self.manager = manager self.is_pairing = False + self._bluez_device = BlueZDevice(self.property('BlueZDevice')) @classmethod def is_device_address(cls, string): @@ -149,11 +176,11 @@ class TuhiKeteDevice(_DBusObject): @GObject.Property def address(self): - return self.property('Address') + return self._bluez_device.property('Address') @GObject.Property def name(self): - return self.property('Name') + return self._bluez_device.property('Name') @GObject.Property def listening(self): diff --git a/tuhi/base.py b/tuhi/base.py index 7441ad0..d664b9e 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -86,6 +86,10 @@ class TuhiDevice(GObject.Object): def address(self): return self._bluez_device.address + @GObject.Property + def bluez_device(self): + return self._bluez_device + @GObject.Property def dbus_device(self): return self._tuhi_dbus_device diff --git a/tuhi/dbusserver.py b/tuhi/dbusserver.py index 7ae2df6..40d885a 100755 --- a/tuhi/dbusserver.py +++ b/tuhi/dbusserver.py @@ -47,8 +47,7 @@ INTROSPECTION_XML = ''' - - + @@ -144,8 +143,8 @@ class TuhiDBusDevice(_TuhiDBus): objpath = f'{BASE_PATH}/{objpath}' _TuhiDBus.__init__(self, connection, objpath, INTF_DEVICE) + self.bluez_device_objpath = device.bluez_device.objpath self.name = device.name - self.btaddr = device.address self.width, self.height = 0, 0 self.drawings = {} self.paired = device.paired @@ -240,10 +239,8 @@ class TuhiDBusDevice(_TuhiDBus): if interface != INTF_DEVICE: return None - if propname == 'Name': - return GLib.Variant.new_string(self.name) - elif propname == 'Address': - return GLib.Variant.new_string(self.btaddr) + if propname == 'BlueZDevice': + return GLib.Variant.new_object_path(self.bluez_device_objpath) elif propname == 'Dimensions': w = GLib.Variant.new_uint32(self.width) h = GLib.Variant.new_uint32(self.height)