Skip to content

Commit

Permalink
make discrete measurement id optional on reading
Browse files Browse the repository at this point in the history
Signed-off-by: gaouizer <[email protected]>

add test

Signed-off-by: gaouizer <[email protected]>

improve test case

Signed-off-by: gaouizer <[email protected]>
  • Loading branch information
gaouizer committed Jul 17, 2024
1 parent 1d467b9 commit 7a3420d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions extensions/iidm/resources/disMeasRef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@
</dm:discreteMeasurement>
</dm:discreteMeasurements>
</iidm:extension>
<iidm:extension id="S1VL1_BBS_TWT_DISCONNECTOR">
<dm:discreteMeasurements>
<dm:discreteMeasurement type="SWITCH_POSITION" valueType="STRING" value="CLOSED" valid="false">
<dm:property name="source" value="test"/>
</dm:discreteMeasurement>
<dm:discreteMeasurement type="OTHER" valueType="STRING" value="CLOSED" valid="false">
<dm:property name="source" value="test"/>
</dm:discreteMeasurement>
</dm:discreteMeasurements>
</iidm:extension>
<iidm:extension id="TWT">
<dm:discreteMeasurements>
<dm:discreteMeasurement id="DIS_MEAS_TAP_POS" type="TAP_POSITION" tapChanger="PHASE_TAP_CHANGER" valueType="INT" value="15" valid="true">
Expand Down
5 changes: 4 additions & 1 deletion extensions/iidm/src/DiscreteMeasurementsXmlSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ Extension& DiscreteMeasurementsXmlSerializer::read(Extendable& extendable, conve

void DiscreteMeasurementsXmlSerializer::readDiscreteMeasurement(DiscreteMeasurements& discreteMeasurements, const xml::XmlStreamReader& reader) {
DiscreteMeasurementAdder adder = discreteMeasurements.newDiscreteMeasurement()
.setId(reader.getAttributeValue(ID))
.setType(Enum::fromString<DiscreteMeasurement::Type>(reader.getAttributeValue(TYPE)))
.setValid(reader.getAttributeValue<bool>(VALID));
const std::string& dmId = reader.getOptionalAttributeValue(ID, "");
if (!dmId.empty()) {
adder.setId(dmId);
}
const std::string& tapChanger = reader.getOptionalAttributeValue(TAP_CHANGER, "");
if (!tapChanger.empty()) {
adder.setTapChanger(Enum::fromString<DiscreteMeasurement::TapChanger>(tapChanger));
Expand Down
17 changes: 17 additions & 0 deletions extensions/iidm/test/DiscreteMeasurementsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,23 @@ BOOST_FIXTURE_TEST_CASE(DiscreteMeasurementsXmlSerializerTest, test::ResourceFix
.putProperty("source", "test2")
.add();

Switch& sw2 = network.getSwitch("S1VL1_BBS_TWT_DISCONNECTOR");
sw2.newExtension<DiscreteMeasurementsAdder>().add();
sw2.getExtension<DiscreteMeasurements>()
.newDiscreteMeasurement()
.setType(DiscreteMeasurement::Type::SWITCH_POSITION)
.setValue("CLOSED")
.setValid(false)
.putProperty("source", "test")
.add();
sw2.getExtension<DiscreteMeasurements>()
.newDiscreteMeasurement()
.setType(DiscreteMeasurement::Type::OTHER)
.setValue("CLOSED")
.setValid(false)
.putProperty("source", "test")
.add();

const std::string& networkStrRef = ResourceFixture::getResource("/disMeasRef.xml");

test::converter::RoundTrip::runXml(network, networkStrRef);
Expand Down

0 comments on commit 7a3420d

Please sign in to comment.