Skip to content

Commit

Permalink
Fix BW missing in weather reports
Browse files Browse the repository at this point in the history
  • Loading branch information
FL550 committed Oct 31, 2023
1 parent bbf1ea6 commit 12fc447
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 47 deletions.
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.22",
version="2.0.23",
author="Max Fermor",
description="A simple tool to retrieve a weather forecast from DWD OpenData",
long_description=long_description,
Expand Down
37 changes: 19 additions & 18 deletions simple_dwd_weatherforecast/dwdforecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,22 @@ class Weather:
}

region_codes = {
"NW": "dweh",
"NI": "dwhg",
"HB": "dwhg",
"SH": "dwhh",
"HH": "dwhh",
"SN": "dwlg",
"ST": "dwlh",
"TH": "dwli",
"BY": "dwmg",
"DW": "dwsg",
"HE": "dwoh",
"RP": "dwoi",
"SL": "dwoi",
"BB": "dwpg",
"BE": "dwpg",
"MV": "dwph",
"NW": "dweh", # Nordrhein-Westfalen
"NI": "dwhg", # Niedersachsen
"HB": "dwhg", # Bremen
"SH": "dwhh", # Schleswig-Holstein
"HH": "dwhh", # Hamburg
"SN": "dwlg", # Sachsen
"ST": "dwlh", # Sachsen-Anhalt
"TH": "dwli", # Thueringen
"BY": "dwmg", # Bayern
"BW": "dwsg", # Baden-Württemberg
"HE": "dwoh", # Hessen
"RP": "dwoi", # Rheinland-Pfalz
"SL": "dwoi", # Saarland
"BB": "dwpg", # Brandenburg
"BE": "dwpg", # Berlin
"MV": "dwph", # Mecklenburg-Vorpommern
}

def __init__(self, station_id):
Expand Down Expand Up @@ -734,8 +734,9 @@ def parse_csv_row(self, row: dict):
if row[WeatherDataType.VISIBILITY.value[1]] != self.NOT_AVAILABLE
else None,
WeatherDataType.SUN_IRRADIANCE.value[0]: round(
float(row[WeatherDataType.SUN_IRRADIANCE.value[1]].replace(",", ".")) * 3.6
, 1
float(row[WeatherDataType.SUN_IRRADIANCE.value[1]].replace(",", "."))
* 3.6,
1,
)
if row[WeatherDataType.SUN_IRRADIANCE.value[1]] != self.NOT_AVAILABLE
else None,
Expand Down
87 changes: 59 additions & 28 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,44 @@ def setUp(self):
self.dwd_weather.station_name = "BAD HOMBURG"

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
def test_download(self, _1, _2):
self.dwd_weather.update()
self.assertIsNotNone(self.dwd_weather.forecast_data)

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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, _1, _2):
self.dwd_weather.update()
mock_function.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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, _1, _2):
self.dwd_weather.issue_time = datetime(
Expand All @@ -53,13 +62,16 @@ def test_issue_time_old(self, mock_function, _1, _2):
mock_function.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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 @@ -72,7 +84,7 @@ def test_issue_time_actual(self, mock_parse_kml, _1, _2, _3):

class WeatherDownload(unittest.TestCase):
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
)
def test_etag_valid(self, mock_function):
stationid = "H889"
Expand All @@ -83,18 +95,20 @@ def test_etag_valid(self, mock_function):
mock_function.assert_called_once()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
)
def test_etag_invalid(self, mock_function):
stationid = "H889"
self.dwd_weather = dwdforecast.Weather(stationid)
self.dwd_weather.etags = {}
self.dwd_weather.etags["https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/{stationid}/kml/MOSMIX_L_LATEST_{stationid}.kmz"] = "invalid_etag"
self.dwd_weather.etags[
"https://opendata.dwd.de/weather/local_forecasts/mos/MOSMIX_L/single_stations/{stationid}/kml/MOSMIX_L_LATEST_{stationid}.kmz"
] = "invalid_etag"
self.dwd_weather.download_latest_kml(stationid)
mock_function.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.parse_kml", return_value=None
)
def test_etag_missing(self, mock_function):
stationid = "H889"
Expand All @@ -104,13 +118,16 @@ def test_etag_missing(self, mock_function):
mock_function.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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 @@ -121,13 +138,16 @@ def test_report_not_called(self, _1, _2, _3, mock_download_latest_report):
mock_download_latest_report.assert_not_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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 @@ -138,13 +158,16 @@ def test_measurements_called(self, _1, _2, _3, mock_download_latest_report):
mock_download_latest_report.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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 @@ -156,13 +179,16 @@ def test_weather_report_called(self, _1, _2, mock_download_weather_report, _3):
mock_download_weather_report.assert_called()

@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report", return_value=None
"simple_dwd_weatherforecast.dwdforecast.Weather.download_latest_report",
return_value=None,
)
@patch(
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report", return_value=None,
"simple_dwd_weatherforecast.dwdforecast.Weather.download_weather_report",
return_value=None,
)
@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 @@ -171,4 +197,9 @@ def test_weather_report_not_called(self, _1, _2, mock_download_weather_report, _
self.dwd_weather = dwdforecast.Weather("01008")
self.dwd_weather.region = None
self.dwd_weather.update()
mock_download_weather_report.assert_not_called()
mock_download_weather_report.assert_not_called()

def test_weather_report_available(self):
self.dwd_weather = dwdforecast.Weather("10739")
self.dwd_weather.update(with_report=True)
self.assertIsNotNone(self.dwd_weather.weather_report)

0 comments on commit 12fc447

Please sign in to comment.