diff --git a/setup.py b/setup.py index a668678..035fe67 100644 --- a/setup.py +++ b/setup.py @@ -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, diff --git a/simple_dwd_weatherforecast/dwdforecast.py b/simple_dwd_weatherforecast/dwdforecast.py index 8d918e2..0c9b799 100644 --- a/simple_dwd_weatherforecast/dwdforecast.py +++ b/simple_dwd_weatherforecast/dwdforecast.py @@ -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): @@ -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, diff --git a/tests/test_update.py b/tests/test_update.py index e66564f..e98d256 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -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( @@ -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 @@ -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" @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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() \ No newline at end of file + 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)