Compare commits

...

3 Commits

Author SHA1 Message Date
SchiZzA 39cd852b36
Merge remote-tracking branch 'origin/stable' into ecowitt_support 2025-12-22 16:43:04 +01:00
Lukas Svoboda 94ec3cb0e5
Merge pull request #86 from schizza/fix/index_computing
Fix Heat Index and Chill Index
2025-12-22 11:47:42 +01:00
SchiZzA 743e62c6dd
Fix Heat Index and Chill Index
Fixed computing Heat and Chill index in cases that outside senosor
battery is drained and station stop sending data for outside temp,
humidity and wind.
2025-12-22 11:47:02 +01:00
1 changed files with 19 additions and 6 deletions

View File

@ -218,15 +218,22 @@ def celsius_to_fahrenheit(celsius: float) -> float:
return celsius * 9.0 / 5.0 + 32 return celsius * 9.0 / 5.0 + 32
def heat_index(data: Any, convert: bool = False) -> float: def heat_index(data: Any, convert: bool = False) -> float | None:
"""Calculate heat index from temperature. """Calculate heat index from temperature.
data: dict with temperature and humidity data: dict with temperature and humidity
convert: bool, convert recieved data from Celsius to Fahrenheit convert: bool, convert recieved data from Celsius to Fahrenheit
""" """
temp = float(data[OUTSIDE_TEMP]) temp = data.get(OUTSIDE_TEMP, None)
rh = float(data[OUTSIDE_HUMIDITY]) rh = data.get(OUTSIDE_HUMIDITY, None)
if not temp or not rh:
return None
temp = float(temp)
rh = float(rh)
adjustment = None adjustment = None
if convert: if convert:
@ -256,15 +263,21 @@ def heat_index(data: Any, convert: bool = False) -> float:
return simple return simple
def chill_index(data: Any, convert: bool = False) -> float: def chill_index(data: Any, convert: bool = False) -> float | None:
"""Calculate wind chill index from temperature and wind speed. """Calculate wind chill index from temperature and wind speed.
data: dict with temperature and wind speed data: dict with temperature and wind speed
convert: bool, convert recieved data from Celsius to Fahrenheit convert: bool, convert recieved data from Celsius to Fahrenheit
""" """
temp = float(data[OUTSIDE_TEMP]) temp = data.get(OUTSIDE_TEMP, None)
wind = float(data[WIND_SPEED]) wind = data.get(WIND_SPEED, None)
if not temp or not wind:
return None
temp = float(temp)
wind = float(wind)
if convert: if convert:
temp = celsius_to_fahrenheit(temp) temp = celsius_to_fahrenheit(temp)