picklepete / pyicloud

A Python + iCloud wrapper to access iPhone and Calendar data.
MIT License
2.45k stars 437 forks source link

Add functionality to erase devices in FindMyiPhone #448

Open AgentHV opened 3 months ago

AgentHV commented 3 months ago

Breaking change

This PR is based on https://github.com/picklepete/pyicloud/pull/227 and therefore has all changes this PR has. Otherwise no breaking changes. I saw it as necessary to base my PR on this PR to reduce the risk of accidentally erasing family devices.

Proposed change

Type of change

Example of code:

Usage example: This code loops through all your devices and prompts you to erase the first one that supports remote erasion

api.find_my_iphone.with_family = False
api.find_my_iphone.refresh_client()

for x in range(0,len(api.find_my_iphone.devices)):
    currentDevice = api.find_my_iphone.device(x)
    print("Device", currentDevice.name, "does support remote erasure: ", currentDevice.canWipe)
    if (currentDevice.canWipe):
        erasetoken = api.fmipWebAuthenticate(currentDevice)
        print(erasetoken)
        input("Submit anything to wipe device")
        currentDevice.erase_device(text="",erasetoken=erasetoken)
        break

Additional information

Checklist

If user exposed functionality or configuration variables are added/changed: