Skip to content

Commit 2d4dee3

Browse files
committed
review
1 parent a998506 commit 2d4dee3

6 files changed

Lines changed: 35 additions & 34 deletions

File tree

modules/bezug_kostalplenticoreem300haus/main.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ else
1010
MYLOGFILE="${RAMDISKDIR}/evu.log"
1111
fi
1212

13-
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.kostal_plenticore.device" "counter" "${kostalplenticorehaus}" >> "$MYLOGFILE" 2>&1
13+
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.kostal_plenticore.device" "counter" "${kostalplenticoreip}" "" "0" "" "${kostalplenticorehaus}" >> "$MYLOGFILE" 2>&1
1414

1515
cat "${RAMDISKDIR}/wattbezug"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

3-
# wr_plenticore will fetch data for both inverter and counter and there is nothing left for us to do.
3+
# wr_plenticore will fetch data for both PV and battery and there is nothing left for us to do.
44
#
55
# The usage of speicher_kostalplenticore without wr_plenticore is not intended and thus not handled.

packages/modules/kostal_plenticore/bat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def __init__(self,
1818
self.sim_counter = SimCounter(device_id, self.component_config.id, prefix="speicher")
1919
self.component_info = ComponentInfo.from_component_config(self.component_config)
2020

21-
def update(self, reader: Callable[[int, ModbusDataType], Any]) -> BatState:
22-
power = reader(582, ModbusDataType.INT_16)
21+
def read_state(self, reader: Callable[[int, ModbusDataType], Any]) -> BatState:
22+
power = reader(582, ModbusDataType.INT_16) * -1
2323
soc = reader(514, ModbusDataType.INT_16)
2424
imported, exported = self.sim_counter.sim_count(power)
2525

@@ -30,7 +30,7 @@ def update(self, reader: Callable[[int, ModbusDataType], Any]) -> BatState:
3030
exported=exported,
3131
)
3232

33-
def set(self, state):
33+
def update(self, state):
3434
self.store.set(state)
3535

3636

packages/modules/kostal_plenticore/counter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def get_values(self, reader: Callable[[int, ModbusDataType], Any]) -> CounterSta
3838
frequency=frequency
3939
)
4040

41-
def get_imported_exported(self, state):
41+
def update_imported_exported(self, state):
4242
state.imported, state.exported = self.sim_counter.sim_count(state.power)
4343
return state
4444

4545
def update(self, reader: Callable[[int, ModbusDataType], Any]):
46-
self.store.set(self.get_imported_exported(self.get_values(reader)))
46+
self.store.set(self.update_imported_exported(self.get_values(reader)))
4747

4848

4949
component_descriptor = ComponentDescriptor(configuration_factory=KostalPlenticoreCounterSetup)

packages/modules/kostal_plenticore/device.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# !/usr/bin/env python3
22
from enum import IntEnum
3+
from ipparser import ipparser
34
from itertools import chain
45
from typing import Any, Callable, Iterable, List, Union
56
from pymodbus.constants import Endian
6-
from ipparser import ipparser
7-
import logging
87
import functools
9-
from modules.common.component_state import BatState, InverterState
8+
import logging
109

10+
from helpermodules.cli import run_using_positional_cli_args
11+
from modules.common import modbus
12+
from modules.common.abstract_device import DeviceDescriptor
13+
from modules.common.component_state import BatState, InverterState
14+
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
15+
from modules.common.store import get_counter_value_store
16+
from modules.kostal_plenticore.bat import KostalPlenticoreBat
1117
from modules.kostal_plenticore.inverter import KostalPlenticoreInverter
12-
from modules.kostal_plenticore.counter import KostalPlenticoreCounter
1318
from modules.kostal_plenticore.config import (KostalPlenticore, KostalPlenticoreBatSetup, KostalPlenticoreCounterSetup,
1419
KostalPlenticoreInverterSetup)
15-
from modules.kostal_plenticore.bat import KostalPlenticoreBat
16-
from modules.common.store import get_counter_value_store
17-
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
18-
from modules.common.abstract_device import DeviceDescriptor
19-
from modules.common import modbus
20-
from helpermodules.cli import run_using_positional_cli_args
20+
from modules.kostal_plenticore.counter import KostalPlenticoreCounter
2121

2222

