Skip to content

Commit 776961c

Browse files
feat(tVoltageLevel): also update 90-30 SourceRef source
1 parent 4e0d862 commit 776961c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

tVoltageLevel/updateVoltageLevel.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const aa2d1 = findElement(
1515
substation,
1616
'Substation[name="AA2"]>VoltageLevel[name="D1"]',
1717
) as Element;
18+
const aa3j1 = findElement(
19+
substation,
20+
'Substation[name="AA3"]>VoltageLevel[name="J1"]',
21+
) as Element;
1822

1923
const orphanVoltageLevel = new DOMParser()
2024
.parseFromString('<VoltageLevel name="E2" />', "application/xml")
@@ -160,5 +164,26 @@ describe("update VoltageLevel element", () => {
160164
),
161165
).to.have.lengthOf(2);
162166
});
167+
168+
it("updates SourceRef source attribute", () => {
169+
const edits = updateVoltageLevel({
170+
element: aa3j1,
171+
attributes: { name: "F1" },
172+
});
173+
174+
expect(edits.length).to.equal(5);
175+
expect(edits[1].attributes.source).to.equal(
176+
"AA3/F1/Q01/QA2/CBR/CSWI1/OpCls.general",
177+
);
178+
expect(edits[2].attributes.source).to.equal(
179+
"AA3/F1/Q01/QA2/CBR/CSWI1/OpCls.q",
180+
);
181+
expect(edits[3].attributes.source).to.equal(
182+
"AA3/F1/Q01/QA2/CBR/CSWI1/OpOpn.general",
183+
);
184+
expect(edits[4].attributes.source).to.equal(
185+
"AA3/F1/Q01/QA2/CBR/CSWI1/OpOpn.q",
186+
);
187+
});
163188
});
164189
});

tVoltageLevel/updateVoltageLevel.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
11
import { Update } from "../foundation/utils.js";
22

3+
function updateSourceRef(
4+
element: Element,
5+
{
6+
oldSubstation,
7+
oldVoltageLevel,
8+
newVoltageLevel,
9+
}: {
10+
oldSubstation: string;
11+
oldVoltageLevel: string;
12+
newVoltageLevel: string;
13+
},
14+
): Update[] {
15+
const sourceRefs = Array.from(
16+
element.ownerDocument.querySelectorAll(
17+
'Private[type="eIEC61850-6-100"]>LNodeInputs>SourceRef',
18+
),
19+
);
20+
21+
const updates: Update[] = [];
22+
23+
sourceRefs.forEach((srcRef) => {
24+
const source = srcRef.getAttribute("source");
25+
if (!source) return;
26+
27+
const oldPath = `${oldSubstation}/${oldVoltageLevel}`;
28+
29+
if (!source.startsWith(oldPath)) return;
30+
31+
const newPath = `${oldSubstation}/${newVoltageLevel}`;
32+
updates.push({
33+
element: srcRef,
34+
attributes: { source: source.replace(oldPath, newPath) },
35+
});
36+
});
37+
38+
return updates.filter((update) => update) as Update[];
39+
}
40+
341
function updateConnectivityNodes(
442
element: Element,
543
{
@@ -95,5 +133,10 @@ export function updateVoltageLevel(update: Update): Update[] {
95133
substation: substationName,
96134
voltageLevelName: newName,
97135
}),
136+
...updateSourceRef(voltageLevel, {
137+
oldSubstation: substationName,
138+
oldVoltageLevel: oldName,
139+
newVoltageLevel: newName,
140+
}),
98141
);
99142
}

0 commit comments

Comments
 (0)