ble: use properties instead of variables

Replace variables (objpath, interface, uuid) with properties.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
pull/136/head
Daniel Martin 2019-06-06 12:22:50 +02:00 committed by Peter Hutterer
parent 7f9e58e587
commit c719ecf2e2
1 changed files with 22 additions and 6 deletions

View File

@ -35,17 +35,26 @@ class BlueZCharacteristic(GObject.Object):
:param obj: the org.bluez.GattCharacteristic1 DBus proxy object
'''
self.obj = obj
self.objpath = obj.get_object_path()
self.interface = obj.get_interface(ORG_BLUEZ_GATTCHARACTERISTIC1)
assert(self.interface is not None)
self.uuid = self.interface.get_cached_property('UUID').unpack()
assert(self.interface is not None)
assert(self.uuid is not None)
self._property_callbacks = {}
self.interface.connect('g-properties-changed',
self._on_properties_changed)
@GObject.Property
def interface(self):
return self.obj.get_interface(ORG_BLUEZ_GATTCHARACTERISTIC1)
@GObject.Property
def objpath(self):
return self.obj.get_object_path()
@GObject.Property
def uuid(self):
return self.interface.get_cached_property('UUID').unpack()
def connect_property(self, propname, callback):
'''
Connect the property with the given name to the callback function
@ -104,10 +113,9 @@ class BlueZDevice(GObject.Object):
:param obj: The org.bluez.Device1 DBus proxy object
'''
GObject.Object.__init__(self)
self.objpath = obj.get_object_path()
self.obj = obj
self.om = om
self.interface = obj.get_interface(ORG_BLUEZ_DEVICE1)
assert(self.interface is not None)
logger.debug(f'Device {self.objpath} - {self.address} - {self.name}')
@ -118,6 +126,14 @@ class BlueZDevice(GObject.Object):
if self.connected:
self.emit('connected')
@GObject.Property
def objpath(self):
return self.obj.get_object_path()
@GObject.Property
def interface(self):
return self.obj.get_interface(ORG_BLUEZ_DEVICE1)
@GObject.Property
def name(self):
try: