dbus: Send out a PropertyChanged event when a device is paired
Just updating the array isn't enough, we need to bubble up the property change and then manually send the PropertyChanged event
This commit is contained in:
parent
daac6e6d96
commit
d3192dc070
8
tuhi.py
8
tuhi.py
|
@ -93,6 +93,14 @@ class TuhiDevice(GObject.Object):
|
|||
|
||||
self._tuhi_dbus_device = None
|
||||
|
||||
@GObject.Property
|
||||
def paired(self):
|
||||
return self._paired
|
||||
|
||||
@paired.setter
|
||||
def paired(self, paired):
|
||||
self._paired = paired
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._bluez_device.name
|
||||
|
|
|
@ -99,6 +99,15 @@ class TuhiDBusDevice(GObject.Object):
|
|||
|
||||
self._connection = connection
|
||||
self._dbusid = self._register_object(connection)
|
||||
device.connect('notify::paired', self._on_device_paired)
|
||||
|
||||
@GObject.Property
|
||||
def paired(self):
|
||||
return self._paired
|
||||
|
||||
@paired.setter
|
||||
def paired(self, paired):
|
||||
self._paired = paired
|
||||
|
||||
def remove(self):
|
||||
self._connection.unregister_object(self._dbusid)
|
||||
|
@ -153,6 +162,10 @@ class TuhiDBusDevice(GObject.Object):
|
|||
def _pair(self):
|
||||
self.emit('pair-requested')
|
||||
|
||||
def _on_device_paired(self, device, pspec):
|
||||
logger.debug('{}: is paired {}'.format(device, device.paired))
|
||||
self.paired = device.paired
|
||||
|
||||
def _listen(self):
|
||||
# FIXME: start listen asynchronously
|
||||
# FIXME: update property when listen finishes
|
||||
|
@ -287,11 +300,34 @@ class TuhiDBusServer(GObject.Object):
|
|||
|
||||
def create_device(self, device):
|
||||
dev = TuhiDBusDevice(device, self._connection)
|
||||
dev.connect('notify::paired', self._on_device_paired)
|
||||
self._devices.append(dev)
|
||||
if not device.paired:
|
||||
self._emit_pairable_signal(dev)
|
||||
return dev
|
||||
|
||||
def _on_device_paired(self, device, param):
|
||||
logger.debug('dbus server {}: is paired {}'.format(device, device.paired))
|
||||
props = GLib.VariantBuilder(GLib.VariantType('a{sv}'))
|
||||
|
||||
objpaths = GLib.Variant.new_array(GLib.VariantType('o'),
|
||||
[GLib.Variant.new_object_path(d.objpath)
|
||||
for d in self._devices if d.paired])
|
||||
de = GLib.Variant.new_dict_entry(GLib.Variant.new_string('Devices'),
|
||||
GLib.Variant.new_variant(objpaths))
|
||||
props.add_value(de)
|
||||
props = props.end()
|
||||
inval_props = GLib.VariantBuilder(GLib.VariantType('as'))
|
||||
inval_props = inval_props.end()
|
||||
|
||||
self._connection.emit_signal(None, BASE_PATH,
|
||||
"org.freedesktop.DBus.Properties",
|
||||
"PropertiesChanged",
|
||||
GLib.Variant.new_tuple(
|
||||
GLib.Variant.new_string(INTF_MANAGER),
|
||||
props,
|
||||
inval_props))
|
||||
|
||||
def _emit_pairable_signal(self, device):
|
||||
arg = GLib.Variant.new_object_path(device.objpath)
|
||||
self._connection.emit_signal(None, BASE_PATH, INTF_MANAGER,
|
||||
|
|
Loading…
Reference in New Issue