Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@


class UpdateConfig:
DATASTORE_VERSION = 74
DATASTORE_VERSION = 75
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/config/power_limit_mode$",
Expand Down Expand Up @@ -1945,3 +1945,15 @@ def upgrade(topic: str, payload) -> Optional[dict]:
return {topic: config_payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 74)

def upgrade_datastore_74(self) -> None:
def upgrade(topic: str, payload) -> None:
if re.search("openWB/system/device/[0-9]+", topic) is not None:
payload = decode_payload(payload)
# update firmware of Sungrow
if payload.get("type") == "solax":
if "version" not in payload["configuration"]:
payload["configuration"].update({"version": "g3"})
Pub().pub(topic, payload)
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 75)
20 changes: 10 additions & 10 deletions packages/modules/devices/solax/solax/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
from modules.common.modbus import ModbusDataType
from modules.common.simcount import SimCounter
from modules.common.store import get_bat_value_store
from modules.devices.solax.solax.config import SolaxBatSetup
from modules.devices.solax.solax.config import SolaxBatSetup, Solax


class SolaxBat(AbstractBat):
def __init__(self,
device_id: int,
device_config: Solax,
component_config: Union[Dict, SolaxBatSetup],
tcp_client: modbus.ModbusTcpClient_,
modbus_id: int) -> None:
self.__device_id = device_id
self.__modbus_id = modbus_id
tcp_client: modbus.ModbusTcpClient_) -> None:
self.device_config = device_config
self.component_config = dataclass_from_dict(SolaxBatSetup, component_config)
self.__tcp_client = tcp_client
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")
self.sim_counter = SimCounter(self.device_config.id, self.component_config.id, prefix="speicher")
self.store = get_bat_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self) -> None:
with self.__tcp_client:
power = self.__tcp_client.read_input_registers(22, ModbusDataType.INT_16, unit=self.__modbus_id)
soc = self.__tcp_client.read_input_registers(28, ModbusDataType.UINT_16, unit=self.__modbus_id)
unit = self.device_config.configuration.modbus_id

# kein Speicher für Versionen G2 und G4
power = self.__tcp_client.read_input_registers(0x0016, ModbusDataType.INT_16, unit=unit)
soc = self.__tcp_client.read_input_registers(0x001C, ModbusDataType.UINT_16, unit=unit)

imported, exported = self.sim_counter.sim_count(power)
bat_state = BatState(
Expand Down
7 changes: 6 additions & 1 deletion packages/modules/devices/solax/solax/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from typing import Optional

from modules.common.component_setup import ComponentSetup
from modules.devices.solax.solax.version import SolaxVersion
from ..vendor import vendor_descriptor


class SolaxConfiguration:
def __init__(self, modbus_id: int = 1, ip_address: Optional[str] = None, port: int = 502):
def __init__(self, modbus_id: int = 1,
ip_address: Optional[str] = None,
port: int = 502,
version: SolaxVersion = SolaxVersion.G3):
self.modbus_id = modbus_id
self.ip_address = ip_address
self.port = port
self.version = version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Muss die neue Einstellung version nicht auch noch in update_config hinzugefügt werden?



class Solax:
Expand Down
47 changes: 31 additions & 16 deletions packages/modules/devices/solax/solax/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,52 @@
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.modbus import ModbusDataType
from modules.common.store import get_counter_value_store
from modules.devices.solax.solax.config import SolaxCounterSetup
from modules.devices.solax.solax.config import SolaxCounterSetup, Solax
from modules.devices.solax.solax.version import SolaxVersion


class SolaxCounter(AbstractCounter):
def __init__(self,
device_id: int,
device_config: Solax,
component_config: Union[Dict, SolaxCounterSetup],
tcp_client: modbus.ModbusTcpClient_,
modbus_id: int) -> None:

tcp_client: modbus.ModbusTcpClient_) -> None:
self.device_config = device_config
self.component_config = dataclass_from_dict(SolaxCounterSetup, component_config)
self.__modbus_id = modbus_id
self.__tcp_client = tcp_client
self.store = get_counter_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self):
with self.__tcp_client:
power = self.__tcp_client.read_input_registers(70, ModbusDataType.INT_32, wordorder=Endian.Little,
unit=self.__modbus_id) * -1
frequency = self.__tcp_client.read_input_registers(7, ModbusDataType.UINT_16, unit=self.__modbus_id) / 100
unit = self.device_config.configuration.modbus_id

if SolaxVersion(self.device_config.configuration.version) == SolaxVersion.G2:
power = self.__tcp_client.read_input_registers(
0x043B, ModbusDataType.INT_32, wordorder=Endian.Little, unit=unit) * -1
frequency = self.__tcp_client.read_input_registers(0x0407, ModbusDataType.UINT_16, unit=unit) / 100
powers = [-value for value in self.__tcp_client.read_input_registers(
0x0704, [ModbusDataType.INT_32] * 3, wordorder=Endian.Little, unit=unit)]
exported, imported = [value * 10 for value in self.__tcp_client.read_input_registers(
0x043D, [ModbusDataType.UINT_32] * 2, wordorder=Endian.Little, unit=unit)]

