Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pynws/simple_nws.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,17 @@ def _convert_forecast(
if (value := forecast_entry.get("temperature")) is not None:
forecast_entry["temperature"] = int(value)

temp_unit = forecast_entry.get("temperatureUnit")

for key in ("probabilityOfPrecipitation", "dewpoint", "relativeHumidity"):
if (value := SimpleNWS.extract_value(forecast_entry, key)) is not None:
forecast_entry[key] = int(value[0])
extracted = SimpleNWS.extract_value(forecast_entry, key)
if isinstance(extracted, tuple):
value, value_unit = extracted
if value_unit.endswith("degC") and temp_unit == "F":
value = round(float(value) * 1.8 + 32, 0)
elif value_unit.endswith("degF") and temp_unit == "C":
value = round((float(value) - 32) / 1.8, 0)
forecast_entry[key] = int(value)

if forecast_entry.get("icon"):
time, weather = parse_icon(forecast_entry["icon"])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_simple_nws.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def test_nws_forecast(aiohttp_client, event_loop, mock_urls):

assert forecast[0]["temperature"] == 41
assert forecast[0]["probabilityOfPrecipitation"] == 20
assert forecast[0]["dewpoint"] == 5
assert forecast[0]["dewpoint"] == 41
assert forecast[0]["relativeHumidity"] == 63

assert forecast[0]["iconWeather"][0][0] == "Thunderstorm (high cloud cover)"
Expand Down Expand Up @@ -200,7 +200,7 @@ async def test_nws_forecast_hourly(aiohttp_client, event_loop, mock_urls):

assert forecast[0]["temperature"] == 78
assert forecast[0]["probabilityOfPrecipitation"] == 20
assert forecast[0]["dewpoint"] == 5
assert forecast[0]["dewpoint"] == 41
assert forecast[0]["relativeHumidity"] == 63


Expand Down