@@ -365,41 +365,18 @@ def _coordinate_charging_next_price_minimum_is_reachable(
365
365
next price minimum.
366
366
"""
367
367
if current_energy_rate >= self .next_price_minimum :
368
- self .log .info (
369
- f"The price of the current minimum ({ current_energy_rate .rate } ct/kWh) is higher than the one of "
370
- f"the upcoming minimum ({ self .next_price_minimum .rate } ct/kWh) "
371
- "--> Will only charge the battery to reach the next price minimum"
372
- )
373
- if minimum_of_soc_until_next_price_minimum > self .target_min_soc :
374
- self .log .info (
375
- "The expected minimum state of charge until the next price minimum without additional charging "
376
- f"{ minimum_of_soc_until_next_price_minimum } is higher than the target minimum state of charge "
377
- f"{ self .target_min_soc } --> There is no need to charge"
378
- )
379
- return
380
-
381
- self .log .debug (
382
- f"Formula for calculating the target state of charge: current { current_state_of_charge } + "
383
- f"target minimum state of charge ({ self .target_min_soc } ) - minimum state of charge until next price "
384
- f"minimum ({ minimum_of_soc_until_next_price_minimum } )"
385
- )
386
368
charging_target_soc = (
387
- current_state_of_charge + self .target_min_soc - minimum_of_soc_until_next_price_minimum
369
+ self ._calculate_target_soc_next_price_minimum_is_reachable_and_current_minimum_is_higher_than_next_one (
370
+ current_energy_rate , current_state_of_charge , minimum_of_soc_until_next_price_minimum
371
+ )
388
372
)
389
-
373
+ if charging_target_soc is None :
374
+ return
390
375
else :
391
- self .log .info (
392
- f"The price of the upcoming minimum ({ self .next_price_minimum .rate } ct/kWh) is higher than the one of "
393
- f"the current minimum ({ current_energy_rate .rate } ct/kWh) "
394
- "--> Will charge as much as possible without wasting any energy of the sun"
395
- )
396
- self .log .debug (
397
- f"Formula for calculating the target state of charge: current ({ current_state_of_charge } ) + "
398
- f"target maximum state of charge ({ self .target_max_soc } ) - "
399
- f"maximum state of charge until next price minimum ({ maximum_of_soc_until_next_price_minimum } )"
400
- )
401
376
charging_target_soc = (
402
- current_state_of_charge + self .target_max_soc - maximum_of_soc_until_next_price_minimum
377
+ self ._calculate_target_soc_next_price_minimum_is_reachable_and_current_minimum_is_lower_than_next_one (
378
+ current_energy_rate , current_state_of_charge , maximum_of_soc_until_next_price_minimum
379
+ )
403
380
)
404
381
405
382
self .log .info (f"The calculated target state of charge is { charging_target_soc } " )
@@ -414,6 +391,50 @@ def _coordinate_charging_next_price_minimum_is_reachable(
414
391
with self ._protocol_amount_of_energy_bought ():
415
392
self ._charge_inverter (charging_target_soc )
416
393
394
+ def _calculate_target_soc_next_price_minimum_is_reachable_and_current_minimum_is_higher_than_next_one (
395
+ self ,
396
+ current_energy_rate : EnergyRate ,
397
+ current_state_of_charge : StateOfCharge ,
398
+ minimum_of_soc_until_next_price_minimum : StateOfCharge ,
399
+ ) -> Optional [StateOfCharge ]:
400
+ self .log .info (
401
+ f"The price of the current minimum ({ current_energy_rate .rate } ct/kWh) is higher than the one of "
402
+ f"the upcoming minimum ({ self .next_price_minimum .rate } ct/kWh) "
403
+ "--> Will only charge the battery to reach the next price minimum"
404
+ )
405
+ if minimum_of_soc_until_next_price_minimum > self .target_min_soc :
406
+ self .log .info (
407
+ "The expected minimum state of charge until the next price minimum without additional charging "
408
+ f"{ minimum_of_soc_until_next_price_minimum } is higher than the target minimum state of charge "
409
+ f"{ self .target_min_soc } --> There is no need to charge"
410
+ )
411
+ return None
412
+
413
+ self .log .debug (
414
+ f"Formula for calculating the target state of charge: current { current_state_of_charge } + "
415
+ f"target minimum state of charge ({ self .target_min_soc } ) - minimum state of charge until next price "
416
+ f"minimum ({ minimum_of_soc_until_next_price_minimum } )"
417
+ )
418
+ return current_state_of_charge + self .target_min_soc - minimum_of_soc_until_next_price_minimum
419
+
420
+ def _calculate_target_soc_next_price_minimum_is_reachable_and_current_minimum_is_lower_than_next_one (
421
+ self ,
422
+ current_energy_rate : EnergyRate ,
423
+ current_state_of_charge : StateOfCharge ,
424
+ maximum_of_soc_until_next_price_minimum : StateOfCharge ,
425
+ ) -> StateOfCharge :
426
+ self .log .info (
427
+ f"The price of the upcoming minimum ({ self .next_price_minimum .rate } ct/kWh) is higher than the one of "
428
+ f"the current minimum ({ current_energy_rate .rate } ct/kWh) "
429
+ "--> Will charge as much as possible without wasting any energy of the sun"
430
+ )
431
+ self .log .debug (
432
+ f"Formula for calculating the target state of charge: current ({ current_state_of_charge } ) + "
433
+ f"target maximum state of charge ({ self .target_max_soc } ) - "
434
+ f"maximum state of charge until next price minimum ({ maximum_of_soc_until_next_price_minimum } )"
435
+ )
436
+ return current_state_of_charge + self .target_max_soc - maximum_of_soc_until_next_price_minimum
437
+
417
438
def _charge_inverter (self , target_state_of_charge : StateOfCharge ) -> None :
418
439
"""
419
440
Charges the inverter battery to the target state of charge within a specified maximum charging duration.
0 commit comments