Skip to content

Commit

Permalink
Add an UNKNOWN value to the WindingType enum
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Courtier <[email protected]>
  • Loading branch information
rcourtier committed Dec 9, 2024
1 parent 09d0a82 commit f680d6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
public enum WindingType {

PRIMARY, SECONDARY, TERTIARY;
PRIMARY, SECONDARY, TERTIARY, UNKNOWN;

/**
* Retrieve the WindingType for the given transformer winding/end.
Expand All @@ -25,23 +25,21 @@ public enum WindingType {
public static WindingType windingType(PropertyBag end) {
if (end.containsKey("windingType")) {
// For CIM14 (CIM ENTSOE Profile1) primary is determined by TransformerWinding.windingType
String wtype = end.getLocal("windingType");
if (wtype.endsWith("WindingType.primary")) {
return WindingType.PRIMARY;
} else if (wtype.endsWith("WindingType.secondary")) {
return WindingType.SECONDARY;
} else if (wtype.endsWith("WindingType.tertiary")) {
return WindingType.TERTIARY;
}
return switch (end.getLocal("windingType")) {
case "WindingType.primary" -> WindingType.PRIMARY;
case "WindingType.secondary" -> WindingType.SECONDARY;
case "WindingType.tertiary" -> WindingType.TERTIARY;
default -> WindingType.UNKNOWN;
};
} else if (end.containsKey("endNumber")) {
// For CIM16 (CGMES 2.4.15) primary is defined by TransformerEnd.endNumber
try {
return WindingType.values()[end.asInt("endNumber") - 1];
} catch (Exception e) {
return WindingType.PRIMARY;
return WindingType.UNKNOWN;
}
}
return WindingType.PRIMARY;
return WindingType.UNKNOWN;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void cim14WindingTypeTest() {

end4 = new PropertyBag(Collections.singletonList(WINDING_TYPE), true);
end4.put(WINDING_TYPE, "WindingType.quaternary");
assertEquals(WindingType.PRIMARY, WindingType.windingType(end4));
assertEquals(1, WindingType.endNumber(end4));
assertEquals(WindingType.UNKNOWN, WindingType.windingType(end4));
assertEquals(4, WindingType.endNumber(end4));
}

@Test
Expand All @@ -69,7 +69,7 @@ void cim16WindingTypeTest() {

end4 = new PropertyBag(Collections.singletonList(END_NUMBER), true);
end4.put(END_NUMBER, "4");
assertEquals(WindingType.PRIMARY, WindingType.windingType(end4));
assertEquals(1, WindingType.endNumber(end4));
assertEquals(WindingType.UNKNOWN, WindingType.windingType(end4));
assertEquals(4, WindingType.endNumber(end4));
}
}

0 comments on commit f680d6a

Please sign in to comment.