@@ -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}
0 commit comments