Skip to content

Commit 2dd185b

Browse files
authored
Merge pull request #207 from malmeloo/fix/accessory-equivalences
fix: define `__hash__` and `__eq__` for `FindMyAccessory`
2 parents 35c1945 + c1e7673 commit 2dd185b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

findmy/accessory.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,22 @@ def from_json(
373373
msg = f"Failed to restore account data: {e}"
374374
raise ValueError(msg) from None
375375

376+
@override
377+
def __hash__(self) -> int:
378+
master = crypto.bytes_to_int(self.master_key)
379+
skn = crypto.bytes_to_int(self.skn)
380+
sks = crypto.bytes_to_int(self.sks)
381+
return hash((master, skn, sks))
382+
383+
@override
384+
def __eq__(self, other: object) -> bool:
385+
if not isinstance(other, FindMyAccessory):
386+
return False
387+
388+
return (
389+
self.master_key == other.master_key and self.skn == other.skn and self.sks == other.sks
390+
)
391+
376392

377393
class _AccessoryKeyGenerator(KeyGenerator[KeyPair]):
378394
"""KeyPair generator. Uses the same algorithm internally as FindMy accessories do."""

0 commit comments

Comments
 (0)