active bat control: improve manual charge logic#3161
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the manual battery charge logic in the get_charge_mode_manual_charge method to make active charging independent of grid and battery power conditions. The key changes ensure that manual charge mode forces charging unconditionally, while manual limit mode now properly allows self-regulation when surplus power is available or the battery is already charging.
Changes:
- Simplified validation logic for manual battery control modes
- Made MANUAL_CHARGE unconditional (always forces charging regardless of grid/battery state)
- Restructured MANUAL_LIMIT to allow self-regulation when surplus exists or battery is charging
- Removed MANUAL_DISCHARGE handling (feature marked as "not allowed in Germany")
Comments suppressed due to low confidence (3)
packages/control/bat_all.py:482
- Spelling error in German comment: "Eingespeist ird" should be "Eingespeist wird" (missing 'w').
# Limit nicht anwenden wenn viel Eingespeist ird oder der Speicher lädt
packages/control/bat_all.py:475
- The comment at line 473 is outdated and misleading. It states "EVU Bezug vorhanden oder gewollte PV-Ladung aktiv" (Grid consumption present or desired PV charging active), but the variables below no longer check for MODE_CHARGE_PV_PRODUCTION. The variable evu_power_valid now only checks if grid power >= -100, and bat_power_valid only checks if battery power <= 0. The comment should be updated to accurately reflect what these variables check, for example: "EVU Bezug vorhanden" (Grid consumption present) and "Speicher entlädt oder steht still" (Battery discharging or idle).
# EVU Bezug vorhanden oder gewollte PV-Ladung aktiv
evu_power_valid = data.data.counter_all_data.get_evu_counter().data.get.power >= -100
bat_power_valid = self.data.get.power <= 0
packages/control/bat_all.py:486
- The debug message at line 486 states "Kein Limit da Speicher lädt" (No limit because battery is charging), but this message is logged in the else block which is executed when EITHER there is surplus (evu_power < -100) OR the battery is charging (bat_power > 0). The message should be updated to reflect both conditions, for example: "Kein Limit da Überschuss vorhanden oder Speicher lädt" (No limit because surplus available or battery is charging).
log.debug("Aktive Speichersteuerung: Manueller Modus - Kein Limit da Speicher lädt")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/control/bat_all.py
Outdated
| elif self.data.config.manual_mode == ManualMode.MANUAL_LIMIT.value: | ||
| if (self.data.config.power_limit_mode == BatPowerLimitMode.MODE_CHARGE_PV_PRODUCTION.value or | ||
| (evu_power_valid and bat_power_valid)): | ||
| # Limit nicht anwenden wenn viel Eingespeist ird oder der Speicher lädt |
There was a problem hiding this comment.
The comment is misleading or incorrect. The comment states "Limit nicht anwenden wenn viel Eingespeist wird oder der Speicher lädt" (Do not apply limit when much is fed in or the battery is charging), but the code does the opposite: it APPLIES the limit (returns BAT_USE_LIMIT) when the condition is true. The condition is true when MODE_CHARGE_PV_PRODUCTION is active OR when there is NOT much feed-in (evu_power >= -100) AND the battery is NOT charging (bat_power <= 0). The comment should be corrected to accurately reflect what the code does, for example: "Limit anwenden wenn kein Überschuss vorhanden oder der Speicher nicht lädt" (Apply limit when no surplus available or the battery is not charging).
| # Limit nicht anwenden wenn viel Eingespeist ird oder der Speicher lädt | |
| # Limit anwenden wenn kein Überschuss vorhanden oder der Speicher nicht lädt |
Speicherlimitierung ist an Speicher- und EVU-Leistung gebunden.
Ist Überschuss im System vorhanden soll kein Limit greifen damit die Eigenregelung des Speichers weiterhin laden kann falls dies möglich ist.
Die Aktive Ladung muss unabhängig von dieser Logik sein, also immer durchgeführt werden.