Skip to content

Commit

Permalink
Fixed detecting not present/unknown battery level for FastPair
Browse files Browse the repository at this point in the history
  • Loading branch information
steam3d committed Apr 21, 2024
1 parent 6314519 commit 58a3e97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bluetooth_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,12 @@ def _perform_query_fastpair(self) -> dict[str, int]:
if group == 3 and code == 3:
# Example: https://github.com/google/nearby/blob/main/fastpair/common/battery_notification.cc
def parse_level(level: int) -> int:
# 0xff means not present/unknown
if level == 0xff:
# 01234567 bits order
# 0x11111111 charging, but not present/unknown battery level charging
# 0x01111111 not charging, but not present/unknown battery level
# 0 bit: 1 charging, 0 not charging
# 1-7 bits: battery level
if (level & 0x7f) == 0x7f:
return None
# Top bit indicates if the device is charging
return level & 0x7f
Expand Down

0 comments on commit 58a3e97

Please sign in to comment.