Skip to content

Commit

Permalink
Merge pull request #61 from malmeloo/fix/location-report-eq
Browse files Browse the repository at this point in the history
reports: Fix equality check between `LocationReport`s
  • Loading branch information
malmeloo authored Aug 4, 2024
2 parents 4239c68 + 62900f9 commit 19bea8a
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 19bea8a

Please sign in to comment.