@@ -349,7 +349,7 @@ def test_recharge_overhang_is_charged_before_turning_point(self):
349349 calc_input = CalculationInput (
350350 consumption = np .array ([100 , 3500 , 100 ]),
351351 production = np .array ([0 , 0 , 0 ]),
352- prices = {0 : 0.20 , 1 : 0.40 , 2 : 0.10 },
352+ prices = {0 : 0.12 , 1 : 0.40 , 2 : 0.10 },
353353 stored_energy = stored_energy ,
354354 stored_usable_energy = stored_usable_energy ,
355355 free_capacity = free_capacity ,
@@ -366,6 +366,46 @@ def test_recharge_overhang_is_charged_before_turning_point(self):
366366 msg = "Expected to charge only the overhang before the turning point"
367367 )
368368
369+ def test_recharge_overhang_is_skipped_when_current_price_too_high (self ):
370+ """Test that overhang precharge is skipped if current price is too far from next low."""
371+ self .logic .enable_precharge_overhang = True
372+ self .logic .max_charge_loss_factor = 0.1
373+ self .logic .set_calculation_parameters (
374+ CalculationParameters (
375+ max_charging_from_grid_limit = 0.79 ,
376+ min_price_difference = 0.05 ,
377+ min_price_difference_rel = 0.2 ,
378+ max_capacity = self .max_capacity ,
379+ max_grid_charge_rate = 2000
380+ )
381+ )
382+
383+ stored_energy = 1000
384+ stored_usable_energy , free_capacity = self ._calculate_battery_values (
385+ stored_energy ,
386+ self .max_capacity
387+ )
388+
389+ calc_input = CalculationInput (
390+ consumption = np .array ([100 , 3500 , 100 ]),
391+ production = np .array ([0 , 0 , 0 ]),
392+ prices = {0 : 0.20 , 1 : 0.40 , 2 : 0.10 },
393+ stored_energy = stored_energy ,
394+ stored_usable_energy = stored_usable_energy ,
395+ free_capacity = free_capacity ,
396+ )
397+
398+ calc_timestamp = datetime .datetime (2025 , 6 , 20 , 12 , 0 , 0 , tzinfo = datetime .timezone .utc )
399+ self .assertTrue (self .logic .calculate (calc_input , calc_timestamp ))
400+ calc_output = self .logic .get_calculation_output ()
401+
402+ self .assertAlmostEqual (
403+ calc_output .required_recharge_energy ,
404+ 3100.0 ,
405+ delta = 0.1 ,
406+ msg = "Expected full recharge amount when current price is still too expensive"
407+ )
408+
369409 def test_recharge_overhang_feature_flag_disables_behavior (self ):
370410 """Test that disabling the feature flag keeps full recharge amount."""
371411 self .logic .enable_precharge_overhang = False
0 commit comments