Skip to content

Commit 4e4527d

Browse files
committed
Make print_scanning_results private
1 parent 90986ef commit 4e4527d

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

findmy/scanner/scanner.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434
BATTERY_LEVEL = {0b00: "Full", 0b01: "Medium", 0b10: "Low", 0b11: "Very Low"}
3535

3636

37+
def _print_scanning_results(seen_devices: dict[str, list[OfflineFindingDevice]]) -> None:
38+
"""Print summary of each device seen."""
39+
# ruff: noqa: T201
40+
print("================ RESULTS =========================")
41+
for mac, devices in seen_devices.items():
42+
avg_rssi = sum(d.rssi for d in devices if d.rssi is not None) / len(
43+
[d for d in devices if d.rssi is not None]
44+
)
45+
print(f"Device {mac} seen {len(devices)} times, average RSSI: {avg_rssi:.1f}")
46+
of_type = "nearby" if isinstance(devices[0], NearbyOfflineFindingDevice) else "separated"
47+
print(
48+
f" {devices[0].device_type} with {devices[0].battery_level} battery"
49+
f" ({of_type} state)"
50+
)
51+
52+
if isinstance(devices[0], SeparatedOfflineFindingDevice):
53+
print(f" Public key: {devices[0].adv_key_b64}")
54+
print(f" Lookup key: {devices[0].hashed_adv_key_b64}")
55+
print("===============================================")
56+
57+
device_type_counts: dict[str, int] = {}
58+
for devs in seen_devices.values():
59+
dev_type = devs[0].device_type
60+
device_type_counts[dev_type] = device_type_counts.get(dev_type, 0) + 1
61+
62+
for dev_type, count in device_type_counts.items():
63+
print(f"Total {dev_type}: {count}")
64+
65+
3766
class OfflineFindingDevice(ABC):
3867
"""Device discoverable through Apple's bluetooth-based Offline Finding protocol."""
3968

@@ -417,36 +446,6 @@ def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
417446

418447
self._scanner_count: int = 0
419448

420-
def print_scanning_results(self, seen_devices: dict[str, list[OfflineFindingDevice]]) -> None:
421-
"""Print summary of each device seen."""
422-
# ruff: noqa: T201
423-
print("================ RESULTS =========================")
424-
for mac, devices in seen_devices.items():
425-
avg_rssi = sum(d.rssi for d in devices if d.rssi is not None) / len(
426-
[d for d in devices if d.rssi is not None]
427-
)
428-
print(f"Device {mac} seen {len(devices)} times, average RSSI: {avg_rssi:.1f}")
429-
of_type = (
430-
"nearby" if isinstance(devices[0], NearbyOfflineFindingDevice) else "separated"
431-
)
432-
print(
433-
f" {devices[0].device_type} with {devices[0].battery_level} battery"
434-
f" ({of_type} state)"
435-
)
436-
437-
if isinstance(devices[0], SeparatedOfflineFindingDevice):
438-
print(f" Public key: {devices[0].adv_key_b64}")
439-
print(f" Lookup key: {devices[0].hashed_adv_key_b64}")
440-
print("===============================================")
441-
442-
device_type_counts: dict[str, int] = {}
443-
for devs in seen_devices.values():
444-
dev_type = devs[0].device_type
445-
device_type_counts[dev_type] = device_type_counts.get(dev_type, 0) + 1
446-
447-
for dev_type, count in device_type_counts.items():
448-
print(f"Total {dev_type}: {count}")
449-
450449
@classmethod
451450
async def create(cls) -> OfflineFindingScanner:
452451
"""Create an instance of the scanner."""
@@ -547,7 +546,7 @@ async def scan_for(
547546
except asyncio.TimeoutError: # timeout reached
548547
self._device_fut = self._loop.create_future()
549548
if print_summary:
550-
self.print_scanning_results(devices_seen)
549+
_print_scanning_results(devices_seen)
551550
return
552551
finally:
553552
await self._stop_scan()

0 commit comments

Comments
 (0)