Skip to content

Active bat control: update power_limit_mode#3169

Open
ndrsnhs wants to merge 4 commits intoopenWB:masterfrom
ndrsnhs:remove-power_limit_mode
Open

Active bat control: update power_limit_mode#3169
ndrsnhs wants to merge 4 commits intoopenWB:masterfrom
ndrsnhs:remove-power_limit_mode

Conversation

@ndrsnhs
Copy link
Copy Markdown
Contributor

@ndrsnhs ndrsnhs commented Mar 2, 2026

Regelmodus no_limit existiert in der Form nicht mehr, kann aber ggfs. noch gesetzt sein

@LKuemmel
Copy link
Copy Markdown
Contributor

LKuemmel commented Mar 3, 2026

@ndrsnhs Bitte ein Rebase machen.

Copy link
Copy Markdown
Contributor

@benderl benderl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitte auch die anderen alten Bezeichnungen migrieren. "no_limit" ist nur einer von dreien.

@benderl benderl added the bug Something isn't working label Apr 1, 2026
@ndrsnhs ndrsnhs closed this Apr 8, 2026
@ndrsnhs ndrsnhs force-pushed the remove-power_limit_mode branch from cbd2b6d to ce0aaa4 Compare April 8, 2026 05:58
@ndrsnhs ndrsnhs reopened this Apr 8, 2026
@ndrsnhs ndrsnhs requested review from LKuemmel and benderl April 8, 2026 06:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bumps the datastore version and adds a new datastore migration to normalize legacy openWB/bat/config/power_limit_mode values that may still be present (e.g. no_limit).

Changes:

  • Increase UpdateConfig.DATASTORE_VERSION from 119 to 120.
  • Add upgrade_datastore_120 to migrate openWB/bat/config/power_limit_mode to current mode values.
  • Append datastore version 120 after running the new migration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3050 to +3058
def upgrade(topic: str, payload) -> None:
if re.search("openWB/bat/config/power_limit_mode", topic) is not None:
mode = decode_payload(payload)
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
else:
mode = "mode_discharge_home_consumption"
return {topic: mode}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In upgrade_datastore_120, the else branch rewrites any existing openWB/bat/config/power_limit_mode value to mode_discharge_home_consumption. This will unintentionally override already-valid values like mode_no_discharge or mode_charge_pv_production and change user configuration during migration. Only map the legacy values you want to replace (e.g. no_limit, limit_stop) and return None for already-valid/unknown values so they remain unchanged.

Suggested change
def upgrade(topic: str, payload) -> None:
if re.search("openWB/bat/config/power_limit_mode", topic) is not None:
mode = decode_payload(payload)
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
else:
mode = "mode_discharge_home_consumption"
return {topic: mode}
def upgrade(topic: str, payload) -> Optional[dict]:
if re.search("openWB/bat/config/power_limit_mode", topic) is not None:
mode = decode_payload(payload)
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
return None

Copilot uses AI. Check for mistakes.
Comment on lines +3050 to +3055
def upgrade(topic: str, payload) -> None:
if re.search("openWB/bat/config/power_limit_mode", topic) is not None:
mode = decode_payload(payload)
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested upgrade callback is annotated as returning None, but it returns a dict in the migration paths. Please change the return type to Optional[dict] (as used by other upgrade_datastore_* functions) to keep typing consistent and avoid misleading static analysis.

Copilot uses AI. Check for mistakes.

def upgrade_datastore_120(self) -> None:
def upgrade(topic: str, payload) -> None:
if re.search("openWB/bat/config/power_limit_mode", topic) is not None:
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The topic match uses re.search("openWB/bat/config/power_limit_mode", topic) without anchors. Using an exact match (e.g. ^openWB/bat/config/power_limit_mode$) avoids accidentally matching unintended topics if similarly named topics are added later, and is consistent with the valid_topic regex patterns.

Suggested change
if re.search("openWB/bat/config/power_limit_mode", topic) is not None:
if re.search("^openWB/bat/config/power_limit_mode$", topic) is not None:

Copilot uses AI. Check for mistakes.
Comment on lines +3053 to +3058
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
else:
mode = "mode_discharge_home_consumption"
return {topic: mode}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration introduces new mapping behavior for openWB/bat/config/power_limit_mode, but there is no test covering the conversion (and especially that already-valid modes are left unchanged). Please add a pytest case similar to existing datastore upgrade tests to prevent regressions.

Suggested change
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
else:
mode = "mode_discharge_home_consumption"
return {topic: mode}
legacy_mode_mapping = {
"no_limit": "mode_no_discharge",
"limit_stop": "mode_no_discharge",
"limit": "mode_discharge_home_consumption",
}
if mode in legacy_mode_mapping:
return {topic: legacy_mode_mapping[mode]}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3049 to +3058
def upgrade_datastore_120(self) -> None:
def upgrade(topic: str, payload) -> Optional[dict]:
if re.search("^openWB/bat/config/power_limit_mode$", topic) is not None:
mode = decode_payload(payload)
if mode == "no_limit" or mode == "limit_stop":
mode = "mode_no_discharge"
return {topic: mode}
elif mode == "limit_home_consumption":
mode = "mode_discharge_home_consumption"
return {topic: mode}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this new datastore migration (mapping legacy values like "no_limit"/"limit_stop"/"limit_home_consumption" to the current BatPowerLimitMode strings), please add a focused unit test (similar to existing upgrade_datastore_94 coverage in packages/helpermodules/update_config_test.py) to prevent regressions and to document the intended mapping behavior.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants