@@ -69,7 +69,9 @@ def get_next_price_minimum(self, first_iteration: bool = False) -> EnergyRate:
69
69
energy_rates_between_first_and_second_maximum
70
70
)
71
71
72
- if self ._check_if_minimum_is_at_end_of_day (minimum_of_energy_rates ):
72
+ if self ._check_if_minimum_is_at_end_of_day_and_energy_rates_of_tomorrow_are_unavailable (
73
+ minimum_of_energy_rates , upcoming_energy_rates
74
+ ):
73
75
minimum_of_energy_rates .is_minimum_that_has_to_be_rechecked = True
74
76
75
77
return minimum_of_energy_rates
@@ -257,20 +259,34 @@ def get_global_minimum_of_energy_rates(self, energy_rates_till_maximum: list[Ene
257
259
)
258
260
return global_minimum_of_energy_rates
259
261
260
- def _check_if_minimum_is_at_end_of_day (self , price_minimum : EnergyRate ) -> bool :
262
+ def _check_if_minimum_is_at_end_of_day_and_energy_rates_of_tomorrow_are_unavailable (
263
+ self , price_minimum : EnergyRate , upcoming_energy_rates : list [EnergyRate ]
264
+ ) -> bool :
261
265
"""
262
- This method determines whether the timestamp of the `price_minimum` falls within the last 3 hours a day.
263
- This is done since the price rates of the next day are only available after ~ 02:00 PM.
266
+ This method determines whether the timestamp of the `price_minimum` is in the last hour of the day and checks if
267
+ there are no energy rates available for the subsequent day.
268
+ This is done since the price rates of the next day are only available after ~ 02:00 PM. If the price rates of
269
+ the next day are unavailable while determining the price minimum, it is likely that the price minimum is just
270
+ the last rate of the day but not actually the minimum.
271
+ In this case we have to check in later (at ~ 02:00 PM) to re-request the prices from the Tibber API to get
272
+ the values of the next day.
264
273
265
274
Args:
266
275
price_minimum (EnergyRate): The energy rate with the minimum price.
276
+ upcoming_energy_rates (list[EnergyRate]): List of upcoming energy rates.
267
277
268
278
Returns:
269
- bool: True if the price minimum is in the last 3 hours of the day, otherwise False.
279
+ bool: True if the price minimum is in the last hour current day and there are no rates for
280
+ the next day, otherwise False.
270
281
"""
271
282
272
- is_price_minimum_near_end_of_day = 21 <= price_minimum .timestamp .hour < = 23
283
+ is_price_minimum_near_end_of_day = price_minimum .timestamp .hour = = 23
273
284
self .log .trace (
274
285
f"The price minimum { price_minimum .timestamp } is at the end of the day: { is_price_minimum_near_end_of_day } "
275
286
)
276
- return is_price_minimum_near_end_of_day
287
+
288
+ today = datetime .now ().date ()
289
+ are_tomorrows_rates_unavailable = all (rate .timestamp .date () == today for rate in upcoming_energy_rates )
290
+ self .log .trace (f"The price rates for tomorrow are unavailable: { are_tomorrows_rates_unavailable } " )
291
+
292
+ return is_price_minimum_near_end_of_day and are_tomorrows_rates_unavailable
0 commit comments