@@ -51,37 +51,43 @@ public static boolean isEnergyValue(TransactionDetails.MeterValues v) {
5151 return false ;
5252 }
5353
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 ());
54+ // edge case handling for format
55+ {
56+ ValueFormat format = Strings .isNullOrEmpty (v .getFormat ())
57+ ? ValueFormat .RAW
58+ : ValueFormat .fromValue (v .getFormat ());
6059
61- Measurand measurand = Strings .isNullOrEmpty (v .getMeasurand ())
62- ? Measurand .ENERGY_ACTIVE_IMPORT_REGISTER
63- : Measurand .fromValue (v .getMeasurand ());
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+ }
65+ }
6466
65- UnitOfMeasure unit = Strings .isNullOrEmpty (v .getUnit ())
66- ? UnitOfMeasure .WH
67- : UnitOfMeasure .fromValue (v .getUnit ());
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 ());
6872
69- // if the format is "SignedData", we cannot make any sense of this entry. we don't know how to decode it.
70- // https://github.com/steve-community/steve/issues/816
71- if (ValueFormat .SIGNED_DATA == format ) {
72- return false ;
73+ if (Measurand .ENERGY_ACTIVE_IMPORT_REGISTER != measurand ) {
74+ return false ;
75+ }
7376 }
7477
75- if (!isWHOrKWH (unit )) {
76- return false ;
77- }
78+ // edge case handling for unit
79+ {
80+ UnitOfMeasure unit = Strings .isNullOrEmpty (v .getUnit ())
81+ ? UnitOfMeasure .WH
82+ : UnitOfMeasure .fromValue (v .getUnit ());
7883
79- if (Measurand .ENERGY_ACTIVE_IMPORT_REGISTER != measurand ) {
80- return false ;
84+ if (!isWHOrKWH (unit )) {
85+ return false ;
86+ }
8187 }
8288
8389 // at this point, we have a value with
84- // - RAW or null format
90+ // - RAW format
8591 // - Wh or kWh unit
8692 // - Energy.Active.Import.Register as the measurand
8793 return true ;
0 commit comments