Skip to content

Commit

Permalink
fix: handle more garage data (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 18, 2022
1 parent e25b321 commit 9ee81c7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ibeacon_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def calculate_distance_meters(power: int, rssi: int) -> float | None:
if rssi == 0:
return None
if (ratio := rssi * 1.0 / power) < 1.0:
return pow(ratio, 10)
distance = cast(float, 0.89976 * pow(ratio, 7.7095) + 0.111)
distance = pow(ratio, 10)
else:
distance = cast(float, 0.89976 * pow(ratio, 7.7095) + 0.111)
return distance if distance < 1000 else None
1 change: 1 addition & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_not_parse_2():
def tests_calculate_distance_meters():
assert calculate_distance_meters(-59, -60) == 1.1352362990362899
assert calculate_distance_meters(59, -60) == 1.183020818815412
assert calculate_distance_meters(12, -80) is None
assert calculate_distance_meters(59, 0) is None
assert calculate_distance_meters(-3, -100) is None
assert calculate_distance_meters(-3, -3) == 1.01076
Expand Down

0 comments on commit 9ee81c7

Please sign in to comment.