From c719ecf2e2cc1bff2f88e2c0886dbfc35b457863 Mon Sep 17 00:00:00 2001 From: Daniel Martin Date: Thu, 6 Jun 2019 12:22:50 +0200 Subject: [PATCH] ble: use properties instead of variables Replace variables (objpath, interface, uuid) with properties. Signed-off-by: Daniel Martin --- tuhi/ble.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tuhi/ble.py b/tuhi/ble.py index 8fc2183..5abb1b8 100755 --- a/tuhi/ble.py +++ b/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: