mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-17 21:53:57 +02:00
scanner: support checking for device - key correspondence
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from findmy import KeyPair
|
||||
from findmy.scanner import (
|
||||
NearbyOfflineFindingDevice,
|
||||
OfflineFindingScanner,
|
||||
@@ -9,6 +10,11 @@ from findmy.scanner import (
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# Set if you want to check whether a specific key (or accessory!) is in the scan results.
|
||||
# Make sure to enter its private key!
|
||||
# Leave empty (= None) to not check.
|
||||
CHECK_KEY = KeyPair.from_b64("")
|
||||
|
||||
|
||||
def _print_nearby(device: NearbyOfflineFindingDevice) -> None:
|
||||
print(f"NEARBY Device - {device.mac_address}")
|
||||
@@ -37,6 +43,8 @@ async def scan() -> None:
|
||||
print("Scanning for FindMy-devices...")
|
||||
print()
|
||||
|
||||
scan_device = None
|
||||
|
||||
async for device in scanner.scan_for(10, extend_timeout=True):
|
||||
if isinstance(device, NearbyOfflineFindingDevice):
|
||||
_print_nearby(device)
|
||||
@@ -45,6 +53,15 @@ async def scan() -> None:
|
||||
else:
|
||||
print(f"Unknown device: {device}")
|
||||
print()
|
||||
continue
|
||||
|
||||
if CHECK_KEY and device.is_from(CHECK_KEY):
|
||||
scan_device = device
|
||||
|
||||
if scan_device:
|
||||
print("Key or accessory was found in scan results! :D")
|
||||
elif CHECK_KEY:
|
||||
print("Selected key or accessory was not found in scan results... :c")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user