be a bit more patient when pairing, the device notification may come after the pairing lock is closed

This commit is contained in:
Daniel Pavel 2013-06-21 16:40:00 +02:00
parent 5785896007
commit 888be8e8a8
1 changed files with 11 additions and 5 deletions

View File

@ -16,7 +16,8 @@ from logitech.unifying_receiver.status import KEYS as _K
# #
# #
# #
_PAIRING_TIMEOUT = 30 _PAIRING_TIMEOUT = 30 # seconds
_STATUS_CHECK = 500 # milliseconds
def _create_page(assistant, kind, header=None, icon_name=None, text=None): def _create_page(assistant, kind, header=None, icon_name=None, text=None):
@ -48,7 +49,7 @@ def _create_page(assistant, kind, header=None, icon_name=None, text=None):
return p return p
def _check_lock_state(assistant, receiver): def _check_lock_state(assistant, receiver, count=2):
if not assistant.is_drawable(): if not assistant.is_drawable():
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("assistant %s destroyed, bailing out", assistant) _log.debug("assistant %s destroyed, bailing out", assistant)
@ -65,7 +66,12 @@ def _check_lock_state(assistant, receiver):
return False return False
if not receiver.status.lock_open: if not receiver.status.lock_open:
_pairing_failed(assistant, receiver, 'failed to open pairing lock') if count > 0:
# the actual device notification may arrive after the lock was paired,
# so have a little patience
GLib.timeout_add(_STATUS_CHECK, _check_lock_state, assistant, receiver, count - 1)
else:
_pairing_failed(assistant, receiver, 'failed to open pairing lock')
return False return False
return True return True
@ -82,7 +88,7 @@ def _prepare(assistant, page, receiver):
assert receiver.status.get(_K.ERROR) is None assert receiver.status.get(_K.ERROR) is None
spinner = page.get_children()[-1] spinner = page.get_children()[-1]
spinner.start() spinner.start()
GLib.timeout_add(750, _check_lock_state, assistant, receiver) GLib.timeout_add(_STATUS_CHECK, _check_lock_state, assistant, receiver)
assistant.set_page_complete(page, True) assistant.set_page_complete(page, True)
else: else:
GLib.idle_add(_pairing_failed, assistant, receiver, 'the pairing lock did not open') GLib.idle_add(_pairing_failed, assistant, receiver, 'the pairing lock did not open')
@ -154,7 +160,7 @@ def _pairing_succeeded(assistant, receiver, device):
hbox.show_all() hbox.show_all()
else: else:
return True return True
GLib.timeout_add(500, _check_encrypted, device) GLib.timeout_add(_STATUS_CHECK, _check_encrypted, device)
page.show_all() page.show_all()