Skip to content

Commit

Permalink
Fixes hourly condition
Browse files Browse the repository at this point in the history
  • Loading branch information
FL550 committed Jun 20, 2021
1 parent 530d343 commit 8a711ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 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="1.1.0",
version="1.1.1",
author="Max Fermor",
description="A simple tool to retrieve a weather forecast from DWD OpenData",
long_description=long_description,
Expand Down
5 changes: 5 additions & 0 deletions simple_dwd_weatherforecast/dwdforecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ def get_condition(self, weather_data):

if len(weather_data) == 0:
return None
if len(weather_data) == 1:
return self.weather_codes[weather_data[0][WeatherDataType.CONDITION.value]][
0
]

priority = 99
condition_text = ""
sunny_counter = 1
Expand Down
25 changes: 24 additions & 1 deletion tests/test_get_timeframe_condition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from unittest.mock import patch
from datetime import datetime
from datetime import datetime, timedelta
from simple_dwd_weatherforecast import dwdforecast
from tests.dummy_data import parsed_data

Expand Down Expand Up @@ -58,3 +58,26 @@ def test_3_max(self, _):
self.dwd_weather.get_timeframe_condition(test_time, 3),
"cloudy",
)

@patch("simple_dwd_weatherforecast.dwdforecast.Weather.update", return_value=None)
def test_hourly_timeframe(self, _):
test_time = datetime(2020, 11, 6, 4, 0)
self.assertEqual(
self.dwd_weather.get_timeframe_condition(test_time, 1),
"partlycloudy",
)
test_time = test_time + timedelta(hours=1)
self.assertEqual(
self.dwd_weather.get_timeframe_condition(test_time, 1),
"cloudy",
)
test_time = test_time + timedelta(hours=1)
self.assertEqual(
self.dwd_weather.get_timeframe_condition(test_time, 1),
"sunny",
)
test_time = test_time + timedelta(hours=1)
self.assertEqual(
self.dwd_weather.get_timeframe_condition(test_time, 1),
"fog",
)

0 comments on commit 8a711ee

Please sign in to comment.