Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E3DC nun komplett auf openwb V2.0 Struktur umgestellt #2449

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions modules/bezug_e3dc/e3dc.py

This file was deleted.

2 changes: 1 addition & 1 deletion modules/bezug_e3dc/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
MYLOGFILE="${RAMDISKDIR}/evu.log"
fi

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "bezug_e3dc.e3dc" "${e3dcip}" >>"${MYLOGFILE}" 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.e3dc.device" "counter" "$e3dcip" "$e3dc2ip" "$e3dcextprod" "$pvwattmodul" "1">>"${MYLOGFILE}" 2>&1
ret=$?

openwbDebugLog ${DMOD} 2 "EVU RET: ${ret}"
Expand Down
78 changes: 0 additions & 78 deletions modules/speicher_e3dc/e3dc.py

This file was deleted.

2 changes: 1 addition & 1 deletion modules/speicher_e3dc/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
MYLOGFILE="${RAMDISKDIR}/bat.log"
fi

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "speicher_e3dc.e3dc" "$e3dcip" "$e3dc2ip" "$e3dcextprod" "$pvwattmodul" >>"${MYLOGFILE}" 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.e3dc.device" "batv19" "$e3dcip" "$e3dc2ip" "$e3dcextprod" "$pvwattmodul" "1">>"${MYLOGFILE}" 2>&1
ret=$?

openwbDebugLog "${DMOD}" 2 "BAT RET: ${ret}"
54 changes: 54 additions & 0 deletions packages/modules/e3dc/bat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
import logging

from modules.common import modbus
from modules.common.component_state import BatState
from modules.common.component_type import ComponentDescriptor
from modules.common.modbus import ModbusDataType, Endian
from modules.common.fault_state import ComponentInfo
from modules.common.store import get_bat_value_store
from modules.common.simcount._simcounter import SimCounter
from modules.e3dc.config import E3dcBatSetup


log = logging.getLogger(__name__)


def read_bat(client: modbus.ModbusTcpClient_) -> [int, int]:
# 40082 SoC
soc = client.read_holding_registers(40082, ModbusDataType.INT_16, unit=1)
# 40069 Speicherleistung
power = client.read_holding_registers(40069, ModbusDataType.INT_32, wordorder=Endian.Little, unit=1)
return soc, power
okaegi marked this conversation as resolved.
Show resolved Hide resolved


class E3dcBat:
def __init__(self,
device_id: int,
address: str,
component_config: E3dcBatSetup) -> None:
self.__device_id = device_id
self.component_config = component_config
self.__device_id = device_id
Comment on lines +30 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.__device_id = device_id
self.component_config = component_config
self.__device_id = device_id
self.component_config = component_config
self.__device_id = device_id

# bat
self.__sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")
self.__store = get_bat_value_store(self.component_config.id)
self.component_info = ComponentInfo.from_component_config(self.component_config)
self.__address = address

def update(self, client: modbus.ModbusTcpClient_) -> None:

soc, power = read_bat(client)
log.debug("Ip: %s, soc %d power %d", self.__address,
soc, power)
imported, exported = self.__sim_counter.sim_count(power)
bat_state = BatState(
power=power,
soc=soc,
imported=imported,
exported=exported
)
self.__store.set(bat_state)


component_descriptor = ComponentDescriptor(configuration_factory=E3dcBatSetup)
76 changes: 76 additions & 0 deletions packages/modules/e3dc/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from modules.common.component_setup import ComponentSetup
from helpermodules.auto_str import auto_str


@auto_str
class E3dcConfiguration:
def __init__(self, address: str = None,
read_ext: int = 0,
pvmodul: str = None
okaegi marked this conversation as resolved.
Show resolved Hide resolved
):
self.address = address
self.read_ext = read_ext
self.pvmodul = pvmodul


@auto_str
class E3dc:
def __init__(self,
name: str = "e3dc",
type: str = "e3dc",
id: int = 0,
configuration: E3dcConfiguration = None) -> None:
self.name = name
self.type = type
self.id = id
self.configuration = configuration or E3dcConfiguration()


@auto_str
class E3dcBatConfiguration:
def __init__(self):
pass


