Skip to content

Commit ebe81c3

Browse files
authored
Merge pull request #1732 from steve-community/1731-not-showing-intermediate-meter-values
1731 not showing intermediate meter values
2 parents 0e52da3 + c770326 commit ebe81c3

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

src/main/java/de/rwth/idsg/steve/utils/TransactionStopServiceHelper.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,49 @@ public static boolean isEnergyValue(TransactionDetails.MeterValues v) {
5151
return false;
5252
}
5353

54-
// from 1.6 docs: "To retain backward compatibility, the default values of all of the optional fields on a
55-
// sampledValue element are such that a value without any additional fields will be interpreted, as a register
56-
// reading of active import energy in Wh (Watt-hour) units."
57-
if (Strings.isNullOrEmpty(v.getReadingContext())
58-
&& Strings.isNullOrEmpty(v.getFormat())
59-
&& Strings.isNullOrEmpty(v.getMeasurand())
60-
&& Strings.isNullOrEmpty(v.getLocation())
61-
&& Strings.isNullOrEmpty(v.getUnit())
62-
&& Strings.isNullOrEmpty(v.getPhase())) {
63-
return true;
64-
}
54+
// edge case handling for format
55+
{
56+
ValueFormat format = Strings.isNullOrEmpty(v.getFormat())
57+
? ValueFormat.RAW
58+
: ValueFormat.fromValue(v.getFormat());
6559

66-
// if the format is "SignedData", we cannot make any sense of this entry. we don't know how to decode it.
67-
// https://github.com/steve-community/steve/issues/816
68-
if (ValueFormat.SIGNED_DATA.value().equals(v.getFormat())) {
69-
return false;
60+
// if the format is "SignedData", we cannot make any sense of this entry. we don't know how to decode it.
61+
// https://github.com/steve-community/steve/issues/816
62+
if (ValueFormat.SIGNED_DATA == format) {
63+
return false;
64+
}
7065
}
7166

72-
if (!isWHOrKWH(v.getUnit())) {
73-
return false;
67+
// edge case handling for measurand
68+
{
69+
Measurand measurand = Strings.isNullOrEmpty(v.getMeasurand())
70+
? Measurand.ENERGY_ACTIVE_IMPORT_REGISTER
71+
: Measurand.fromValue(v.getMeasurand());
72+
73+
if (Measurand.ENERGY_ACTIVE_IMPORT_REGISTER != measurand) {
74+
return false;
75+
}
7476
}
7577

76-
if (!Measurand.ENERGY_ACTIVE_IMPORT_REGISTER.value().equals(v.getMeasurand())) {
77-
return false;
78+
// edge case handling for unit
79+
{
80+
UnitOfMeasure unit = Strings.isNullOrEmpty(v.getUnit())
81+
? UnitOfMeasure.WH
82+
: UnitOfMeasure.fromValue(v.getUnit());
83+
84+
if (!isWHOrKWH(unit)) {
85+
return false;
86+
}
7887
}
7988

8089
// at this point, we have a value with
81-
// - RAW or null format
90+
// - RAW format
8291
// - Wh or kWh unit
8392
// - Energy.Active.Import.Register as the measurand
8493
return true;
8594
}
8695

87-
private static boolean isWHOrKWH(String str) {
88-
return UnitOfMeasure.WH.value().equals(str) || UnitOfMeasure.K_WH.value().equals(str);
96+
private static boolean isWHOrKWH(UnitOfMeasure unit) {
97+
return UnitOfMeasure.WH == unit || UnitOfMeasure.K_WH == unit;
8998
}
9099
}

src/test/java/de/rwth/idsg/steve/utils/TransactionStopServiceHelperTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,14 @@ public void testIsEnergy_nonNumericValue() {
152152

153153
Assertions.assertFalse(TransactionStopServiceHelper.isEnergyValue(value));
154154
}
155+
156+
@Test
157+
public void testIsEnergy_valueAndUnit() {
158+
var value = TransactionDetails.MeterValues.builder()
159+
.value("22")
160+
.unit("Wh")
161+
.build();
162+
163+
Assertions.assertTrue(TransactionStopServiceHelper.isEnergyValue(value));
164+
}
155165
}

0 commit comments

Comments
 (0)