Skip to content

Commit

Permalink
Replaces missing precipitation data from hourly
Browse files Browse the repository at this point in the history
  • Loading branch information
FL550 committed Oct 6, 2023
1 parent 1660228 commit 7873aa9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ There is also data available which is updated every hour by DWD. Be careful thou
- PRECIPITATION_PROBABILITY
- PRECIPITATION_DURATION

These values will be replaced by the 6 hour forecast.

You can use this data by using the optional parameter `force_hourly=True`.

```python
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="simple_dwd_weatherforecast",
version="2.0.15",
version="2.0.16",
author="Max Fermor",
description="A simple tool to retrieve a weather forecast from DWD OpenData",
long_description=long_description,
Expand Down
7 changes: 7 additions & 0 deletions simple_dwd_weatherforecast/dwdforecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,14 @@ def update(
or (datetime.now(timezone.utc) - self.issue_time >= timedelta(hours=6))
or force_hourly
):
if force_hourly:
self.download_latest_kml(self.station_id)
temp_forecast_data = self.forecast_data
self.download_latest_kml(self.station_id, force_hourly)
if force_hourly:
for item in self.forecast_data:
self.forecast_data[item]["wwP"] = temp_forecast_data[item]["wwP"]
self.forecast_data[item]["DRR1"] = temp_forecast_data[item]["DRR1"]

def get_weather_type(self, kmlTree, weatherDataType: WeatherDataType):
"""Parses the kml-File to the requested value and returns the items as array"""
Expand Down
23 changes: 20 additions & 3 deletions tests/test_update_hourly.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ def test_download(self):
self.assertIsNotNone(self.dwd_weather.forecast_data)

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_kml", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_kml",
return_value=None,
)
def test_issue_time_none(self, mock_function):
self.dwd_weather.update()
mock_function.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_kml", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_kml",
return_value=None,
)
def test_issue_time_old(self, mock_function):
self.dwd_weather.issue_time = datetime(
Expand All @@ -36,7 +38,8 @@ def test_issue_time_old(self, mock_function):
mock_function.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_kml", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_kml",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
Expand All @@ -45,3 +48,17 @@ def test_issue_time_actual(self, mock_function, _):
self.dwd_weather.issue_time = datetime.now(timezone.utc)
self.dwd_weather.update()
mock_function.assert_not_called()

def test_replace_of_prec_probability_duration(self):
timestamp = datetime.now(timezone.utc)
self.dwd_weather.update(force_hourly=True)
self.assertIsNotNone(
self.dwd_weather.get_forecast_data(
dwdforecast.WeatherDataType.PRECIPITATION_PROBABILITY, timestamp
)
)
self.assertIsNotNone(
self.dwd_weather.get_forecast_data(
dwdforecast.WeatherDataType.PRECIPITATION_DURATION, timestamp
)
)

0 comments on commit 7873aa9

Please sign in to comment.