Skip to content

add voltage regulation for battery creation#209

Open
EtienneLt wants to merge 1 commit into
mainfrom
add-battery-creation-voltage-regulation
Open

add voltage regulation for battery creation#209
EtienneLt wants to merge 1 commit into
mainfrom
add-battery-creation-voltage-regulation

Conversation

@EtienneLt

Copy link
Copy Markdown
Contributor

PR Summary

Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
@EtienneLt EtienneLt self-assigned this Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Battery creation now accepts voltage regulation settings, validates regulating terminals and target voltage, and creates the corresponding VoltageRegulation extension in node-breaker and bus-breaker flows. Tests cover successful configuration and validation failures.

Changes

Battery voltage regulation

Layer / File(s) Summary
Voltage regulation DTO contract
src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java
Adds target voltage, regulator state, and regulating terminal fields, then maps them into BatteryCreation.
Voltage regulation validation and creation
src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java
Validates the regulating terminal and non-negative target voltage, and creates the VoltageRegulation extension for both battery topology flows.
Voltage regulation test coverage
src/test/java/org/gridsuite/modification/modifications/BatteryCreationInBusBreakerTest.java, src/test/java/org/gridsuite/modification/modifications/BatteryCreationInNodeBreakerTest.java
Verifies configured voltage regulation, invalid terminal references, and negative target voltage errors.

Sequence Diagram(s)

sequenceDiagram
  participant BatteryCreationInfos
  participant BatteryCreation
  participant Network
  participant VoltageRegulation
  BatteryCreationInfos->>BatteryCreation: map voltage regulation settings
  BatteryCreation->>Network: resolve regulating terminal and validate targetV
  BatteryCreation->>VoltageRegulation: create extension with terminal and targetV
Loading

Suggested reviewers: etiennehomer

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is a generic template placeholder and provides no meaningful summary of the changes. Replace the template text with a brief summary of what changed, why, and any reviewer notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding voltage regulation support during battery creation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java (1)

85-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using Boolean instead of primitive boolean for consistency.

Using a primitive boolean defaults to false when omitted from the request payload. For consistency with other optional parameters in this class (such as participate and reactiveCapabilityCurve), consider using the Boolean wrapper class to allow representing an omitted configuration as null.

♻️ Proposed refactor
     `@Schema`(description = "Voltage regulation on")
-    private boolean voltageRegulationOn;
+    private Boolean voltageRegulationOn;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java`
around lines 85 - 86, Change the voltageRegulationOn field in
BatteryCreationInfos from primitive boolean to Boolean so omitted request values
remain null, matching the optional participate and reactiveCapabilityCurve
fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java`:
- Around line 97-104: Update the regulated-terminal validation in
BatteryCreation to reject partially specified regulating terminal fields instead
of allowing getTerminalFromIdentifiable to return null; validate that the
regulating terminal arguments are either all provided or all absent, then
perform lookup using the existing network argument rather than
voltageLevel.getNetwork().
- Around line 192-213: Update createBatteryVoltageRegulation to return without
creating a VoltageRegulation extension when voltage regulation parameters are
not configured, while preserving the existing setup when configuration is
present. Build the equipment report identifier without producing "null:null"
when regulatingTerminalType or regulatingTerminalId is missing, using a
null-safe representation instead.

---

Nitpick comments:
In `@src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java`:
- Around line 85-86: Change the voltageRegulationOn field in
BatteryCreationInfos from primitive boolean to Boolean so omitted request values
remain null, matching the optional participate and reactiveCapabilityCurve
fields.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ba89dd8-8f4f-4c29-9d00-6965c47d0019

📥 Commits

Reviewing files that changed from the base of the PR and between 08e5f73 and 5b5084d.

📒 Files selected for processing (4)
  • src/main/java/org/gridsuite/modification/dto/BatteryCreationInfos.java
  • src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java
  • src/test/java/org/gridsuite/modification/modifications/BatteryCreationInBusBreakerTest.java
  • src/test/java/org/gridsuite/modification/modifications/BatteryCreationInNodeBreakerTest.java

Comment on lines +97 to +104
// check regulated terminal
VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fix partial regulating terminal validation and redundant network lookup.

There are two issues here:

  1. ModificationUtils.getInstance().getTerminalFromIdentifiable() will return null if any of the regulating terminal arguments are null. Consequently, if a request provides partial properties (e.g., specifying regulatingTerminalId but omitting regulatingTerminalType), it bypasses validation and silently returns null instead of throwing an error.
  2. Fetching voltageLevel.getNetwork() is redundant since the network is already directly available as the method argument.
