From 96633454578f91429cf42279e9c6f447ad8bf188 Mon Sep 17 00:00:00 2001
From: HARPER Jon <jon.harper87@gmail.com>
Date: Wed, 30 Aug 2023 10:36:45 +0200
Subject: [PATCH 1/3] Remove deprecated checkActivePowerLimits call (fixup from
 powsybl 4.7 migration)

Signed-off-by: HARPER Jon <jon.harper87@gmail.com>
---
 .../java/com/powsybl/network/store/iidm/impl/BatteryImpl.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java
index 2bcff7bc4..6a18e939e 100644
--- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java
+++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/BatteryImpl.java
@@ -95,7 +95,7 @@ public double getMaxP() {
     @Override
     public Battery setMaxP(double maxP) {
         ValidationUtil.checkMaxP(this, maxP);
-        ValidationUtil.checkActivePowerLimits(this, getMinP(), maxP, getTargetP());
+        ValidationUtil.checkActivePowerLimits(this, getMinP(), maxP);
         double oldValue = getResource().getAttributes().getMaxP();
         if (maxP != oldValue) {
             updateResource(res -> res.getAttributes().setMaxP(maxP));

From e1bf740a562251da1f971fce699eeae89f459600 Mon Sep 17 00:00:00 2001
From: HARPER Jon <jon.harper87@gmail.com>
Date: Wed, 30 Aug 2023 10:37:12 +0200
Subject: [PATCH 2/3] powsybl 6 tieline remove(boolean updateDangling)

Signed-off-by: HARPER Jon <jon.harper87@gmail.com>
---
 .../network/store/iidm/impl/TieLineImpl.java  | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java
index 1ef6761fb..30f7477e6 100644
--- a/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java
+++ b/network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TieLineImpl.java
@@ -64,10 +64,20 @@ public DanglingLine getDanglingLine(String voltageLevelId) {
 
     @Override
     public void remove() {
+        remove(false);
+    }
+
+    @Override
+    public void remove(boolean updateDanglingLines) {
         var resource = getResource();
 
         index.notifyBeforeRemoval(this);
 
+        if (updateDanglingLines) {
+            updateDanglingLine(getDanglingLine1());
+            updateDanglingLine(getDanglingLine2());
+        }
+
         getDanglingLine1().removeTieLine();
         getDanglingLine2().removeTieLine();
         index.removeTieLine(resource.getId());
@@ -399,4 +409,22 @@ static int getOverloadDuration(Branch.Overload o1, Branch.Overload o2) {
         int duration2 = o2 != null ? o2.getTemporaryLimit().getAcceptableDuration() : Integer.MAX_VALUE;
         return Math.min(duration1, duration2);
     }
+
+    private static void updateDanglingLine(DanglingLine danglingLine) {
+        // Only update if we have values
+        if (!Double.isNaN(danglingLine.getBoundary().getP())) {
+            danglingLine.setP0(-danglingLine.getBoundary().getP());
+            if (danglingLine.getGeneration() != null) {
+                // We do not reset regulation if we only have computed a dc load flow
+                danglingLine.getGeneration().setTargetP(0.0);
+            }
+        }
+        if (!Double.isNaN(danglingLine.getBoundary().getQ())) {
+            danglingLine.setQ0(-danglingLine.getBoundary().getQ());
+            if (danglingLine.getGeneration() != null) {
+                // If q values are available a complete ac load flow has been computed, we reset regulation
+                danglingLine.getGeneration().setTargetQ(0.0).setVoltageRegulationOn(false).setTargetV(Double.NaN);
+            }
+        }
+    }
 }

From d4e24e344915cbf22ab69cf93ff2c63e8aacd371 Mon Sep 17 00:00:00 2001
From: HARPER Jon <jon.harper87@gmail.com>
Date: Wed, 30 Aug 2023 15:07:32 +0200
Subject: [PATCH 3/3] MergeNetworkTest remove deleted tests override (xnode,
 merge)

Signed-off-by: HARPER Jon <jon.harper87@gmail.com>
---
 .../network/store/iidm/impl/tck/MergeNetworkTest.java  | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java
index 1935d2f56..7e5737752 100644
--- a/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java
+++ b/network-store-iidm-impl/src/test/java/com/powsybl/network/store/iidm/impl/tck/MergeNetworkTest.java
@@ -38,21 +38,11 @@ public void multipleDanglingLinesInMergedNetwork() {
         // FIXME
     }
 
-    @Override
-    public void testMergeSameId() {
-        // FIXME
-    }
-
     @Override
     public void test() {
         // FIXME
     }
 
-    @Override
-    public void xnodeNonCompatible() {
-        // FIXME
-    }
-
     @Override
     public void mergeThenCloneVariantBug() {
         // FIXME