From 46ec85d7182d16c641921574e7909dbecb152a72 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 9 Feb 2018 15:43:04 +1000 Subject: [PATCH] ble: make manufacturer_data a property We only ever used it in conjunction with vendor_id, so we can just make this a normal property and send GObject notifies when it changes. This allows us to listen for the MD to change when it finished registration. [BT: do not add the second indirection by calling vendor_id] --- tuhi/base.py | 2 +- tuhi/ble.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tuhi/base.py b/tuhi/base.py index 1f32aa0..6f26032 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -246,7 +246,7 @@ class Tuhi(GObject.Object): if bluez_device.vendor_id not in WACOM_COMPANY_IDS: return False - manufacturer_data = bluez_device.get_manufacturer_data(bluez_device.vendor_id) + manufacturer_data = bluez_device.manufacturer_data return manufacturer_data is not None and len(manufacturer_data) == 4 def _on_bluez_discovery_started(self, manager): diff --git a/tuhi/ble.py b/tuhi/ble.py index 55c643c..e81a554 100755 --- a/tuhi/ble.py +++ b/tuhi/ble.py @@ -152,10 +152,18 @@ class BlueZDevice(GObject.Object): return (self.interface.get_cached_property('Connected').unpack() and self.interface.get_cached_property('ServicesResolved').unpack()) - def get_manufacturer_data(self, vendor_id): + @GObject.Property + def manufacturer_data(self): md = self.interface.get_cached_property('ManufacturerData') - if md is not None and vendor_id in md.keys(): - return md[vendor_id] + if md is None: + return None + + try: + return next(iter(dict(md).values())) + except StopIteration: + # dict is empty + pass + return None def resolve(self, om): @@ -257,6 +265,8 @@ class BlueZDevice(GObject.Object): self.emit('connected') if 'RSSI' in properties: self.emit('updated') + if 'ManufacturerData' in properties: + self.notify('manufacturer-data') def connect_gatt_value(self, uuid, callback): '''