2323
log = logging.getLogger(__name__)
@@ -33,21 +33,21 @@ def update(
3333
reader: Callable[[int, modbus.ModbusDataType], Any],
3434
set_inverter_state: bool = True):
3535
battery = next((component for component in components if isinstance(component, KostalPlenticoreBat)), None)
36-
bat_state_net = battery.update(reader) if battery else None
36+
bat_state_net = battery.read_state(reader) if battery else None
3737
for component in components:
3838
if isinstance(component, KostalPlenticoreInverter):
39-
inverter_state = component.update(reader)
39+
inverter_state = component.read_state(reader)
4040
if bat_state_net:
4141
dc_in = component.dc_in_string_1_2(reader)
4242
home_consumption = component.home_consumption(reader)
4343
if dc_in >= 0:
4444
# Wird PV-DC-Leistung erzeugt, müssen die Wandlungsverluste betrachtet werden.
4545
# Kostal liefert nur DC-seitige Werte.
46-
if bat_state_net.power > 0:
46+
if bat_state_net.power < 0:
4747
# Wird die Batterie entladen, werden die Wandlungsverluste anteilig an der DC-Leistung auf PV
4848
# und Batterie verteilt. Dazu muss der Divisor Total_DC_power != 0 sein.
49-
power_gross = bat_state_net.power + dc_in
50-
pv_state = InverterState(power=bat_state_net.power / power_gross * inverter_state.power,
49+
power_gross = dc_in - bat_state_net.power
50+
pv_state = InverterState(power=dc_in / power_gross * inverter_state.power,
5151
exported=inverter_state.exported)
5252
# Speicherladung muss durch Wandlungsverluste und internen Verbrauch korrigiert werden, sonst
5353
# wird ein falscher Hausverbrauch berechnet. Die Verluste fallen hier unter den Tisch.
@@ -59,24 +59,25 @@ def update(
5959
# Ladeleistung der Batterie. Die PV-Leistung ist die Summe aus verlustbehafteter
6060
# AC-Leistungsabgabe des WR und der DC-Ladeleistung. Die Wandlungsverluste werden also nur
6161
# in der PV-Leistung ersichtlich.
62-
pv_state = InverterState(power=inverter_state.power + bat_state_net.power,
62+
pv_state = InverterState(power=inverter_state.power - bat_state_net.power,
6363
exported=inverter_state.exported)
6464
bat_state_gross = bat_state_net
6565
# https://github.com/snaptec/openWB/pull/2440#discussion_r996275286
6666
# power_gross = bat_state.power + dc_in
6767
# bat_state_gross = BatteryState(power=bat_state_net.power / power_gross * inverter_state.power)
6868
# pv_state = InverterState(power=inverter_state.power - bat_state_gross.power)
6969
else:
70+
inverter_state.power = 0
7071
pv_state = inverter_state
7172
bat_state_gross = bat_state_net
7273
else:
7374
pv_state = inverter_state
7475
if set_inverter_state:
75-
component.set(pv_state)
76+
component.update(pv_state)
7677
elif isinstance(component, KostalPlenticoreCounter):
7778
component.update(reader)
7879
if bat_state_net:
79-
battery.set(bat_state_gross)
80+
battery.update(bat_state_gross)
8081
if set_inverter_state is False:
8182
return pv_state
8283

@@ -118,14 +119,14 @@ def read_legacy_inverter(ip1: str, ip2: str, battery: int, ip3: str) -> Inverter
118119

119120
def get_hybrid_inverter_state(ip: str) -> InverterState:
120121
battery_component = KostalPlenticoreBat(1, KostalPlenticoreBatSetup())
121-
with modbus.ModbusTcpClient_(ip) as client:
122+
with modbus.ModbusTcpClient_(ip, 1502) as client:
122123
return update(
123124
[inverter_component, battery_component], _create_reader(client), set_inverter_state=False
124125
)
125126

126127
def get_standard_inverter_state(ip: str) -> InverterState:
127-
with modbus.ModbusTcpClient_(ip) as client:
128-
return inverter_component.update(_create_reader(client))
128+
with modbus.ModbusTcpClient_(ip, 1502) as client:
129+
return inverter_component.read_state(_create_reader(client))
129130

130131
def inverter_state_sum(a: InverterState, b: InverterState) -> InverterState:
131132
return InverterState(exported=a.exported + b.exported, power=a.power + b.power)
@@ -135,7 +136,7 @@ def inverter_state_sum(a: InverterState, b: InverterState) -> InverterState:
135136
map(get_standard_inverter_state, filter("none".__ne__, chain([ip2], ipparser(ip3)))),
136137
get_hybrid_inverter_state(ip1) if battery else get_standard_inverter_state(ip1)
137138
)
138-
inverter_component.set(inverter_state)
139+
inverter_component.update(inverter_state)
139140
return inverter_state
140141

141142

@@ -150,10 +151,10 @@ def read_legacy_counter(ip1: str, ip2: str, battery: int, ip3: str, position: in
150151
else:
151152
with client:
152153
counter_state = counter_component.get_values(reader)
153-
bat_power = KostalPlenticoreBat(None, KostalPlenticoreBatSetup()).update(reader).power
154+
bat_power = KostalPlenticoreBat(None, KostalPlenticoreBatSetup()).read_state(reader).power
154155
inverter_power = read_legacy_inverter(ip1, ip2, battery, ip3).power
155156
counter_state.power += inverter_power + bat_power
156-
counter_state = counter_component.get_imported_exported(counter_state)
157+
counter_state = counter_component.update_imported_exported(counter_state)
157158
get_counter_value_store(None).set(counter_state)
158159

159160

packages/modules/kostal_plenticore/inverter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def __init__(self,
1515
self.store = get_inverter_value_store(self.component_config.id)
1616
self.component_info = ComponentInfo.from_component_config(self.component_config)
1717

18-
def update(self, reader: Callable[[int, ModbusDataType], Any]) -> InverterState:
18+
def read_state(self, reader: Callable[[int, ModbusDataType], Any]) -> InverterState:
1919
# PV-Anlage kann nichts verbrauchen, also ggf. Register-/Rundungsfehler korrigieren.
20-
power = min(0, reader(575, ModbusDataType.INT_16)) * -1
20+
power = reader(575, ModbusDataType.INT_16) * -1
2121
exported = reader(320, ModbusDataType.FLOAT_32)
2222

2323
return InverterState(
@@ -31,7 +31,7 @@ def dc_in_string_1_2(self, reader: Callable[[int, ModbusDataType], Any]):
3131
def home_consumption(self, reader: Callable[[int, ModbusDataType], Any]):
3232
return reader(106, ModbusDataType.FLOAT_32)
3333

34-
def set(self, state):
34+
def update(self, state):
3535
self.store.set(state)
3636

3737

0 commit comments

Comments
 (0)