elif SolaxVersion(self.device_config.configuration.version) == SolaxVersion.G3:
power = self.__tcp_client.read_input_registers(
0x0046, ModbusDataType.INT_32, wordorder=Endian.Little, unit=unit) * -1
frequency = self.__tcp_client.read_input_registers(0x0007, ModbusDataType.UINT_16, unit=unit) / 100
try:
powers = [-value for value in self.__tcp_client.read_input_registers(
130, [ModbusDataType.INT_32] * 3, wordorder=Endian.Little, unit=self.__modbus_id
)]
0x0082, [ModbusDataType.INT_32] * 3, wordorder=Endian.Little, unit=unit)]
except Exception:
powers = None
exported, imported = [value * 10
for value in self.__tcp_client.read_input_registers(
72, [ModbusDataType.UINT_32] * 2, wordorder=Endian.Little, unit=self.__modbus_id
)]
exported, imported = [value * 10 for value in self.__tcp_client.read_input_registers(
0x0048, [ModbusDataType.UINT_32] * 2, wordorder=Endian.Little, unit=unit)]

else:
power = self.__tcp_client.read_input_registers(
0x0409, ModbusDataType.INT_32, wordorder=Endian.Little, unit=unit) * -1
frequency = self.__tcp_client.read_input_registers(0x0406, ModbusDataType.UINT_16, unit=unit) / 100
powers = None
exported, imported = [value * 100 for value in self.__tcp_client.read_input_registers(
0x042F, [ModbusDataType.UINT_32] * 2, wordorder=Endian.Little, unit=unit)]

counter_state = CounterState(
imported=imported,
Expand Down
6 changes: 3 additions & 3 deletions packages/modules/devices/solax/solax/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

def create_device(device_config: Solax):
def create_bat_component(component_config: SolaxBatSetup):
return SolaxBat(device_config.id, component_config, client, device_config.configuration.modbus_id)
return SolaxBat(device_config, component_config, client)

def create_counter_component(component_config: SolaxCounterSetup):
return SolaxCounter(device_config.id, component_config, client, device_config.configuration.modbus_id)
return SolaxCounter(device_config, component_config, client)

def create_inverter_component(component_config: SolaxInverterSetup):
return SolaxInverter(device_config.id, component_config, client, device_config.configuration.modbus_id)
return SolaxInverter(device_config, component_config, client)

def update_components(components: Iterable[Union[SolaxBat, SolaxCounter, SolaxInverter]]):
with client:
Expand Down
29 changes: 20 additions & 9 deletions packages/modules/devices/solax/solax/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,38 @@
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.modbus import ModbusDataType
from modules.common.store import get_inverter_value_store
from modules.devices.solax.solax.config import SolaxInverterSetup
from modules.devices.solax.solax.config import SolaxInverterSetup, Solax
from modules.devices.solax.solax.version import SolaxVersion


class SolaxInverter(AbstractInverter):
def __init__(self,
device_id: int,
device_config: Solax,
component_config: Union[Dict, SolaxInverterSetup],
tcp_client: modbus.ModbusTcpClient_,
modbus_id: int) -> None:
tcp_client: modbus.ModbusTcpClient_) -> None:
self.device_config = device_config
self.component_config = dataclass_from_dict(SolaxInverterSetup, component_config)
self.__modbus_id = modbus_id
self.__tcp_client = tcp_client
self.store = get_inverter_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))

def update(self) -> None:
with self.__tcp_client:
power_temp = self.__tcp_client.read_input_registers(10, [ModbusDataType.UINT_16] * 2, unit=self.__modbus_id)
unit = self.device_config.configuration.modbus_id

if SolaxVersion(self.device_config.configuration.version) == SolaxVersion.G2:
power = self.__tcp_client.read_input_registers(0x0413, ModbusDataType.UINT_16, unit=unit) * -1
exported = self.__tcp_client.read_input_registers(
0x0423, ModbusDataType.UINT_32, wordorder=Endian.Little, unit=unit) * 100
elif SolaxVersion(self.device_config.configuration.version) == SolaxVersion.G3:
power_temp = self.__tcp_client.read_input_registers(0x000A, [ModbusDataType.UINT_16] * 2, unit=unit)
power = sum(power_temp) * -1
exported = self.__tcp_client.read_input_registers(
0x0052, ModbusDataType.UINT_32, wordorder=Endian.Little, unit=unit) * 100
else:
power_temp = self.__tcp_client.read_input_registers(0x0410, [ModbusDataType.UINT_16] * 2, unit=unit)
power = sum(power_temp) * -1
exported = self.__tcp_client.read_input_registers(82, ModbusDataType.UINT_32, wordorder=Endian.Little,
unit=self.__modbus_id) * 100
exported = self.__tcp_client.read_input_registers(
0x042B, ModbusDataType.UINT_32, wordorder=Endian.Little, unit=unit) * 100

inverter_state = InverterState(
power=power,
Expand Down
7 changes: 7 additions & 0 deletions packages/modules/devices/solax/solax/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from enum import Enum


class SolaxVersion(Enum):
G2 = "g2"
G3 = "g3"
G4 = "g4"