From ee35605986e67dfb2a2d120663686a4438e51ec4 Mon Sep 17 00:00:00 2001 From: ndrsnhs <156670705+ndrsnhs@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:03:46 +0100 Subject: [PATCH] support new firmware version v112 (#2040) * support new firmware version v112 * fix typo --- packages/helpermodules/update_config.py | 13 ++++++- .../modules/devices/sungrow/sungrow/bat.py | 39 +++++++++++-------- .../modules/devices/sungrow/sungrow/config.py | 5 ++- .../devices/sungrow/sungrow/firmware.py | 6 +++ 4 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 packages/modules/devices/sungrow/sungrow/firmware.py diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index 765b864234..f9ac468aee 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -49,7 +49,7 @@ class UpdateConfig: - DATASTORE_VERSION = 65 + DATASTORE_VERSION = 66 valid_topic = [ "^openWB/bat/config/configured$", "^openWB/bat/config/power_limit_mode$", @@ -1842,3 +1842,14 @@ def upgrade_datastore_64(self) -> None: 'https://wb-solution.de/shop/', 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) diff --git a/packages/modules/devices/sungrow/sungrow/bat.py b/packages/modules/devices/sungrow/sungrow/bat.py index c85f1910b3..53d56da2c7 100644 --- a/packages/modules/devices/sungrow/sungrow/bat.py +++ b/packages/modules/devices/sungrow/sungrow/bat.py @@ -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): @@ -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( diff --git a/packages/modules/devices/sungrow/sungrow/config.py b/packages/modules/devices/sungrow/sungrow/config.py index bc112dd867..2fabdcade5 100644 --- a/packages/modules/devices/sungrow/sungrow/config.py +++ b/packages/modules/devices/sungrow/sungrow/config.py @@ -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 @@ -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: diff --git a/packages/modules/devices/sungrow/sungrow/firmware.py b/packages/modules/devices/sungrow/sungrow/firmware.py new file mode 100644 index 0000000000..fc8cce263b --- /dev/null +++ b/packages/modules/devices/sungrow/sungrow/firmware.py @@ -0,0 +1,6 @@ +from enum import Enum + + +class Firmware(Enum): + v111 = "v111" + v112 = "v112"