kete: don't assume all devices are unregistered when searching

Instead, wait for the signal from tuhi and then go for it.

Fixes #80
This commit is contained in:
Peter Hutterer 2018-02-12 12:19:39 +10:00 committed by Benjamin Tissoires
parent ad0e81b395
commit 58220efe31
1 changed files with 13 additions and 7 deletions

View File

@ -347,15 +347,24 @@ class TuhiKeteManager(_DBusObject):
pass pass
self.notify('devices') self.notify('devices')
def _handle_unregistered_device(self, objpath):
for addr, dev in self._devices.items():
if dev.objpath == objpath:
self.emit('unregistered-device', dev)
return
device = TuhiKeteDevice(self, objpath)
self._unregistered_devices[objpath] = device
logger.debug(f'New unregistered device: {device}')
self.emit('unregistered-device', device)
def _on_signal_received(self, proxy, sender, signal, parameters): def _on_signal_received(self, proxy, sender, signal, parameters):
if signal == 'SearchStopped': if signal == 'SearchStopped':
self.notify('searching') self.notify('searching')
elif signal == 'UnregisteredDevice': elif signal == 'UnregisteredDevice':
objpath = parameters[0] objpath = parameters[0]
device = TuhiKeteDevice(self, objpath) self._handle_unregistered_device(objpath)
self._unregistered_devices[objpath] = device
logger.debug(f'Found unregistered device: {device}')
self.emit('unregistered-device', device)
def __getitem__(self, btaddr): def __getitem__(self, btaddr):
return self._devices[btaddr] return self._devices[btaddr]
@ -394,9 +403,6 @@ class Searcher(Worker):
self.manager.start_search() self.manager.start_search()
logger.debug('Started searching') logger.debug('Started searching')
for d in self.manager.devices:
self._on_unregistered_device(self.manager, d)
def stop(self): def stop(self):
if self.manager.searching: if self.manager.searching:
logger.debug('Stopping search') logger.debug('Stopping search')