We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 967cc9f commit 780eb0aCopy full SHA for 780eb0a
1 file changed
src/bluetooth_data_tools/distance.py
@@ -1,14 +1,12 @@
1
-from typing import cast
2
-
3
MAX_THEORETICAL_DISTANCE = 400.0
4
5
6
def calculate_distance_meters(power: int, rssi: int) -> float | None:
7
"""Calculate the distance in meters between the scanner and the device."""
8
if rssi == 0 or power == 0:
9
return None
10
- if (ratio := rssi * 1.0 / power) < 1.0:
11
- distance = pow(ratio, 10)
+ if (ratio := rssi / power) < 1.0:
+ distance = ratio**10
12
else:
13
- distance = cast(float, 0.89976 * pow(ratio, 7.7095) + 0.111)
+ distance = 0.89976 * ratio**7.7095 + 0.111
14
return min(distance, MAX_THEORETICAL_DISTANCE)
0 commit comments