From 6158cf48427fe1cf54c2d037aff6f059c214dc65 Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Thu, 28 Aug 2025 10:35:30 +0200 Subject: [PATCH 1/4] catch Error when currents are not available --- packages/modules/devices/sonnen/sonnenbatterie/api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/modules/devices/sonnen/sonnenbatterie/api.py b/packages/modules/devices/sonnen/sonnenbatterie/api.py index 55a3f232b7..30da4790bd 100644 --- a/packages/modules/devices/sonnen/sonnenbatterie/api.py +++ b/packages/modules/devices/sonnen/sonnenbatterie/api.py @@ -354,9 +354,12 @@ def update_battery(self, sim_counter: SimCounter) -> BatState: # this is not correct, but we have no other way to get the currents # the current is calculated as apparent power / voltage battery_ac_voltage = battery_state["Uac"] - currents = [float(battery_state[f"Sac{phase}"]) / battery_ac_voltage - if battery_state[f"Sac{phase}"] else None - for phase in range(1, 4)] + try: + currents = [float(battery_state[f"Sac{phase}"]) / battery_ac_voltage + if battery_state[f"Sac{phase}"] else None + for phase in range(1, 4)] + except Exception: + currents = [None, None, None] imported, exported = sim_counter.sim_count(battery_power) return BatState(power=battery_power, currents=currents if None not in currents else None, From 326ecd6716c1a92630a060814f5c1779529b3249 Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Thu, 28 Aug 2025 12:58:26 +0200 Subject: [PATCH 2/4] check battery_state for key --- packages/modules/devices/sonnen/sonnenbatterie/api.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/modules/devices/sonnen/sonnenbatterie/api.py b/packages/modules/devices/sonnen/sonnenbatterie/api.py index 30da4790bd..94e47123e3 100644 --- a/packages/modules/devices/sonnen/sonnenbatterie/api.py +++ b/packages/modules/devices/sonnen/sonnenbatterie/api.py @@ -354,12 +354,9 @@ def update_battery(self, sim_counter: SimCounter) -> BatState: # this is not correct, but we have no other way to get the currents # the current is calculated as apparent power / voltage battery_ac_voltage = battery_state["Uac"] - try: - currents = [float(battery_state[f"Sac{phase}"]) / battery_ac_voltage - if battery_state[f"Sac{phase}"] else None - for phase in range(1, 4)] - except Exception: - currents = [None, None, None] + currents = [float(battery_state[f"Sac{phase}"]) / battery_ac_voltage + if f"Sac{phase}" in battery_state and battery_state[f"Sac{phase}"] else None + for phase in range(1, 4)] imported, exported = sim_counter.sim_count(battery_power) return BatState(power=battery_power, currents=currents if None not in currents else None, From aa77afee91c32208b2478f8ccba4b07aa46fc5ad Mon Sep 17 00:00:00 2001 From: LKuemmel <76958050+LKuemmel@users.noreply.github.com> Date: Fri, 29 Aug 2025 11:41:29 +0200 Subject: [PATCH 3/4] Update packages/modules/devices/sonnen/sonnenbatterie/api.py --- packages/modules/devices/sonnen/sonnenbatterie/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/devices/sonnen/sonnenbatterie/api.py b/packages/modules/devices/sonnen/sonnenbatterie/api.py index 94e47123e3..c8d234d99e 100644 --- a/packages/modules/devices/sonnen/sonnenbatterie/api.py +++ b/packages/modules/devices/sonnen/sonnenbatterie/api.py @@ -355,7 +355,7 @@ def update_battery(self, sim_counter: SimCounter) -> BatState: # the current is calculated as apparent power / voltage battery_ac_voltage = battery_state["Uac"] currents = [float(battery_state[f"Sac{phase}"]) / battery_ac_voltage - if f"Sac{phase}" in battery_state and battery_state[f"Sac{phase}"] else None + if battery_state.get(f"Sac{phase}) else None for phase in range(1, 4)] imported, exported = sim_counter.sim_count(battery_power) return BatState(power=battery_power, From ceab95721c59751474292afcedcbd8c269640e11 Mon Sep 17 00:00:00 2001 From: LKuemmel <76958050+LKuemmel@users.noreply.github.com> Date: Fri, 29 Aug 2025 11:43:43 +0200 Subject: [PATCH 4/4] typo --- packages/modules/devices/sonnen/sonnenbatterie/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/modules/devices/sonnen/sonnenbatterie/api.py b/packages/modules/devices/sonnen/sonnenbatterie/api.py index c8d234d99e..462e486cb1 100644 --- a/packages/modules/devices/sonnen/sonnenbatterie/api.py +++ b/packages/modules/devices/sonnen/sonnenbatterie/api.py @@ -355,7 +355,7 @@ def update_battery(self, sim_counter: SimCounter) -> BatState: # the current is calculated as apparent power / voltage battery_ac_voltage = battery_state["Uac"] currents = [float(battery_state[f"Sac{phase}"]) / battery_ac_voltage - if battery_state.get(f"Sac{phase}) else None + if battery_state.get(f"Sac{phase}") else None for phase in range(1, 4)] imported, exported = sim_counter.sim_count(battery_power) return BatState(power=battery_power,