idasen_controller/main.py
async def connect(client = None, attempt = 0):
    """Attempt to connect to the desk"""
    # Attempt to load and connect to the pickled desk
    desk = unpickle_desk()
    if desk:
        pickled = True
    if not desk:
        # If that fails then rescan for the desk
        desk = await scan(config['mac_address'])
    if not desk:
        print('Could not find desk {}'.format(config['mac_address']))
        os._exit(1)
    # Cache the Bleak device config to connect more quickly in future
    pickle_desk(desk)
    try:
        print('Connecting\r', end ="")
        if not client:
            client = BleakClient(desk, device=config['adapter_name'])
        await client.connect(timeout=config['connection_timeout'])
        print("Connected {}".format(config['mac_address']))
        return client 
    except BleakError as e:
        if attempt == 0 and pickled:
            # Could be a bad pickle so remove it and try again
            try:
                os.remove(PICKLE_FILE)
                print('Connecting failed - Retrying without cached connection')
            except OSError:
                pass
            return await connect(attempt = attempt + 1)
        else:
            print('Connecting failed')
            print(e)
            os._exit(1)
Attempt to connect to the desk
Attempt to connect to the desk
Attempt to connect to the desk
async def connect(client = None, attempt = 0):
    desk = unpickle_desk()
    if desk:
        pickled = True
    if not desk:
        desk = await scan(config['mac_address'])
    if not desk:
        print('Could not find desk {}'.format(config['mac_address']))
        os._exit(1)
    pickle_desk(desk)
    try:
        print('Connecting\r', end ="")
        if not client:
            client = BleakClient(desk, device=config['adapter_name'])
        await client.connect(timeout=config['connection_timeout'])
        print("Connected {}".format(config['mac_address']))
        return client 
    except BleakError as e:
        if attempt == 0 and pickled:
            try:
                os.remove(PICKLE_FILE)
                print('Connecting failed - Retrying without cached connection')
            except OSError:
                pass
            return await connect(attempt = attempt + 1)
        else:
            print('Connecting failed')
            print(e)
            os._exit(1)
async def connect ( client = None , attempt = 0 ) : desk = unpickle_desk ( ) if desk : pickled = True if not desk : desk = await scan ( config [ 'mac_address' ] ) if not desk : print ( 'Could not find desk {}' . format ( config [ 'mac_address' ] ) ) os . _exit ( 1 ) pickle_desk ( desk ) try : print ( 'Connecting\r' , end = "" ) if not client : client = BleakClient ( desk , device = config [ 'adapter_name' ] ) await client . connect ( timeout = config [ 'connection_timeout' ] ) print ( "Connected {}" . format ( config [ 'mac_address' ] ) ) return client except BleakError as e : if attempt == 0 and pickled : try : os . remove ( PICKLE_FILE ) print ( 'Connecting failed - Retrying without cached connection' ) except OSError : pass return await connect ( attempt = attempt + 1 ) else : print ( 'Connecting failed' ) print ( e ) os . _exit ( 1 )
Attempt to connect to the desk
Attempt to connect to the desk
"""Attempt to connect to the desk""" # Attempt to load and connect to the pickled desk # If that fails then rescan for the desk # Cache the Bleak device config to connect more quickly in future # Could be a bad pickle so remove it and try again
client
attempt