Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/control/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def process_algorithm_results(self) -> None:
# set digital outputs according to matching output_pattern
for output in pattern["matrix"].keys():
data.data.io_states[
f"io_states{action.config.configuration.io_device}"
f"io_states{action.config.configuration.io_device_output}"
].data.set.digital_output[output] = pattern["matrix"][output]
for io in data.data.system_data.values():
if isinstance(io, AbstractIoDevice):
Expand Down
15 changes: 14 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

class UpdateConfig:

DATASTORE_VERSION = 113
DATASTORE_VERSION = 114

valid_topic = [
"^openWB/bat/config/bat_control_permitted$",
Expand Down Expand Up @@ -2958,3 +2958,16 @@ def upgrade(topic: str, payload) -> None:

self._loop_all_received_topics(upgrade)
self._append_datastore_version(113)

def upgrade_datastore_114(self) -> None:
def upgrade(topic: str, payload) -> Optional[dict]:
if re.search("openWB/io/action/[0-9]+/config", topic) is not None:
config = decode_payload(payload)
if (config["configuration"]["passthrough_enabled"] is True and
config["configuration"].get("io_device_output") is None):
config["configuration"]["io_device_output"] = config["configuration"].get("io_device")
else:
config["configuration"]["io_device_output"] = None
Comment on lines +2966 to +2970
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

upgrade_datastore_114 overwrites an already configured io_device_output: when passthrough_enabled is true but io_device_output is already set, the current else branch resets it to None. This will silently drop the user’s new output-device selection. Adjust the logic to only set a default when the key is missing/None, and otherwise preserve the existing value (and only clear it when passthrough is disabled, if that’s intended).

Suggested change
if (config["configuration"]["passthrough_enabled"] is True and
config["configuration"].get("io_device_output") is None):
config["configuration"]["io_device_output"] = config["configuration"].get("io_device")
else:
config["configuration"]["io_device_output"] = None
configuration = config.get("configuration", {})
passthrough_enabled = configuration.get("passthrough_enabled")
if passthrough_enabled:
# Only set a default if io_device_output is missing or None; preserve existing values.
if configuration.get("io_device_output") is None:
configuration["io_device_output"] = configuration.get("io_device")
else:
# When passthrough is disabled, clear io_device_output.
configuration["io_device_output"] = None
config["configuration"] = configuration

Copilot uses AI. Check for mistakes.
return {topic: config}
Comment on lines +2964 to +2971
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

upgrade_datastore_114 assumes every openWB/io/action/<id>/config payload has configuration.passthrough_enabled. For other IO actions (or type: null configs), config["configuration"]["passthrough_enabled"] can raise a KeyError and abort the upgrade. Guard via config.get("type") == "stepwise_control" (or check for the key with .get) before touching these fields, and consider anchoring the regex to ^...$ to avoid accidental matches.

Suggested change
if re.search("openWB/io/action/[0-9]+/config", topic) is not None:
config = decode_payload(payload)
if (config["configuration"]["passthrough_enabled"] is True and
config["configuration"].get("io_device_output") is None):
config["configuration"]["io_device_output"] = config["configuration"].get("io_device")
else:
config["configuration"]["io_device_output"] = None
return {topic: config}
if re.search(r"^openWB/io/action/[0-9]+/config$", topic) is not None:
config = decode_payload(payload)
# Only apply this migration to stepwise_control IO actions that are expected
# to have a passthrough_enabled flag in their configuration.
if config.get("type") == "stepwise_control":
configuration = config.get("configuration") or {}
passthrough_enabled = configuration.get("passthrough_enabled")
if passthrough_enabled is True and configuration.get("io_device_output") is None:
configuration["io_device_output"] = configuration.get("io_device")
else:
configuration["io_device_output"] = None
config["configuration"] = configuration
return {topic: config}

Copilot uses AI. Check for mistakes.
Comment on lines +2964 to +2971
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

There are existing unit tests for datastore migrations (packages/helpermodules/update_config_test.py covers e.g. upgrade_datastore_94). Adding upgrade_datastore_114 introduces new migration behavior (and edge cases like existing io_device_output / non-stepwise configs) but no corresponding test. Please add a focused test that asserts the migration only touches stepwise_control actions and that it preserves an existing io_device_output value.

Suggested change
if re.search("openWB/io/action/[0-9]+/config", topic) is not None:
config = decode_payload(payload)
if (config["configuration"]["passthrough_enabled"] is True and
config["configuration"].get("io_device_output") is None):
config["configuration"]["io_device_output"] = config["configuration"].get("io_device")
else:
config["configuration"]["io_device_output"] = None
return {topic: config}
if re.search(r"^openWB/io/action/[0-9]+/config$", topic) is not None:
config = decode_payload(payload)
# Only adjust stepwise_control actions and do not overwrite an existing io_device_output
if config.get("type") != "stepwise_control":
return None
configuration = config.get("configuration", {})
# Preserve existing io_device_output values
if configuration.get("io_device_output") is not None:
return None
# For passthrough-enabled stepwise_control actions with no io_device_output set,
# default io_device_output to the existing io_device value
if configuration.get("passthrough_enabled") is True:
configuration["io_device_output"] = configuration.get("io_device")
config["configuration"] = configuration
return {topic: config}
return None

Copilot uses AI. Check for mistakes.
self._loop_all_received_topics(upgrade)
self._append_datastore_version(114)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class StepwiseControlConfig:
devices: List[Dict] = field(default_factory=empty_list_factory)
# [{"type": "inverter", "id": 1},...]
passthrough_enabled: bool = False
io_device_output: Optional[int] = None
output_pattern: List[Dict] = field(default_factory=empty_io_pattern_stepwise_factory)


Expand Down
Loading