Skip to content

Commit

Permalink
Merge pull request #59 from briis/dev
Browse files Browse the repository at this point in the history
Add feels like temperature to calcs
  • Loading branch information
natekspencer committed Apr 24, 2023
2 parents 0eed758 + 533843b commit 437c4d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
15 changes: 15 additions & 0 deletions pyweatherflowudp/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ def dew_point_temperature(
).to(air_temperature.u)


def feels_like_temperature(
air_temperature: Quantity[float],
relative_humidity: Quantity[float],
wind_speed: Quantity[float],
) -> Quantity[float] | None:
"""Calculate the "feels like" temperature."""
# fmt: off
if (temp := heat_index(air_temperature=air_temperature, relative_humidity=relative_humidity)) is not None:
return temp
if (temp := wind_chill(air_temperature=air_temperature, wind_speed=wind_speed)) is not None:
return temp
# fmt: on
return air_temperature


def freezing_level(
air_temperature: Quantity[float], altitude: Quantity[float]
) -> Quantity[float]:
Expand Down
14 changes: 8 additions & 6 deletions pyweatherflowudp/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pint import Quantity

from .calc import wind_chill
from .calc import feels_like_temperature, wind_chill
from .const import (
EVENT_OBSERVATION_AIR,
EVENT_OBSERVATION_SKY,
Expand Down Expand Up @@ -475,11 +475,13 @@ class TempestDevice(AirSensorType, SkySensorType):
@property
def feels_like_temperature(self) -> Quantity[float] | None:
"""Return the feels like temperature in degrees Celsius (°C)."""
if self.heat_index is not None:
return self.heat_index
if self.wind_chill_temperature is not None:
return self.wind_chill_temperature
return self.air_temperature
if None in (self.air_temperature, self.relative_humidity, self.wind_speed):
return None
return feels_like_temperature(
air_temperature=self.air_temperature,
relative_humidity=self.relative_humidity,
wind_speed=self.wind_speed,
)

@property
def wind_chill_temperature(self) -> Quantity[float] | None:
Expand Down
4 changes: 2 additions & 2 deletions pyweatherflowudp/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PrecipitationType(IntEnum):
HAIL = 2
RAIN_HAIL = 3

# Handle unknown/future fan modes
# Handle unknown/future precipitation types
UNKNOWN = -1

@classmethod
Expand All @@ -31,7 +31,7 @@ class RadioStatus(IntEnum):
RADIO_ACTIVE = 3
BLE_CONNECTED = 7

# Handle unknown/future fan modes
# Handle unknown/future radio statuses
UNKNOWN = -1

@classmethod
Expand Down

0 comments on commit 437c4d1

Please sign in to comment.