@auto_str
class E3dcBatSetup(ComponentSetup[E3dcBatConfiguration]):
def __init__(self,
name: str = "e3dc Speicher",
type: str = "bat",
id: int = 0,
configuration: E3dcBatConfiguration = None) -> None:
super().__init__(name, type, id, configuration
or E3dcBatConfiguration())


@auto_str
class E3dcCounterConfiguration:
def __init__(self):
pass


@auto_str
class E3dcCounterSetup(ComponentSetup[E3dcCounterConfiguration]):
def __init__(self,
name: str = "e3dc Zähler",
type: str = "counter",
id: int = 0,
configuration: E3dcCounterConfiguration = None) -> None:
super().__init__(name, type, id, configuration or
E3dcCounterConfiguration())


@auto_str
class E3dcInverterConfiguration:
def __init__(self):
pass


@auto_str
class E3dcInverterSetup(ComponentSetup[E3dcInverterConfiguration]):
def __init__(self,
name: str = "E3dc Wechselrichter",
type: str = "inverter",
id: int = 0,
configuration: E3dcInverterConfiguration = None) -> None:
super().__init__(name, type, id, configuration or E3dcInverterConfiguration())
58 changes: 58 additions & 0 deletions packages/modules/e3dc/counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
import logging
from typing import Dict, Union

from dataclass_utils import dataclass_from_dict
from modules.common import modbus
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo
from modules.common.simcount._simcounter import SimCounter
from modules.common.modbus import ModbusDataType, Endian
from modules.common.store import get_counter_value_store
from modules.e3dc.config import E3dcCounterSetup

log = logging.getLogger(__name__)


def read_counter(client: modbus.ModbusTcpClient_) -> [int, [int]]:
log.debug("Beginning EVU update")
power = client.read_holding_registers(40073, ModbusDataType.INT_32, wordorder=Endian.Little, unit=1)
# 40130,40131, 40132 je Phasenleistung in Watt
# max 6 Leistungsmesser verbaut ab 40105, typ 1 ist evu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"max 6 Leistungsmesser verbaut": Das ist immernoch der alte Kommentar. Der Code liest bis zu 7 Leistungsmesser aus. Entweder der Kommentar lügt oder der Code weiter unten liest unnötigerweise 28 Register aus und die 28 sollte durch eine 24 getauscht werden.

# bei den meisten e3dc auf 40128
# for register in range (40104,40132,4):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# for register in range (40104,40132,4):

Diese Zeile vom Kommentar scheint mir keine Hilfe zu sein.

meters = client.read_holding_registers(40104, [ModbusDataType.INT_16] * 28, unit=1)
log.debug("power: %d, meters: %s", power, meters)
powers = next(meters[i+1:i+4] for i in reversed(range(0, len(meters), 4)) if meters[i] == 1)
log.debug("powers %s", powers)
return power, powers


class E3dcCounter:
def __init__(self,
device_id: int,
address: str,
component_config: Union[Dict, E3dcCounterSetup]) -> None:
self.__device_id = device_id
self.component_config = dataclass_from_dict(E3dcCounterSetup, component_config)
self.__sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug")
self.__store = get_counter_value_store(self.component_config.id)
self.component_info = ComponentInfo.from_component_config(self.component_config)
self.__address = address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du hattest dich nicht zu meinem Einwand geäußert, dass _address nur zwecks Logausgabe mitgeschleppt wird. Eine Mögliche Alternative wäre in der Funktion update_components in der device.py eine Logausgabe "reading %s" mit der Adresse rauszuhauen. Dann ist die IP auch geloggt, aber du musst die nicht überall durchschleppen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du hattest dich nicht zu meinem Einwand geäußert, dass _address nur zwecks Logausgabe mitgeschleppt wird. Eine Mögliche Alternative wäre in der Funktion update_components in der device.py eine Logausgabe "reading %s" mit der Adresse rauszuhauen. Dann ist die IP auch geloggt, aber du musst die nicht überall durchschleppen.


def update(self, client: modbus.ModbusTcpClient_):
power, powers = read_counter(client)
log.debug("Ip: %s, power %d", self.__address, power)
imported, exported = self.__sim_counter.sim_count(power)
counter_state = CounterState(
imported=imported,
exported=exported,
powers=powers,
power=power
)
self.__store.set(counter_state)
log.debug("Update completed successfully")


component_descriptor = ComponentDescriptor(configuration_factory=E3dcCounterSetup)
Loading