From d966823b4d0c0bbe0c0d672d033a7348c53b47d4 Mon Sep 17 00:00:00 2001 From: ChirpyTurnip <85000166+ChirpyTurnip@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:35:36 +1300 Subject: [PATCH 1/4] Refactor metric value calculation for phases --- custom_components/ocpp/chargepoint.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/custom_components/ocpp/chargepoint.py b/custom_components/ocpp/chargepoint.py index 80bfa1960..137472fa7 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: From a698b38a8a2e5b4f4bfcc704c7e97df4d20980be Mon Sep 17 00:00:00 2001 From: ChirpyTurnip <85000166+ChirpyTurnip@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:38:01 +1300 Subject: [PATCH 2/4] Update services.yaml --- custom_components/ocpp/services.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/custom_components/ocpp/services.yaml b/custom_components/ocpp/services.yaml index 2e98b3e80..b0d0a0db4 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 From 90d0b4fb1fd36e27ee1a343b1cfec47b0554948f Mon Sep 17 00:00:00 2001 From: ChirpyTurnip <85000166+ChirpyTurnip@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:39:07 +1300 Subject: [PATCH 3/4] Pass conn_id to clear_profile method --- custom_components/ocpp/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/ocpp/api.py b/custom_components/ocpp/api.py index 23549b706..8b28b7ad6 100644 --- a/custom_components/ocpp/api.py +++ b/custom_components/ocpp/api.py @@ -892,7 +892,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): From c05bdd1b3150b9a39a312e72628edccd43fe77d0 Mon Sep 17 00:00:00 2001 From: ChirpyTurnip <85000166+ChirpyTurnip@users.noreply.github.com> Date: Sat, 3 Oct 2026 15:40:04 +1300 Subject: [PATCH 4/4] Add optional conn_id field to CLEAR_PROFILE_SERVICE_DATA_SCHEMA --- custom_components/ocpp/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/ocpp/api.py b/custom_components/ocpp/api.py index 8b28b7ad6..13a7f1c17 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), } )