Skip to content

Commit

Permalink
support new firmware version v112 (#2040)
Browse files Browse the repository at this point in the history
* support new firmware version v112

* fix typo
  • Loading branch information
ndrsnhs authored Dec 17, 2024
1 parent 4922b9e commit ee35605
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
13 changes: 12 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@


class UpdateConfig:
DATASTORE_VERSION = 65
DATASTORE_VERSION = 66
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/config/power_limit_mode$",
Expand Down Expand Up @@ -1842,3 +1842,14 @@ def upgrade_datastore_64(self) -> None:
'<a href="https://wb-solution.de/shop/">https://wb-solution.de/shop/</a>',
MessageType.INFO)
self.__update_topic("openWB/system/datastore_version", 65)

def upgrade_datastore_65(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") == "sungrow" and "firmware" not in payload["configuration"]:
payload["configuration"].update({"firmware": "v111"})
Pub().pub(topic, payload)
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 66)
39 changes: 22 additions & 17 deletions packages/modules/devices/sungrow/sungrow/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from modules.common.store import get_bat_value_store
from modules.devices.sungrow.sungrow.config import SungrowBatSetup, Sungrow
from modules.devices.sungrow.sungrow.version import Version
from modules.devices.sungrow.sungrow.firmware import Firmware


class SungrowBat(AbstractBat):
Expand All @@ -28,24 +29,28 @@ def __init__(self,

def update(self) -> None:
unit = self.device_config.configuration.modbus_id
soc = int(self.__tcp_client.read_input_registers(13022, ModbusDataType.INT_16, unit=unit) / 10)
bat_power = self.__tcp_client.read_input_registers(13021, ModbusDataType.INT_16, unit=unit)

# Beim WiNet S-Dongle fehlt das Register für das Vorzeichen der Speicherleistung
if self.device_config.configuration.version == Version.SH_winet_dongle:
total_power = self.__tcp_client.read_input_registers(13033, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit)
pv_power = self.__tcp_client.read_input_registers(5016, ModbusDataType.UINT_32,
wordorder=Endian.Little, unit=unit)

# Ist die Gesamtleistung des WR größer als die PV-Erzeugung wird der Speicher entladen
if total_power > pv_power:
bat_power = bat_power * -1
soc = int(self.__tcp_client.read_input_registers(13022, ModbusDataType.UINT_16, unit=unit) / 10)

if Firmware(self.device_config.configuration.firmware) == Firmware.v112:
bat_power = self.__tcp_client.read_input_registers(13021, ModbusDataType.INT_16, unit=unit)
else:
resp = self.__tcp_client._delegate.read_input_registers(13000, 1, unit=unit)
binary = bin(resp.registers[0])[2:].zfill(8)
if binary[5] == "1":
bat_power = bat_power * -1
bat_power = self.__tcp_client.read_input_registers(13021, ModbusDataType.UINT_16, unit=unit)

# Beim WiNet S-Dongle fehlt das Register für das Vorzeichen der Speicherleistung
if self.device_config.configuration.version == Version.SH_winet_dongle:
total_power = self.__tcp_client.read_input_registers(13033, ModbusDataType.INT_32,
wordorder=Endian.Little, unit=unit)
pv_power = self.__tcp_client.read_input_registers(5016, ModbusDataType.UINT_32,
wordorder=Endian.Little, unit=unit)

# Ist die Gesamtleistung des WR größer als die PV-Erzeugung wird der Speicher entladen
if total_power > pv_power:
bat_power = bat_power * -1
else:
resp = self.__tcp_client._delegate.read_input_registers(13000, 1, unit=unit)
binary = bin(resp.registers[0])[2:].zfill(8)
if binary[5] == "1":
bat_power = bat_power * -1

imported, exported = self.sim_counter.sim_count(bat_power)
bat_state = BatState(
Expand Down
5 changes: 4 additions & 1 deletion packages/modules/devices/sungrow/sungrow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from modules.common.component_setup import ComponentSetup
from modules.devices.sungrow.sungrow.version import Version
from modules.devices.sungrow.sungrow.firmware import Firmware
from ..vendor import vendor_descriptor


Expand All @@ -10,11 +11,13 @@ def __init__(self,
ip_address: Optional[str] = None,
port: int = 502,
modbus_id: int = 1,
version: Version = Version.SG):
version: Version = Version.SG,
firmware: Firmware = Firmware.v111):
self.ip_address = ip_address
self.port = port
self.modbus_id = modbus_id
self.version = version
self.firmware = firmware


class Sungrow:
Expand Down
6 changes: 6 additions & 0 deletions packages/modules/devices/sungrow/sungrow/firmware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class Firmware(Enum):
v111 = "v111"
v112 = "v112"

0 comments on commit ee35605

Please sign in to comment.