Skip to content

Commit

Permalink
Fix bug in calculating perceived brightness at low levels (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya authored Aug 3, 2021
1 parent 7577829 commit d9c4b22
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ecowitt2mqtt/util/meteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ def calculate_illuminance_wm2_to_lux(value: float) -> float:
def calculate_illuminance_wm2_to_perceived(value: float) -> float:
"""Calculate illuminance (in lux)."""
lux = calculate_illuminance_wm2_to_lux(value)
return round(math.log10(lux) / 5, 2) * 100
try:
perceived = round(math.log10(lux) / 5, 2) * 100
except ValueError:
# If we've approached negative infinity, we'll get a math domain error; in that
# case, return 0.0:
return 0.0
if perceived < 0:
return 0.0
return perceived


def calculate_pressure(
Expand Down

0 comments on commit d9c4b22

Please sign in to comment.