Skip to content

Commit

Permalink
Merge pull request #91 from malmeloo/fix/nearby-device-discovery
Browse files Browse the repository at this point in the history
Add key generation margin when comparing against detected device
  • Loading branch information
malmeloo authored Dec 23, 2024
2 parents 889f689 + bf49c69 commit b171755
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions findmy/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import time
from abc import ABC, abstractmethod
from datetime import datetime
from datetime import datetime, timedelta
from typing import TYPE_CHECKING, Any, AsyncGenerator

from bleak import BleakScanner
Expand Down Expand Up @@ -240,7 +240,12 @@ def is_from(self, other_device: HasPublicKey | RollingKeyPairSource) -> bool:
if isinstance(other_device, HasPublicKey):
return self.adv_key_bytes == other_device.adv_key_bytes
if isinstance(other_device, RollingKeyPairSource):
return any(self.is_from(key) for key in other_device.keys_at(self.detected_at))
# 12 hour margin around the detected time
potential_keys = other_device.keys_between(
self.detected_at - timedelta(hours=12),
self.detected_at + timedelta(hours=12),
)
return any(self.is_from(key) for key in potential_keys)

msg = f"Cannot compare against {type(other_device)}"
raise ValueError(msg)
Expand Down

0 comments on commit b171755

Please sign in to comment.