diff --git a/custom_components/ocpp/api.py b/custom_components/ocpp/api.py index 23549b70..13a7f1c1 100644 --- a/custom_components/ocpp/api.py +++ b/custom_components/ocpp/api.py @@ -98,6 +98,7 @@ CLEAR_PROFILE_SERVICE_DATA_SCHEMA = vol.Schema( { vol.Optional("devid"): cv.string, + vol.Optional("conn_id"): vol.Coerce(int), } ) @@ -892,7 +893,8 @@ async def handle_trigger_custom_message(self, call, cp): @check_charger_available async def handle_clear_profile(self, call, cp): """Handle the clear profile service call.""" - await cp.clear_profile() + conn_id = call.data.get("conn_id") + await cp.clear_profile(conn_id=conn_id) @check_charger_available async def handle_update_firmware(self, call, cp): diff --git a/custom_components/ocpp/chargepoint.py b/custom_components/ocpp/chargepoint.py index 80bfa196..137472fa 100644 --- a/custom_components/ocpp/chargepoint.py +++ b/custom_components/ocpp/chargepoint.py @@ -1225,15 +1225,27 @@ def _sum_l123(phase_info: dict) -> float: if is_current: # Current.* shown per phase -> avg of L1/L2/L3, ignore N if not phase_info.keys().isdisjoint(phases_l123): - metric_value = _avg_l123(phase_info) + l2 = phase_info.get(Phase.l2.value, 0.0) + l3 = phase_info.get(Phase.l3.value, 0.0) + + if abs(float(l2)) >= 0.1 and abs(float(l3)) >= 0.1: + metric_value = ( + phase_info.get(Phase.l1.value, 0.0) + l2 + l3 + ) / 3 + else: + metric_value = phase_info.get(Phase.l1.value, 0.0) + elif not phase_info.keys().isdisjoint(line_to_neutral_phases): # Workaround for some chargers that erroneously use line to neutral for current - metric_value = average_of_nonzero( - [ - phase_info.get(phase, 0.0) - for phase in line_to_neutral_phases - ] - ) + l2 = phase_info.get(Phase.l2_n.value, 0.0) + l3 = phase_info.get(Phase.l3_n.value, 0.0) + + if abs(float(l2)) >= 0.1 and abs(float(l3)) >= 0.1: + metric_value = ( + phase_info.get(Phase.l1_n.value, 0.0) + l2 + l3 + ) / 3 + else: + metric_value = phase_info.get(Phase.l1_n.value, 0.0) # Special-case: Power.Factor must be averaged, never summed elif metric == Measurand.power_factor.value: diff --git a/custom_components/ocpp/services.yaml b/custom_components/ocpp/services.yaml index 2e98b3e8..b0d0a0db 100644 --- a/custom_components/ocpp/services.yaml +++ b/custom_components/ocpp/services.yaml @@ -78,6 +78,12 @@ clear_profile: required: false advanced: true example: charger + conn_id: + name: Connector ID + description: OCPP connector to clear profiles from + required: false + advanced: true + example: 1 update_firmware: name: Update charger firmware