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]
pull/81/merge
Peter Hutterer 2018-02-09 15:43:04 +10:00 committed by Benjamin Tissoires
parent 72523df3af
commit 46ec85d718
2 changed files with 14 additions and 4 deletions

View File

@ -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):

View File

@ -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):
'''