Add option to align FindMyAccessories key generation

Sometimes the key generation diverges for example if the accessory has no power. FindMy solves this be re-aligning the key generation if a btle connection is established. FindMy.app stores there alignment records in the `KeyAlignmentRecord` directory.

This PR extends the FindMyAccessory class to read those records during `from_plist`-generation and re-sync the key generation by this
This commit is contained in:
pajowu
2025-04-15 15:08:21 +02:00
parent 4b7a9cbb45
commit ed098cc8ce
2 changed files with 60 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ Example showing how to fetch locations of an AirTag, or any other FindMy accesso
from __future__ import annotations
import argparse
import logging
import sys
from pathlib import Path
@@ -19,10 +20,15 @@ ANISETTE_SERVER = "http://localhost:6969"
logging.basicConfig(level=logging.INFO)
def main(plist_path: str) -> int:
def main(plist_path: Path, alignment_plist_path: Path | None) -> int:
# Step 0: create an accessory key generator
with Path(plist_path).open("rb") as f:
airtag = FindMyAccessory.from_plist(f)
with plist_path.open("rb") as f:
f2 = alignment_plist_path.open("rb") if alignment_plist_path else None
airtag = FindMyAccessory.from_plist(f, f2)
if f2:
f2.close()
# Step 1: log into an Apple account
print("Logging into account")
@@ -43,10 +49,9 @@ def main(plist_path: str) -> int:
if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <path to accessory plist>", file=sys.stderr)
print(file=sys.stderr)
print("The plist file should be dumped from MacOS's FindMy app.", file=sys.stderr)
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument("plist_path", type=Path)
parser.add_argument("--alignment_plist_path", default=None, type=Path)
args = parser.parse_args()
sys.exit(main(sys.argv[1]))
sys.exit(main(args.plist_path, args.alignment_plist_path))