Skip to content

Commit

Permalink
reports: Fix equality check between LocationReports
Browse files Browse the repository at this point in the history
  • Loading branch information
malmeloo committed Aug 4, 2024
1 parent 7b8707b commit 62900f9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions findmy/reports/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,34 @@ def status(self) -> int:
status_bytes = self._decrypted_data[1][9:10]
return int.from_bytes(status_bytes, "big")

@override
def __eq__(self, other: object) -> bool:
"""
Compare two report instances.
Two reports are considered equal iff they correspond to the same key,
were reported at the same timestamp and represent the same physical location.
"""
if not isinstance(other, LocationReport):
return NotImplemented

return (
super().__eq__(other)
and self.timestamp == other.timestamp
and self.latitude == other.latitude
and self.longitude == other.longitude
)

@override
def __hash__(self) -> int:
"""
Get the hash of this instance.
Two instances will have the same hash iff they correspond to the same key,
were reported at the same timestamp and represent the same physical location.
"""
return hash((self.hashed_adv_key_bytes, self.timestamp, self.latitude, self.longitude))

def __lt__(self, other: LocationReport) -> bool:
"""
Compare against another `KeyReport`.
Expand Down

0 comments on commit 62900f9

Please sign in to comment.