kete: stop listening when pairing a device

Or the internal state of kete is that the device is listening while
tuhi says it is not.
pull/63/head
Benjamin Tissoires 2018-01-31 18:37:17 +01:00 committed by Peter Hutterer
parent 3f75c927dc
commit 277523c7d5
1 changed files with 19 additions and 7 deletions

View File

@ -578,7 +578,8 @@ class TuhiKeteShell(cmd.Cmd):
return names
def _on_name_vanished(self, manager):
logger.debug('Tuhi daemon went away, I should stop the current workers')
logger.debug('Tuhi daemon went away, terminating the current workers')
self.terminate_workers()
def emptyline(self):
# make sure we do not re-enter the last typed command
@ -590,8 +591,7 @@ class TuhiKeteShell(cmd.Cmd):
def do_exit(self, args):
'''Leave the shell'''
for worker in self._workers:
worker.stop()
self.terminate_workers()
return True
def precmd(self, line):
@ -620,6 +620,15 @@ class TuhiKeteShell(cmd.Cmd):
worker.run()
self._workers.append(worker)
def terminate_worker(self, worker):
worker.stop()
self._workers.remove(worker)
def terminate_workers(self):
for worker in self._workers:
worker.stop()
self._workers = []
def do_devices(self, arg):
'''List known devices. These are devices previously paired with the daemon.'''
logger.debug('Listing available devices:')
@ -687,8 +696,7 @@ class TuhiKeteShell(cmd.Cmd):
if mode == 'off':
for worker in [w for w in self._workers if isinstance(w, Listener)]:
if worker.device.address == address:
worker.stop()
self._workers.remove(worker)
self.terminate_worker(worker)
break
return
@ -832,8 +840,7 @@ class TuhiKeteShell(cmd.Cmd):
self.start_worker(Searcher, parsed_args)
else:
if parsed_args.mode == 'off':
current_searcher.stop()
self._workers.remove(current_searcher)
self.terminate_worker(current_searcher)
else:
logger.info('Already searching')
@ -881,6 +888,11 @@ class TuhiKeteShell(cmd.Cmd):
device = None
# make sure we do not keep a listener on the device
for worker in [w for w in self._workers if isinstance(w, Listener)]:
if worker.device.address == address:
self.terminate_worker(worker)
for d in self._manager.devices + self._manager.pairable_devices:
if d.address == address:
device = d