Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reports: Fix equality check between LocationReports #61

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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