@@ -988,13 +988,13 @@ def average_of_nonzero(values):
988
988
989
989
measurand_data = {}
990
990
for item in data :
991
- # create ordered Dict for each measurand, eg {"voltage":{"unit":"V","L1":"230"...}}
991
+ # create ordered Dict for each measurand, eg {"voltage":{"unit":"V","L1-N ":"230"...}}
992
992
measurand = item .get (om .measurand .value , None )
993
993
phase = item .get (om .phase .value , None )
994
994
value = item .get (om .value .value , None )
995
995
unit = item .get (om .unit .value , None )
996
996
context = item .get (om .context .value , None )
997
- if measurand is not None and phase is not None :
997
+ if measurand is not None and phase is not None and unit is not None :
998
998
if measurand not in measurand_data :
999
999
measurand_data [measurand ] = {}
1000
1000
measurand_data [measurand ][om .unit .value ] = unit
@@ -1011,27 +1011,33 @@ def average_of_nonzero(values):
1011
1011
for metric , phase_info in measurand_data .items ():
1012
1012
metric_value = None
1013
1013
if metric in [Measurand .voltage .value ]:
1014
- if ( phase_info .keys () & line_to_neutral_phases ) is not None :
1014
+ if not phase_info .keys (). isdisjoint ( line_to_neutral_phases ):
1015
1015
# Line to neutral voltages are averaged
1016
1016
metric_value = average_of_nonzero (
1017
1017
[phase_info .get (phase , 0 ) for phase in line_to_neutral_phases ]
1018
1018
)
1019
- elif ( phase_info .keys () & line_to_line_phases ) is not None :
1019
+ elif not phase_info .keys (). isdisjoint ( line_to_line_phases ):
1020
1020
# Line to line voltages are averaged and converted to line to neutral
1021
1021
metric_value = average_of_nonzero (
1022
1022
[phase_info .get (phase , 0 ) for phase in line_to_line_phases ]
1023
1023
) / sqrt (3 )
1024
+ elif not phase_info .keys ().isdisjoint (line_phases ):
1025
+ # Workaround for chargers that don't follow engineering convention
1026
+ # Assumes voltages are line to neutral
1027
+ metric_value = average_of_nonzero (
1028
+ [phase_info .get (phase , 0 ) for phase in line_phases ]
1029
+ )
1024
1030
elif metric in [
1025
1031
Measurand .current_import .value ,
1026
1032
Measurand .current_export .value ,
1027
1033
Measurand .power_active_import .value ,
1028
1034
Measurand .power_active_export .value ,
1029
1035
]:
1030
- if ( phase_info .keys () & line_phases ) is not None :
1036
+ if not phase_info .keys (). isdisjoint ( line_phases ):
1031
1037
metric_value = sum (
1032
1038
phase_info .get (phase , 0 ) for phase in line_phases
1033
1039
)
1034
- elif ( phase_info .keys () & line_to_neutral_phases ) is not None :
1040
+ elif not phase_info .keys (). isdisjoint ( line_to_neutral_phases ):
1035
1041
# Workaround for some chargers that erroneously use line to neutral for current
1036
1042
metric_value = sum (
1037
1043
phase_info .get (phase , 0 ) for phase in line_to_neutral_phases
0 commit comments