diff --git a/pynws/simple_nws.py b/pynws/simple_nws.py index cf1ce21..ec88cb0 100644 --- a/pynws/simple_nws.py +++ b/pynws/simple_nws.py @@ -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"]) diff --git a/tests/test_simple_nws.py b/tests/test_simple_nws.py index 7d12ed6..381efe0 100644 --- a/tests/test_simple_nws.py +++ b/tests/test_simple_nws.py @@ -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)" @@ -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