From 9c8951f66880dfc5359fdd301d3d2af533750edc Mon Sep 17 00:00:00 2001 From: ndrsnhs Date: Mon, 8 Jul 2024 08:59:44 +0200 Subject: [PATCH] add different factors for deye three phase inverters --- packages/helpermodules/update_config.py | 9 +++++++++ packages/modules/devices/deye/bat.py | 4 ++-- packages/modules/devices/deye/config.py | 3 ++- packages/modules/devices/deye/counter.py | 2 +- packages/modules/devices/deye/device.py | 3 ++- packages/modules/devices/deye/inverter.py | 4 ++-- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/helpermodules/update_config.py b/packages/helpermodules/update_config.py index e055b77522..5e522c286b 100644 --- a/packages/helpermodules/update_config.py +++ b/packages/helpermodules/update_config.py @@ -1571,3 +1571,12 @@ def upgrade(topic: str, payload) -> Optional[dict]: return {topic: updated_payload} self._loop_all_received_topics(upgrade) self.__update_topic("openWB/system/datastore_version", 48) + + def upgrade_datastore_48(self) -> None: + def upgrade(topic: str, payload) -> Optional[dict]: + if re.search("openWB/chargepoint/template/[0-9]+$", topic) is not None: + payload = decode_payload(payload) + if payload.get("type") == "deye" and "factor" not in payload["configuration"]: + payload["configuration"].update({"factor": 1}) + self._loop_all_received_topics(upgrade) + self.__update_topic("openWB/system/datastore_version", 49) diff --git a/packages/modules/devices/deye/bat.py b/packages/modules/devices/deye/bat.py index c0e178e272..e48c6bfc10 100644 --- a/packages/modules/devices/deye/bat.py +++ b/packages/modules/devices/deye/bat.py @@ -21,11 +21,11 @@ def __init__(self, device_id: int, component_config: DeyeBatSetup) -> None: self.__device_id = device_id self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher") - def update(self, client: ModbusTcpClient_, device_type: DeviceType) -> None: + def update(self, client: ModbusTcpClient_, device_type: DeviceType, factor: int) -> None: unit = self.component_config.configuration.modbus_id if device_type == DeviceType.THREE_PHASE: - power = client.read_holding_registers(590, ModbusDataType.INT_16, unit=unit) * -10 + power = client.read_holding_registers(590, ModbusDataType.INT_16, unit=unit) * -1 * factor soc = client.read_holding_registers(588, ModbusDataType.INT_16, unit=unit) # 516: Geladen in kWh * 0,1 imported = client.read_holding_registers(516, ModbusDataType.UINT_16, unit=unit) * 100 diff --git a/packages/modules/devices/deye/config.py b/packages/modules/devices/deye/config.py index 95211f3155..955cf8ce58 100644 --- a/packages/modules/devices/deye/config.py +++ b/packages/modules/devices/deye/config.py @@ -8,10 +8,11 @@ class DeyeConfiguration: def __init__(self, ip_address: Optional[str] = None, port: int = 8899, - device_type: str = "three_phase"): + device_type: str = "three_phase", factor: int = 1): self.ip_address = ip_address self.port = port self.device_type = device_type + self.factor = factor class Deye: diff --git a/packages/modules/devices/deye/counter.py b/packages/modules/devices/deye/counter.py index 2224a86b1d..5ff79789b7 100644 --- a/packages/modules/devices/deye/counter.py +++ b/packages/modules/devices/deye/counter.py @@ -18,7 +18,7 @@ def __init__(self, device_id: int, component_config: DeyeCounterSetup) -> None: self.__device_id = device_id self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug") - def update(self, client: ModbusTcpClient_, device_type: DeviceType): + def update(self, client: ModbusTcpClient_, device_type: DeviceType, factor: int): unit = self.component_config.configuration.modbus_id if device_type == DeviceType.THREE_PHASE: diff --git a/packages/modules/devices/deye/device.py b/packages/modules/devices/deye/device.py index 422c200919..9d39e6e070 100644 --- a/packages/modules/devices/deye/device.py +++ b/packages/modules/devices/deye/device.py @@ -31,7 +31,8 @@ def update_components(components: Iterable[Union[DeyeBat, DeyeCounter, DeyeInver with client as c: for component in components: with SingleComponentUpdateContext(component.fault_state): - component.update(c, DeviceType(device_config.configuration.device_type)) + component.update(c, DeviceType(device_config.configuration.device_type), + device_config.configuration.factor) try: client = ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port) diff --git a/packages/modules/devices/deye/inverter.py b/packages/modules/devices/deye/inverter.py index fada08eea5..10bb4c8ebd 100644 --- a/packages/modules/devices/deye/inverter.py +++ b/packages/modules/devices/deye/inverter.py @@ -20,12 +20,12 @@ def __init__(self, device_id: int, component_config: Union[Dict, DeyeInverterSet self.__device_id = device_id self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv") - def update(self, client: ModbusTcpClient_, device_type: DeviceType) -> None: + def update(self, client: ModbusTcpClient_, device_type: DeviceType, factor: int) -> None: unit = self.component_config.configuration.modbus_id if device_type == DeviceType.THREE_PHASE: # Wechselrichter hat 2 mppt Tracker - power = sum(client.read_holding_registers(672, [ModbusDataType.INT_16]*2, unit=unit)) * -10 + power = sum(client.read_holding_registers(672, [ModbusDataType.INT_16]*2, unit=unit)) * -1 * factor # 534: Gesamt Produktion Wechselrichter unsigned integer in kWh * 0,1 exported = client.read_holding_registers(534, ModbusDataType.UINT_16, unit=unit) * 100 elif device_type == DeviceType.SINGLE_PHASE_STRING or device_type == DeviceType.SINGLE_PHASE_HYBRID: