diff --git a/pymobiledevice3/cli/restore.py b/pymobiledevice3/cli/restore.py index 62c1f9fa..13e126fa 100644 --- a/pymobiledevice3/cli/restore.py +++ b/pymobiledevice3/cli/restore.py @@ -11,7 +11,7 @@ from pymobiledevice3 import usbmux from pymobiledevice3.cli.cli_common import print_json, set_verbosity -from pymobiledevice3.exceptions import ConnectionFailedError, IncorrectModeError +from pymobiledevice3.exceptions import ConnectionFailedError, ConnectionFailedToUsbmuxdError, IncorrectModeError from pymobiledevice3.irecv import IRecv from pymobiledevice3.lockdown import LockdownClient, create_using_usbmux from pymobiledevice3.restore.device import Device @@ -44,16 +44,20 @@ def device(ctx, param, value): ecid = value logger.debug('searching among connected devices via lockdownd') - for device in usbmux.list_devices(): - try: - lockdown = create_using_usbmux(serial=device.serial, connection_type='USB') - except (ConnectionFailedError, IncorrectModeError): - continue - if (ecid is None) or (lockdown.ecid == value): - logger.debug('found device') - return lockdown - else: - continue + try: + for device in usbmux.list_devices(): + try: + lockdown = create_using_usbmux(serial=device.serial, connection_type='USB') + except (ConnectionFailedError, IncorrectModeError): + continue + if (ecid is None) or (lockdown.ecid == value): + logger.debug('found device') + return lockdown + else: + continue + except ConnectionFailedToUsbmuxdError: + pass + logger.debug('waiting for device to be available in Recovery mode') return IRecv(ecid=ecid)