Skip to content

Commit

Permalink
Merge pull request snaptec#2445 from LKuemmel/sungrow_dongle
Browse files Browse the repository at this point in the history
option for Sungrow SG with WiNet-dongle
  • Loading branch information
LKuemmel authored Oct 27, 2022
2 parents 2b912e2 + f2a6515 commit bd00aab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
29 changes: 14 additions & 15 deletions packages/modules/sungrow/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from modules.common.simcount import SimCounter
from modules.common.store import get_counter_value_store
from modules.sungrow.config import SungrowCounterSetup
from modules.sungrow.version import Version


class SungrowCounter:
Expand All @@ -28,30 +29,28 @@ def __init__(self,

def update(self):
unit = self.__device_modbus_id
if self.component_config.configuration.version == 1:
power = self.__tcp_client.read_input_registers(5082, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit)
frequency = self.__tcp_client.read_input_registers(5035, ModbusDataType.UINT_16, unit=unit) / 10
voltages = self.__tcp_client.read_input_registers(5018, [ModbusDataType.UINT_16] * 3,
wordorder=Endian.Little, unit=unit)
voltages = [voltage / 10 for voltage in voltages]
if self.component_config.configuration.version == Version.SH:
power = self.__tcp_client.read_input_registers(13009, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit) * -1
# no valid data for powers per phase
# powers = self.__tcp_client.read_input_registers(5084, [ModbusDataType.UINT_16] * 3,
# powers = self.__tcp_client.read_input_registers(5084, [ModbusDataType.INT_16] * 3,
# wordorder=Endian.Little, unit=unit)
# powers = [power / 10 for power in powers]
# log.info("power: " + str(power) + " powers?: " + str(powers))
else:
power = self.__tcp_client.read_input_registers(13009, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit) * -1
frequency = self.__tcp_client.read_input_registers(5035, ModbusDataType.UINT_16, unit=unit) / 10
voltages = self.__tcp_client.read_input_registers(5018, [ModbusDataType.UINT_16] * 3,
wordorder=Endian.Little, unit=unit)
voltages = [voltage / 10 for voltage in voltages]
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
# no valid data for powers per phase
# powers = self.__tcp_client.read_input_registers(5084, [ModbusDataType.INT_16] * 3,
# powers = self.__tcp_client.read_input_registers(5084, [ModbusDataType.UINT_16] * 3,
# wordorder=Endian.Little, unit=unit)
# powers = [power / 10 for power in powers]
# log.info("power: " + str(power) + " powers?: " + str(powers))
frequency = self.__tcp_client.read_input_registers(5035, ModbusDataType.UINT_16, unit=unit) / 10
voltages = self.__tcp_client.read_input_registers(5018, [ModbusDataType.UINT_16] * 3,
wordorder=Endian.Little, unit=unit)
voltages = [voltage / 10 for voltage in voltages]

imported, exported = self.__sim_counter.sim_count(power)

Expand Down
4 changes: 3 additions & 1 deletion packages/modules/sungrow/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from modules.sungrow import inverter
from modules.sungrow.config import (Sungrow, SungrowBatSetup, SungrowCounterConfiguration, SungrowCounterSetup,
SungrowInverterSetup)
from modules.sungrow.version import Version


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -91,7 +93,7 @@ def read_legacy_bat(ip_address: str, port: int, modbus_id: int, num: Optional[in

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(
id=None, configuration=SungrowCounterConfiguration(version=version)))
id=None, configuration=SungrowCounterConfiguration(version=Version(version))))


def read_legacy_inverter(ip_address: str, port: int, modbus_id: int, num: int):
Expand Down
7 changes: 7 additions & 0 deletions packages/modules/sungrow/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from enum import IntEnum


class Version(IntEnum):
SH = 0
SG = 1
SG_winet_dongle = 2
1 change: 1 addition & 0 deletions web/settings/modulconfigevu.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<select name="sungrowsr" id="sungrowsr" class="form-control">
<option <?php if($sungrowsrold == 0) echo "selected" ?> value="0">SH (Hybrid)</option>
<option <?php if($sungrowsrold == 1) echo "selected" ?> value="1">SG (kein Hybrid)</option>
<option <?php if($sungrowsrold == 2) echo "selected" ?> value="2">SG mit WiNet-Dongle (kein Hybrid)</option>
</select>
</div>
</div>
Expand Down

0 comments on commit bd00aab

Please sign in to comment.