Skip to content

Commit 65a3fd1

Browse files
committed
relax conditions of "is this energy value" logic (#1731)
1 parent 2414c85 commit 65a3fd1

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,32 @@ 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+
//
55+
// init relevant fields with default values if empty
56+
//
57+
ValueFormat format = Strings.isNullOrEmpty(v.getFormat())
58+
? ValueFormat.RAW
59+
: ValueFormat.fromValue(v.getFormat());
60+
61+
Measurand measurand = Strings.isNullOrEmpty(v.getMeasurand())
62+
? Measurand.ENERGY_ACTIVE_IMPORT_REGISTER
63+
: Measurand.fromValue(v.getMeasurand());
64+
65+
UnitOfMeasure unit = Strings.isNullOrEmpty(v.getUnit())
66+
? UnitOfMeasure.WH
67+
: UnitOfMeasure.fromValue(v.getUnit());
6568

6669
// if the format is "SignedData", we cannot make any sense of this entry. we don't know how to decode it.
6770
// https://github.com/steve-community/steve/issues/816
68-
if (ValueFormat.SIGNED_DATA.value().equals(v.getFormat())) {
71+
if (ValueFormat.SIGNED_DATA == format) {
6972
return false;
7073
}
7174

72-
if (!isWHOrKWH(v.getUnit())) {
75+
if (!isWHOrKWH(unit)) {
7376
return false;
7477
}
7578

76-
if (!Measurand.ENERGY_ACTIVE_IMPORT_REGISTER.value().equals(v.getMeasurand())) {
79+
if (Measurand.ENERGY_ACTIVE_IMPORT_REGISTER != measurand) {
7780
return false;
7881
}
7982

@@ -84,7 +87,7 @@ public static boolean isEnergyValue(TransactionDetails.MeterValues v) {
8487
return true;
8588
}
8689

87-
private static boolean isWHOrKWH(String str) {
88-
return UnitOfMeasure.WH.value().equals(str) || UnitOfMeasure.K_WH.value().equals(str);
90+
private static boolean isWHOrKWH(UnitOfMeasure unit) {
91+
return UnitOfMeasure.WH == unit || UnitOfMeasure.K_WH == unit;
8992
}
9093
}

0 commit comments

Comments
 (0)