Skip to content

Commit

Permalink
fix sma error handling (#1782)
Browse files Browse the repository at this point in the history
* fix sma error handling

* dc power NaN
  • Loading branch information
LKuemmel authored Jul 24, 2024
1 parent a7ee062 commit a4141b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/modules/devices/sma_sunny_boy/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from helpermodules.cli import run_using_positional_cli_args
from modules.common import modbus
from modules.common.abstract_device import AbstractDevice, DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.component_context import MultiComponentUpdateContext, SingleComponentUpdateContext
from modules.common.component_state import InverterState
from modules.common.store import get_inverter_value_store
from modules.devices.sma_sunny_boy import bat, bat_smart_energy, counter, inverter
Expand Down Expand Up @@ -71,11 +71,13 @@ def add_component(self, component_config: Union[Dict,
def update(self) -> None:
log.debug("Start device reading " + str(self.components))
if self.components:
with self.client:
for component in self.components.values():
# Auch wenn bei einer Komponente ein Fehler auftritt, sollen alle anderen noch ausgelesen werden.
with SingleComponentUpdateContext(component.fault_state):
component.update()
with MultiComponentUpdateContext(self.components):
with self.client:
for component in self.components.values():
# Auch wenn bei einer Komponente ein Fehler auftritt, sollen alle anderen noch ausgelesen
# werden.
with SingleComponentUpdateContext(component.fault_state):
component.update()
else:
log.warning(
self.device_config.name +
Expand Down
3 changes: 3 additions & 0 deletions packages/modules/devices/sma_sunny_boy/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class SmaSunnyBoyInverter:

SMA_INT32_NAN = -0x80000000 # SMA uses this value to represent NaN
SMA_UINT_64_NAN = 0x100000000
SMA_NAN = -0xC000

def __init__(self,
Expand Down Expand Up @@ -66,6 +67,8 @@ def read(self) -> InverterState:
raise ValueError("Unbekannte Version "+str(self.component_config.configuration.version))
if power_total == self.SMA_INT32_NAN or power_total == self.SMA_NAN:
power_total = 0
if dc_power == self.SMA_UINT_64_NAN:
dc_power = 0

inverter_state = InverterState(
power=power_total * -1,
Expand Down

0 comments on commit a4141b6

Please sign in to comment.