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]
This commit is contained in:
parent
72523df3af
commit
46ec85d718
|
@ -246,7 +246,7 @@ class Tuhi(GObject.Object):
|
||||||
if bluez_device.vendor_id not in WACOM_COMPANY_IDS:
|
if bluez_device.vendor_id not in WACOM_COMPANY_IDS:
|
||||||
return False
|
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
|
return manufacturer_data is not None and len(manufacturer_data) == 4
|
||||||
|
|
||||||
def _on_bluez_discovery_started(self, manager):
|
def _on_bluez_discovery_started(self, manager):
|
||||||
|
|
16
tuhi/ble.py
16
tuhi/ble.py
|
@ -152,10 +152,18 @@ class BlueZDevice(GObject.Object):
|
||||||
return (self.interface.get_cached_property('Connected').unpack() and
|
return (self.interface.get_cached_property('Connected').unpack() and
|
||||||
self.interface.get_cached_property('ServicesResolved').unpack())
|
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')
|
md = self.interface.get_cached_property('ManufacturerData')
|
||||||
if md is not None and vendor_id in md.keys():
|
if md is None:
|
||||||
return md[vendor_id]
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
return next(iter(dict(md).values()))
|
||||||
|
except StopIteration:
|
||||||
|
# dict is empty
|
||||||
|
pass
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def resolve(self, om):
|
def resolve(self, om):
|
||||||
|
@ -257,6 +265,8 @@ class BlueZDevice(GObject.Object):
|
||||||
self.emit('connected')
|
self.emit('connected')
|
||||||
if 'RSSI' in properties:
|
if 'RSSI' in properties:
|
||||||
self.emit('updated')
|
self.emit('updated')
|
||||||
|
if 'ManufacturerData' in properties:
|
||||||
|
self.notify('manufacturer-data')
|
||||||
|
|
||||||
def connect_gatt_value(self, uuid, callback):
|
def connect_gatt_value(self, uuid, callback):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue