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

fix confidence/horizontal acc, add mac address #85

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[pre-commit.ci lite] apply automatic fixes
  • Loading branch information
pre-commit-ci-lite[bot] authored Nov 20, 2024
commit a4b753287ec4adbc514fc8da553e2c039329ec88
8 changes: 6 additions & 2 deletions findmy/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ def adv_key_bytes(self) -> bytes:
def adv_key_b64(self) -> str:
"""Return the advertised (public) key as a base64-encoded string."""
return base64.b64encode(self.adv_key_bytes).decode("ascii")

@property
def mac_address(self) -> str:
"""Get the mac address from the public key."""
first_hex = self.adv_key_bytes[0] | 0b11000000
return parsers.format_hex_byte(first_hex) + ":" + ":".join([parsers.format_hex_byte(x) for x in self.adv_key_bytes[1:6]])
return (
parsers.format_hex_byte(first_hex)
+ ":"
+ ":".join([parsers.format_hex_byte(x) for x in self.adv_key_bytes[1:6]])
)

@property
@override
Expand Down
4 changes: 2 additions & 2 deletions findmy/reports/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ def timestamp(self) -> datetime:
"""The `datetime` when this report was recorded by a device."""
timestamp_int = int.from_bytes(self._payload[0:4], "big") + (60 * 60 * 24 * 11323)
return datetime.fromtimestamp(timestamp_int, tz=timezone.utc).astimezone()

@property
def confidence(self) -> int:
"""Confidence of the location of this report. Int between 1 and 3"""
# If the payload length is 88, the confidence is the 5th byte, otherwise it's the 6th byte
if (len(self._payload) == 88):
if len(self._payload) == 88:
return self.payload[4]
return self.payload[5]

Expand Down
3 changes: 2 additions & 1 deletion findmy/util/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ def decode_plist(data: bytes) -> Any: # noqa: ANN401

return plistlib.loads(data)


def format_hex_byte(byte):
return f'{byte:02x}'.upper()
return f"{byte:02x}".upper()
Loading