Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5e60445

Browse files
committedDec 7, 2024
Adjust time handling for solar forecast calculations
1 parent 70206b0 commit 5e60445

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed
 

‎source/main.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ def log_solar_forecast(log_as_review: bool = False) -> None:
1414
sun_forecast_handler = SunForecastHandler()
1515
deprecated_sun_forecast_handler = DeprecatedSunForecastHandler()
1616

17-
start = datetime.now(tz=TimeHandler.get_timezone()).replace(hour=0, minute=0, second=0, microsecond=0)
18-
end = start + timedelta(days=1)
17+
now = datetime.now(tz=TimeHandler.get_timezone())
18+
start = now.replace(hour=5, minute=0, second=0, microsecond=0)
19+
end = now.replace(hour=23, minute=0, second=0, microsecond=0)
20+
if log_as_review:
21+
end -= timedelta(minutes=2)
22+
1923
solar_output_today = sun_forecast_handler.get_solar_output_in_timeframe(start, end)
2024
solar_output_today_deprecated = deprecated_sun_forecast_handler.get_expected_solar_output_of_today()
2125
if log_as_review:

‎source/sun_forecast_handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def _get_debug_solar_output(self) -> EnergyAmount:
4040
def get_solar_output_in_timeframe(self, timestamp_start: datetime, timestamp_end: datetime) -> EnergyAmount:
4141
solar_data = []
4242

43-
now = datetime.now(tz=(TimeHandler.get_timezone())) - timedelta(
44-
minutes=1
43+
now = datetime.now(tz=(TimeHandler.get_timezone())).replace(second=0, microsecond=0) - timedelta(
44+
seconds=1
4545
) # Account for execution times of the program
4646
if timestamp_start >= now or timestamp_end >= now:
4747
self.log.trace("Need to retrieve forecast data")

0 commit comments

Comments
 (0)
Please sign in to comment.