cli: reduce chance of connect notifications clashing when pairing

This commit is contained in:
Peter F. Patel-Schneider 2020-09-16 13:00:38 -04:00
parent ad57db4a39
commit 714f8782b3
1 changed files with 8 additions and 5 deletions

View File

@ -51,15 +51,18 @@ def run(receivers, args, find_receiver, _ignore):
class _HandleWithNotificationHook(int): class _HandleWithNotificationHook(int):
def notifications_hook(self, n): def notifications_hook(self, n):
nonlocal known_devices
assert n assert n
if n.devnumber == 0xFF: if n.devnumber == 0xFF:
_notifications.process(receiver, n) _notifications.process(receiver, n)
elif n.sub_id == 0x41: # allow for other protocols! (was and n.address == 0x04) elif n.sub_id == 0x41: # allow for other protocols! (was and n.address == 0x04)
if n.devnumber not in known_devices: kd, known_devices = known_devices, None # only process one connection notification
receiver.status.new_device = receiver[n.devnumber] if kd is not None:
elif receiver.re_pairs: if n.devnumber not in kd:
del receiver[n.devnumber] # get rid of information on device re-paired away receiver.status.new_device = receiver.register_new_device(n.devnumber, n)
receiver.status.new_device = receiver[n.devnumber] elif receiver.re_pairs:
del receiver[n.devnumber] # get rid of information on device re-paired away
receiver.status.new_device = receiver.register_new_device(n.devnumber, n)
timeout = 20 # seconds timeout = 20 # seconds
receiver.handle = _HandleWithNotificationHook(receiver.handle) receiver.handle = _HandleWithNotificationHook(receiver.handle)