ble: use properties instead of variables
Replace variables (objpath, interface, uuid) with properties. Signed-off-by: Daniel Martin <consume.noise@gmail.com>
This commit is contained in:
parent
7f9e58e587
commit
c719ecf2e2
28
tuhi/ble.py
28
tuhi/ble.py
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue