Skip to content

Commit bec8e06

Browse files
committed
Refactor solar data cache getter to not require timestamps if the cache is used
1 parent 65117f1 commit bec8e06

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

source/inverter_charge_controller.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def _is_next_price_minimum_reachable_by_charging_the_battery_fully(
254254
average_power_consumption,
255255
target_max_soc,
256256
self.next_price_minimum.has_to_be_rechecked,
257-
self._get_solar_data(timestamp_now, self.next_price_minimum.timestamp),
257+
self._get_solar_data(),
258258
)
259259
)
260260
if minimum_of_soc_until_next_price_minimum >= target_min_soc:
@@ -587,12 +587,17 @@ def _get_average_power_consumption(self) -> Power:
587587
self._set_cache_key(cache_key, average_power_consumption)
588588
return average_power_consumption
589589

590-
def _get_solar_data(self, timeframe_start: datetime, timeframe_end: datetime) -> dict[str, Power]:
590+
def _get_solar_data(
591+
self, timeframe_start: Optional[datetime] = None, timeframe_end: Optional[datetime] = None
592+
) -> dict[str, Power]:
591593
cache_key = "solar_data"
592594
solar_data = self._get_value_from_cache_if_exists(cache_key)
593595
if solar_data:
594596
return solar_data
595597

598+
if not timeframe_start or not timeframe_end:
599+
raise ValueError("Timeframe start and end must be provided to retrieve solar data if the cache is empty")
600+
596601
solar_data = self.sun_forecast_handler.retrieve_solar_data(timeframe_start, timeframe_end)
597602
self._set_cache_key(cache_key, solar_data)
598603
return solar_data

0 commit comments

Comments
 (0)