Skip to content

Commit

Permalink
Fix get daily condition current day
Browse files Browse the repository at this point in the history
  • Loading branch information
FL550 committed Sep 3, 2024
1 parent 1d88e59 commit 6bb62ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 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.33",
version="2.0.34",
author="Max Fermor",
description="A simple tool to retrieve a weather forecast from DWD OpenData",
long_description=long_description,
Expand Down
13 changes: 9 additions & 4 deletions simple_dwd_weatherforecast/dwdforecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,15 @@ def is_in_timerange_day(self, timestamp: datetime):
return (
self.strip_to_day(
arrow.get(
list(self.forecast_data.keys())[0], "YYYY-MM-DDTHH:mm:ss.SSSZ" # type: ignore
list(self.forecast_data.keys())[0], # type: ignore
"YYYY-MM-DDTHH:mm:ss.SSSZ", # type: ignore
).datetime
)
<= self.strip_to_day(timestamp)
<= self.strip_to_day(
arrow.get(
list(self.forecast_data.keys())[-1], "YYYY-MM-DDTHH:mm:ss.SSSZ" # type: ignore
list(self.forecast_data.keys())[-1], # type: ignore
"YYYY-MM-DDTHH:mm:ss.SSSZ", # type: ignore
).datetime
)
)
Expand Down Expand Up @@ -356,9 +358,11 @@ def get_timeframe_condition(
return None

def get_daily_condition(self, timestamp: datetime, shouldUpdate=True):
print("testieng")
if shouldUpdate:
self.update()
if self.is_in_timerange(timestamp):
if self.is_in_timerange_day(timestamp):
print("working")
return self.get_condition(self.get_day_values(timestamp))
return None

Expand Down Expand Up @@ -609,7 +613,8 @@ def get_day_values(self, timestamp: datetime):
"timestamp has to be checked prior to be in timerange"
result = []
first_entry_date = arrow.get(
next(iter(self.forecast_data)), "YYYY-MM-DDTHH:mm:ss.SSSZ" # type: ignore
next(iter(self.forecast_data)), # type: ignore
"YYYY-MM-DDTHH:mm:ss.SSSZ", # type: ignore
).datetime # type: ignore
if timestamp.day != first_entry_date.day:
time_step = self.strip_to_day(timestamp)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_get_daily_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ def test_3_max(self, _):
self.dwd_weather.get_daily_condition(test_time),
"cloudy",
)

@patch("simple_dwd_weatherforecast.dwdforecast.Weather.update", return_value=None)
def test_same_day(self, _):
test_time = datetime(2020, 11, 6, 0, 0)
self.assertEqual(
self.dwd_weather.get_daily_condition(test_time),
"sunny",
)

0 comments on commit 6bb62ba

Please sign in to comment.