88from findmy import (
99 FindMyAccessory ,
1010 KeyPair ,
11- NearbyOfflineFindingDevice ,
1211 OfflineFindingScanner ,
13- SeparatedOfflineFindingDevice ,
1412)
1513
1614logging .basicConfig (level = logging .INFO )
1715
1816
19- def _print_nearby (device : NearbyOfflineFindingDevice ) -> None :
20- print (f"NEARBY Device - { device .mac_address } " )
21- print (f" Status byte: { device .status :x} " )
22- print (" Extra data:" )
23- for k , v in sorted (device .additional_data .items ()):
24- print (f" { k :20} : { v } " )
25- print ()
26-
27-
28- def _print_separated (device : SeparatedOfflineFindingDevice ) -> None :
29- print (f"SEPARATED Device - { device .mac_address } " )
30- print (f" Public key: { device .adv_key_b64 } " )
31- print (f" Lookup key: { device .hashed_adv_key_b64 } " )
32- print (f" Status byte: { device .status :x} " )
33- print (f" Hint byte: { device .hint :x} " )
34- print (" Extra data:" )
35- for k , v in sorted (device .additional_data .items ()):
36- print (f" { k :20} : { v } " )
37- print ()
38-
39-
4017async def scan (check_key : KeyPair | FindMyAccessory | None = None ) -> bool :
4118 scanner = await OfflineFindingScanner .create ()
4219
@@ -45,16 +22,12 @@ async def scan(check_key: KeyPair | FindMyAccessory | None = None) -> bool:
4522
4623 scan_device = None
4724
48- async for device in scanner .scan_for (10 , extend_timeout = True ):
49- if isinstance (device , NearbyOfflineFindingDevice ):
50- _print_nearby (device )
51- elif isinstance (device , SeparatedOfflineFindingDevice ):
52- _print_separated (device )
53- else :
54- print (f"Unknown device: { device } " )
55- print ()
56- continue
25+ scan_out_file = Path ("scan_results.jsonl" )
26+ # Clear previous scan results
27+ if scan_out_file .exists ():
28+ scan_out_file .unlink ()
5729
30+ async for device in scanner .scan_for (10 , extend_timeout = True , print_summary = True ):
5831 if check_key and device .is_from (check_key ):
5932 scan_device = device
6033
0 commit comments