🐛 Proposed fix
-        // check regulated terminal
-        VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
-        ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
-                regulatingTerminalId,
-                regulatingTerminalType,
-                regulatingTerminalVlId);
-        checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");
+        // check regulated terminal
+        VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
+        if (regulatingTerminalId != null || regulatingTerminalType != null || regulatingTerminalVlId != null) {
+            if (regulatingTerminalId == null || regulatingTerminalType == null || regulatingTerminalVlId == null) {
+                throw new NetworkModificationException(CREATE_BATTERY_ERROR, errorMessage + "regulatingTerminalId, regulatingTerminalType, and regulatingTerminalVlId must all be provided together");
+            }
+            ModificationUtils.getInstance().getTerminalFromIdentifiable(network,
+                    regulatingTerminalId,
+                    regulatingTerminalType,
+                    regulatingTerminalVlId);
+        }
+        checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// check regulated terminal
VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");
// check regulated terminal
VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, voltageLevelId);
if (regulatingTerminalId != null || regulatingTerminalType != null || regulatingTerminalVlId != null) {
if (regulatingTerminalId == null || regulatingTerminalType == null || regulatingTerminalVlId == null) {
throw new NetworkModificationException(CREATE_BATTERY_ERROR, errorMessage + "regulatingTerminalId, regulatingTerminalType, and regulatingTerminalVlId must all be provided together");
}
ModificationUtils.getInstance().getTerminalFromIdentifiable(network,
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
}
checkIsNotNegativeValue(errorMessage, targetV, CREATE_BATTERY_ERROR, "Target Voltage");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java`
around lines 97 - 104, Update the regulated-terminal validation in
BatteryCreation to reject partially specified regulating terminal fields instead
of allowing getTerminalFromIdentifiable to return null; validate that the
regulating terminal arguments are either all provided or all absent, then
perform lookup using the existing network argument rather than
voltageLevel.getNetwork().

Comment on lines +192 to +213
private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) {
Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
List<ReportNode> voltageReports = new ArrayList<>();
VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class)
.withRegulatingTerminal(regulatingTerminal)
.withVoltageRegulatorOn(voltageRegulationOn);
if (targetV != null) {
voltageRegulationAdder.withTargetV(targetV);
}
voltageRegulationAdder.add();
voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
regulatingTerminalVlId,
"Voltage level"));
voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
regulatingTerminalType + ":" + regulatingTerminalId,
"Equipment"));
ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Conditionally create the VoltageRegulation extension and prevent "null:null" in reports.

Currently, a VoltageRegulation extension is unconditionally added to every created battery, even if no voltage regulation parameters were provided. Additionally, if the regulating terminal parameters are missing, the report will literally output "null:null" for the Equipment.

Add a guard to only create the extension when voltage regulation is configured, and handle null safely in the reports.

🐛 Proposed fix
     private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) {
+        if (!voltageRegulationOn && targetV == null && regulatingTerminalId == null && regulatingTerminalType == null && regulatingTerminalVlId == null) {
+            return;
+        }
         Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
                 regulatingTerminalId,
                 regulatingTerminalType,
                 regulatingTerminalVlId);
         List<ReportNode> voltageReports = new ArrayList<>();
         VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class)
                 .withRegulatingTerminal(regulatingTerminal)
                 .withVoltageRegulatorOn(voltageRegulationOn);
         if (targetV != null) {
             voltageRegulationAdder.withTargetV(targetV);
         }
         voltageRegulationAdder.add();
-        voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
-                regulatingTerminalVlId,
-                "Voltage level"));
-        voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
-                regulatingTerminalType + ":" + regulatingTerminalId,
-                "Equipment"));
+        if (regulatingTerminalVlId != null) {
+            voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
+                    regulatingTerminalVlId,
+                    "Voltage level"));
+        }
+        if (regulatingTerminalId != null && regulatingTerminalType != null) {
+            voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
+                    regulatingTerminalType + ":" + regulatingTerminalId,
+                    "Equipment"));
+        }
         ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated");
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) {
Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
List<ReportNode> voltageReports = new ArrayList<>();
VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class)
.withRegulatingTerminal(regulatingTerminal)
.withVoltageRegulatorOn(voltageRegulationOn);
if (targetV != null) {
voltageRegulationAdder.withTargetV(targetV);
}
voltageRegulationAdder.add();
voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
regulatingTerminalVlId,
"Voltage level"));
voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
regulatingTerminalType + ":" + regulatingTerminalId,
"Equipment"));
ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated");
}
private void createBatteryVoltageRegulation(Battery battery, VoltageLevel voltageLevel, ReportNode subReportNode) {
if (!voltageRegulationOn && targetV == null && regulatingTerminalId == null && regulatingTerminalType == null && regulatingTerminalVlId == null) {
return;
}
Terminal regulatingTerminal = ModificationUtils.getInstance().getTerminalFromIdentifiable(voltageLevel.getNetwork(),
regulatingTerminalId,
regulatingTerminalType,
regulatingTerminalVlId);
List<ReportNode> voltageReports = new ArrayList<>();
VoltageRegulationAdder voltageRegulationAdder = battery.newExtension(VoltageRegulationAdder.class)
.withRegulatingTerminal(regulatingTerminal)
.withVoltageRegulatorOn(voltageRegulationOn);
if (targetV != null) {
voltageRegulationAdder.withTargetV(targetV);
}
voltageRegulationAdder.add();
if (regulatingTerminalVlId != null) {
voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
regulatingTerminalVlId,
"Voltage level"));
}
if (regulatingTerminalId != null && regulatingTerminalType != null) {
voltageReports.add(ModificationUtils.getInstance().buildCreationReport(
regulatingTerminalType + ":" + regulatingTerminalId,
"Equipment"));
}
ModificationUtils.getInstance().reportModifications(subReportNode, voltageReports, "network.modification.VoltageRegulationCreated");
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/modification/modifications/BatteryCreation.java`
around lines 192 - 213, Update createBatteryVoltageRegulation to return without
creating a VoltageRegulation extension when voltage regulation parameters are
not configured, while preserving the existing setup when configuration is
present. Build the equipment report identifier without producing "null:null"
when regulatingTerminalType or regulatingTerminalId is missing, using a
null-safe representation instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant