def pair(args):
"""
Pair to the specified device
Args:
args (dict): args parsed on the command line
Returns:
results (dict): return message and code of the operation
"""
def success():
try:
device_manager.trust_device()
device_manager.connect_device()
format_results({'result': 'Success', 'code': ''})
finally:
mainloop.quit()
def error(err):
try:
if err == 'org.freedesktop.DBus.Error.NoReply' and self.dev:
code = 'Timeout'
device_manager.cancel_device()
if err in ('org.bluez.Error.AuthenticationCanceled', 'org.bluez.Error.AuthenticationFailed',
'org.bluez.Error.AuthenticationRejected', 'org.bluez.Error.AuthenticationTimeout'):
code = 'AuthenticationError'
else:
code = 'CreatingDeviceFailed'
format_results({'result': 'Error', 'code': code})
finally:
mainloop.quit()
mainloop = MainLoop()
device_manager = DeviceManager(args.device)
device_manager.pair_device(success, error)
mainloop.run()
评论列表
文章目录