Skip to content

Commit

Permalink
Adjust time handling for solar forecast calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
felixschndr committed Dec 7, 2024
1 parent 9f6ed04 commit 16024dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ def log_solar_forecast(log_as_review: bool = False) -> None:
sun_forecast_handler = SunForecastHandler()
deprecated_sun_forecast_handler = DeprecatedSunForecastHandler()

start = datetime.now(tz=TimeHandler.get_timezone()).replace(hour=0, minute=0, second=0, microsecond=0)
end = start + timedelta(days=1)
now = datetime.now(tz=TimeHandler.get_timezone())
start = now.replace(hour=5, minute=0, second=0, microsecond=0)
end = now.replace(hour=23, minute=0, second=0, microsecond=0)
if log_as_review:
end -= timedelta(minutes=2)

solar_output_today = sun_forecast_handler.get_solar_output_in_timeframe(start, end)
solar_output_today_deprecated = deprecated_sun_forecast_handler.get_expected_solar_output_of_today()
if log_as_review:
Expand Down
4 changes: 2 additions & 2 deletions source/sun_forecast_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def _get_debug_solar_output(self) -> EnergyAmount:
def get_solar_output_in_timeframe(self, timestamp_start: datetime, timestamp_end: datetime) -> EnergyAmount:
solar_data = []

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

0 comments on commit 16024dd

Please sign in to comment.