From dde2ad4b46b499408862be7097ac3b04fc90e619 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 17 Jan 2018 11:34:54 +1000 Subject: [PATCH] ble: use ServicesResolved for the connected signal --- tuhi/ble.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tuhi/ble.py b/tuhi/ble.py index 7a6e1f8..5aeeb34 100755 --- a/tuhi/ble.py +++ b/tuhi/ble.py @@ -114,8 +114,7 @@ class BlueZDevice(GObject.Object): self.characteristics = {} self.resolve(om) self.interface.connect('g-properties-changed', self._on_properties_changed) - # FIXME: this should switch to ServicesResolved - if self.interface.get_cached_property('Connected').get_boolean(): + if self.connected: self.emit('connected') @property @@ -137,6 +136,11 @@ class BlueZDevice(GObject.Object): return md.keys()[0] return None + @property + def connected(self): + return (self.interface.get_cached_property('Connected').unpack() and + self.interface.get_cached_property('ServicesResolved').unpack()) + def resolve(self, om): """ Resolve the GattServices and GattCharacteristics. This function does @@ -186,9 +190,8 @@ class BlueZDevice(GObject.Object): asynchronous and returns immediately. """ i = self.obj.get_interface(ORG_BLUEZ_DEVICE1) - if i.get_cached_property('Connected').get_boolean(): + if self.connected: logger.info('{}: Device is already connected'.format(self.address)) - # FIXME: this should switch to ServicesResolved self.emit('connected') return @@ -205,10 +208,12 @@ class BlueZDevice(GObject.Object): if 'Connected' in properties: if properties['Connected']: logger.info('Connection established') - self.emit('connected') else: logger.info('Disconnected') self.emit('disconnected') + elif 'ServicesResolved' in properties: + if properties['ServicesResolved']: + self.emit('connected') def connect_gatt_value(self, uuid, callback): """