From 796d3e6f810a98372dbc0d883bee007ad1b1152a Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:45:15 +0200 Subject: [PATCH 01/16] Update main.sh --- modules/bezug_sungrow/main.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/bezug_sungrow/main.sh b/modules/bezug_sungrow/main.sh index 014157688..4a7a632bb 100755 --- a/modules/bezug_sungrow/main.sh +++ b/modules/bezug_sungrow/main.sh @@ -10,8 +10,12 @@ else MYLOGFILE="$RAMDISKDIR/evu.log" fi -bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "counter" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" "$sungrowsr" >>"$MYLOGFILE" 2>&1 -ret=$? +if [[ "$pvwattmodul" == "wr_sungrow" ]]; then + echo "value read at pv modul" >/dev/null +else + bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "counter" "$pv1_ipa" "$pv1_ida" "$sungrowsr" "0" "0">>"$MYLOGFILE" 2>&1 + ret=$? +fi openwbDebugLog $DMOD 2 "EVU RET: $ret" From d13e3058bb268ed51b08506f106baa4bf051f70a Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:46:55 +0200 Subject: [PATCH 02/16] Update main.sh --- modules/speicher_sungrow/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/speicher_sungrow/main.sh b/modules/speicher_sungrow/main.sh index e73f14ff3..cef18d12a 100755 --- a/modules/speicher_sungrow/main.sh +++ b/modules/speicher_sungrow/main.sh @@ -10,7 +10,7 @@ else MYLOGFILE="$RAMDISKDIR/bat.log" fi -bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "bat" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" >>"$MYLOGFILE" 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "bat" "$pv1_ipa" "$pv1_ida" "0" "0">>"$MYLOGFILE" 2>&1 ret=$? openwbDebugLog $DMOD 2 "BAT RET: $ret" From 77edff503ecea04d82c91b4bd0e43b3804721e87 Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:49:23 +0200 Subject: [PATCH 03/16] Update Moduls --- modules/wr2_sungrow/main.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/wr2_sungrow/main.sh b/modules/wr2_sungrow/main.sh index 4ec64e43c..c12ad3dae 100755 --- a/modules/wr2_sungrow/main.sh +++ b/modules/wr2_sungrow/main.sh @@ -9,7 +9,8 @@ if [ ${DMOD} == "MAIN" ]; then else MYLOGFILE="$RAMDISKDIR/nurpv.log" fi + read_counter=0 -bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$pv2ip" "$pv2port" "$pv2id" "2" >>"$MYLOGFILE" 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$pv2ip" "$pv2id" "2" "$read_counter" "$sungrow2sr">>"$MYLOGFILE" 2>&1 cat "$RAMDISKDIR/pv2watt" From 20e6fff90a816fb6f910153f44255ecd5851742d Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:50:42 +0200 Subject: [PATCH 04/16] Update Modules --- modules/wr_sungrow/main.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/wr_sungrow/main.sh b/modules/wr_sungrow/main.sh index eeb7ea2a1..ca1414be3 100755 --- a/modules/wr_sungrow/main.sh +++ b/modules/wr_sungrow/main.sh @@ -10,6 +10,11 @@ else MYLOGFILE="$RAMDISKDIR/nurpv.log" fi -bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$speicher1_ip" "$sungrowspeicherport" "$sungrowspeicherid" "1" >>"$MYLOGFILE" 2>&1 +if [[ "$wattbezugmodul" == "bezug_sungrow" ]]; then + read_counter=1 +else + read_counter=0 +fi +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.sungrow.device" "inverter" "$pv1_ipa" "$pv1_ida" "1" "$read_counter" "$sungrowsr">>"$MYLOGFILE" 2>&1 cat "$RAMDISKDIR/pvwatt" From 697c49f1a256debad3870742cac3f6465f43b42f Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:57:33 +0200 Subject: [PATCH 05/16] Update counter.py --- packages/modules/devices/sungrow/counter.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/modules/devices/sungrow/counter.py b/packages/modules/devices/sungrow/counter.py index 01b2aae3a..e0802c43d 100644 --- a/packages/modules/devices/sungrow/counter.py +++ b/packages/modules/devices/sungrow/counter.py @@ -27,7 +27,7 @@ def __init__(self, self.store = get_counter_value_store(self.component_config.id) self.component_info = ComponentInfo.from_component_config(self.component_config) - def update(self): + def update(self, pv_power: float): unit = self.__device_modbus_id if self.component_config.configuration.version == Version.SH: power = self.__tcp_client.read_input_registers(13009, ModbusDataType.INT_32, @@ -38,10 +38,13 @@ def update(self): # powers = [power / 10 for power in powers] # log.info("power: " + str(power) + " powers?: " + str(powers)) else: - power = self.__tcp_client.read_input_registers(5082, ModbusDataType.INT_32, - wordorder=Endian.Little, unit=unit) - if self.component_config.configuration.version == Version.SG_winet_dongle: - power = power * -1 + if pv_power != 0: + power = self.__tcp_client.read_input_registers(5082, ModbusDataType.INT_32, + wordorder=Endian.Little, unit=unit) + else: + power = self.__tcp_client.read_input_registers(5090, ModbusDataType.INT_32, + wordorder=Endian.Little, unit=unit) + # no valid data for powers per phase # powers = self.__tcp_client.read_input_registers(5084, [ModbusDataType.UINT_16] * 3, # wordorder=Endian.Little, unit=unit) From 2a0f1030ce0f5c11514b25fe11565c6d3dca3c94 Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:16:11 +0200 Subject: [PATCH 06/16] Update device.py --- packages/modules/devices/sungrow/device.py | 40 ++++++++++++++-------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/packages/modules/devices/sungrow/device.py b/packages/modules/devices/sungrow/device.py index 40f69619b..648c28f74 100644 --- a/packages/modules/devices/sungrow/device.py +++ b/packages/modules/devices/sungrow/device.py @@ -6,7 +6,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 from modules.devices.sungrow import bat from modules.devices.sungrow import counter from modules.devices.sungrow import inverter @@ -33,7 +33,7 @@ def __init__(self, device_config: Union[Dict, Sungrow]) -> None: try: self.device_config = dataclass_from_dict(Sungrow, device_config) self.client = modbus.ModbusTcpClient_(self.device_config.configuration.ip_address, - self.device_config.configuration.port) + 502) except Exception: log.exception("Fehler im Modul "+self.device_config.name) @@ -59,10 +59,13 @@ def update(self) -> None: log.debug("Start device reading " + str(self.components)) if self.components: with self.client: - for component in self.components: - # Auch wenn bei einer Komponente ein Fehler auftritt, sollen alle anderen noch ausgelesen werden. - with SingleComponentUpdateContext(self.components[component].component_info): - self.components[component].update() + with MultiComponentUpdateContext(self.components): + for component in self.components: + if isinstance(component, inverter.SungrowInverter): + pv_power = component.update() + for component in self.components: + if isinstance(component, counter.SungrowCounter): + component.update(pv_power) else: log.warning( self.device_config.name + @@ -77,27 +80,36 @@ def update(self) -> None: } -def read_legacy(ip_address: str, port: int, modbus_id: int, component_config: dict): +def read_legacy(ip_address: str, modbus_id: int, component_config: dict): device_config = Sungrow() device_config.configuration.ip_address = ip_address - device_config.configuration.port = port + device_config.configuration.port = 502 device_config.configuration.modbus_id = modbus_id dev = Device(device_config) dev.add_component(component_config) dev.update() -def read_legacy_bat(ip_address: str, port: int, modbus_id: int, num: Optional[int] = None): - read_legacy(ip_address, port, modbus_id, bat.component_descriptor.configuration_factory(id=None)) +def read_legacy_bat(ip_address: str, modbus_id: int, num: Optional[int] = None, read_counter: Optional[int] = None, version: Optional[int] = None): + read_legacy(ip_address, modbus_id, bat.component_descriptor.configuration_factory(id=None)) -def read_legacy_counter(ip_address: str, port: int, modbus_id: int, version: int): - read_legacy(ip_address, port, modbus_id, counter.component_descriptor.configuration_factory( +def read_legacy_counter(ip_address: str, modbus_id: int, version: int, read_counter: int, unused_version: int): + read_legacy(ip_address, modbus_id, counter.component_descriptor.configuration_factory( id=None, configuration=SungrowCounterConfiguration(version=Version(version)))) -def read_legacy_inverter(ip_address: str, port: int, modbus_id: int, num: int): - read_legacy(ip_address, port, modbus_id, inverter.component_descriptor.configuration_factory(id=num)) +def read_legacy_inverter(ip_address: str, modbus_id: int, num: int, read_counter: int, version: int): + device_config = Sungrow() + device_config.configuration.ip_address = ip_address + device_config.configuration.port = 502 + device_config.configuration.modbus_id = modbus_id + dev = Device(device_config) + dev.add_component(inverter.component_descriptor.configuration_factory(id=num)) + if read_counter == 1: + dev.add_component(counter.component_descriptor.configuration_factory( + id=None, configuration=SungrowCounterConfiguration(version=Version(version)))) + dev.update() def main(argv: List[str]): From 52c49404f38a04a9974afa017539d32fe33f7778 Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:18:38 +0200 Subject: [PATCH 07/16] Update inverter.py --- packages/modules/devices/sungrow/inverter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/modules/devices/sungrow/inverter.py b/packages/modules/devices/sungrow/inverter.py index 0be1b1be1..375567a42 100644 --- a/packages/modules/devices/sungrow/inverter.py +++ b/packages/modules/devices/sungrow/inverter.py @@ -26,7 +26,7 @@ def __init__(self, self.store = get_inverter_value_store(self.component_config.id) self.component_info = ComponentInfo.from_component_config(self.component_config) - def update(self) -> None: + def update(self) -> float: unit = self.__device_modbus_id power = self.__tcp_client.read_input_registers(5016, ModbusDataType.UINT_32, @@ -40,6 +40,7 @@ def update(self) -> None: exported=exported ) self.store.set(inverter_state) + return power component_descriptor = ComponentDescriptor(configuration_factory=SungrowInverterSetup) From dd594808c46fd269f7d34c3cce201e2c6a227a2a Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:22:32 +0200 Subject: [PATCH 08/16] Update device.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Längenanpassung --- packages/modules/devices/sungrow/device.py | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/modules/devices/sungrow/device.py b/packages/modules/devices/sungrow/device.py index 648c28f74..451b20c15 100644 --- a/packages/modules/devices/sungrow/device.py +++ b/packages/modules/devices/sungrow/device.py @@ -10,7 +10,9 @@ from modules.devices.sungrow import bat from modules.devices.sungrow import counter from modules.devices.sungrow import inverter -from modules.devices.sungrow.config import (Sungrow, SungrowBatSetup, SungrowCounterConfiguration, SungrowCounterSetup, +from modules.devices.sungrow.config import (Sungrow, SungrowBatSetup, + SungrowCounterConfiguration, + SungrowCounterSetup, SungrowInverterSetup) from modules.devices.sungrow.version import Version @@ -18,7 +20,9 @@ log = logging.getLogger(__name__) -sungrow_component_classes = Union[bat.SungrowBat, counter.SungrowCounter, inverter.SungrowInverter] +sungrow_component_classes = Union[bat.SungrowBat, + counter.SungrowCounter, + inverter.SungrowInverter] class Device(AbstractDevice): @@ -39,7 +43,9 @@ def __init__(self, device_config: Union[Dict, Sungrow]) -> None: def add_component(self, component_config: Union[Dict, - SungrowBatSetup, SungrowCounterSetup, SungrowInverterSetup]) -> None: + SungrowBatSetup, + SungrowCounterSetup, + SungrowInverterSetup]) -> None: if isinstance(component_config, Dict): component_type = component_config["type"] else: @@ -90,16 +96,26 @@ def read_legacy(ip_address: str, modbus_id: int, component_config: dict): dev.update() -def read_legacy_bat(ip_address: str, modbus_id: int, num: Optional[int] = None, read_counter: Optional[int] = None, version: Optional[int] = None): +def read_legacy_bat(ip_address: str, modbus_id: int, + num: Optional[int] = None, + read_counter: Optional[int] = None, + version: Optional[int] = None): read_legacy(ip_address, modbus_id, bat.component_descriptor.configuration_factory(id=None)) -def read_legacy_counter(ip_address: str, modbus_id: int, version: int, read_counter: int, unused_version: int): +def read_legacy_counter(ip_address: str, modbus_id: int, + version: int, + read_counter: int, + unused_version: int): read_legacy(ip_address, modbus_id, counter.component_descriptor.configuration_factory( id=None, configuration=SungrowCounterConfiguration(version=Version(version)))) -def read_legacy_inverter(ip_address: str, modbus_id: int, num: int, read_counter: int, version: int): +def read_legacy_inverter(ip_address: str, + modbus_id: int, + num: int, + read_counter: int, + version: int): device_config = Sungrow() device_config.configuration.ip_address = ip_address device_config.configuration.port = 502 From 3b504143091016d0f79a8face0056f6b5052f1ee Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:23:42 +0200 Subject: [PATCH 09/16] Update device.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verbesserung Länge zeilen --- packages/modules/devices/sungrow/device.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/modules/devices/sungrow/device.py b/packages/modules/devices/sungrow/device.py index 451b20c15..805e023ce 100644 --- a/packages/modules/devices/sungrow/device.py +++ b/packages/modules/devices/sungrow/device.py @@ -86,7 +86,9 @@ def update(self) -> None: } -def read_legacy(ip_address: str, modbus_id: int, component_config: dict): +def read_legacy(ip_address: str, + modbus_id: int, + component_config: dict): device_config = Sungrow() device_config.configuration.ip_address = ip_address device_config.configuration.port = 502 From 9460d2ffc622993c1f90b0522b0a91407c97567f Mon Sep 17 00:00:00 2001 From: Maxify23 <95931708+Maxify23@users.noreply.github.com> Date: Thu, 1 Jun 2023 20:31:00 +0200 Subject: [PATCH 10/16] Update modulconfigbat.php --- web/settings/modulconfigbat.php | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/web/settings/modulconfigbat.php b/web/settings/modulconfigbat.php index 117b0ac93..724568b7e 100644 --- a/web/settings/modulconfigbat.php +++ b/web/settings/modulconfigbat.php @@ -90,7 +90,7 @@ - + @@ -261,22 +261,11 @@ function visibility_solarwatt_ip2() {