cli.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:bjarkan 作者: GetWellNetwork 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号