-
Notifications
You must be signed in to change notification settings - Fork 198
E3DC nun komplett auf openwb V2.0 Struktur umgestellt #2449
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
Changes from 7 commits
7858789
acf50f4
7d2fdbb
b7e27f1
4fec76f
ddbe6aa
502a9d7
6809da8
6a38f02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #!/usr/bin/env python3 | ||
| from typing import Dict, Union | ||
| import logging | ||
|
|
||
| from dataclass_utils import dataclass_from_dict | ||
| 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_): | ||
| # 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 | ||
|
|
||
|
|
||
| class E3dcBat: | ||
| def __init__(self, | ||
| device_id: int, | ||
| ip_address: str, | ||
| component_config: Union[Dict, E3dcBatSetup]) -> None: | ||
| self.__device_id = device_id | ||
| self.component_config = dataclass_from_dict(E3dcBatSetup, component_config) | ||
okaegi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # 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.__ip_address = ip_address | ||
okaegi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def update(self, client: modbus.ModbusTcpClient_) -> None: | ||
|
|
||
| soc, power = read_bat(client) | ||
| log.debug("Ip: %s, soc %d power %d", self.__ip_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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from modules.common.component_setup import ComponentSetup | ||
| from modules.common import modbus | ||
|
|
||
|
|
||
| class E3dcConfiguration: | ||
| def __init__(self, ip_address1: str = None, | ||
| ip_address2: str = None, | ||
| read_ext: int = 0, | ||
| pvmodul: str = None | ||
okaegi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ): | ||
| self.ip_address1 = ip_address1 | ||
| self.ip_address2 = ip_address2 | ||
|
||
| self.read_ext = read_ext | ||
| self.pvmodul = pvmodul | ||
| # nur init hier | ||
| self.client = modbus.ModbusTcpClient_('127.0.0.1', 502) | ||
|
|
||
|
|
||
| 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() | ||
|
|
||
|
|
||
| class E3dcBatConfiguration: | ||
| def __init__(self): | ||
| pass | ||
|
|
||
|
|
||
| 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()) | ||
|
|
||
|
|
||
| class E3dcCounterConfiguration: | ||
| def __init__(self): | ||
| pass | ||
|
|
||
|
|
||
| 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()) | ||
|
|
||
|
|
||
| class E3dcInverterConfiguration: | ||
| def __init__(self): | ||
| pass | ||
|
|
||
|
|
||
| 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()) | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||
| #!/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 | ||||
| from modules.common.store.ramdisk.io import ramdisk_write, ramdisk_read_int | ||||
|
|
||||
| log = logging.getLogger(__name__) | ||||
|
|
||||
|
|
||||
| def read_counter(client: modbus.ModbusTcpClient_, ip_address): | ||||
|
||||
| log.debug("Beginning EVU update") | ||||
| try: | ||||
| foundreg = ramdisk_read_int("e3dc_evu_addr." + ip_address) | ||||
| except FileNotFoundError: | ||||
| foundreg = 0 | ||||
| power = client.read_holding_registers(40073, ModbusDataType.INT_32, wordorder=Endian.Little, unit=1) | ||||
| # 40130 Phasenleistung in Watt | ||||
|
||||
| # max 6 Leistungsmesser verbaut ab 410105, typ 1 ist evu | ||||
|
||||
| # bei den meisten e3dc auf 40128 | ||||
| # for register in range (40104,40132,4): | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Diese Zeile vom Kommentar scheint mir keine Hilfe zu sein. |
||||
| if foundreg == 0: | ||||
| for register in range(40128, 40103, -4): | ||||
| powers = client.read_holding_registers(register, [ModbusDataType.INT_16] * 4, unit=1) | ||||
| log.debug("register: %d, powers %s", | ||||
| register, powers) | ||||
| if powers[0] == 1: | ||||
okaegi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
| log.debug("Evu counter found, save %d", register) | ||||
| ramdisk_write("e3dc_evu_addr." + ip_address, register) | ||||
| break | ||||
| else: | ||||
| powers = client.read_holding_registers(foundreg, [ModbusDataType.INT_16] * 4, unit=1) | ||||
| log.debug("foundreg: %d, powers %s", foundreg, powers) | ||||
| return power, powers | ||||
|
|
||||
|
|
||||
| class E3dcCounter: | ||||
| def __init__(self, | ||||
| device_id: int, | ||||
| ip_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.__ip_address = ip_address | ||||
|
||||
|
|
||||
| def update(self, client: modbus.ModbusTcpClient_): | ||||
| power, powers = read_counter(client, self.__ip_address) | ||||
| imported, exported = self.__sim_counter.sim_count(power) | ||||
| counter_state = CounterState( | ||||
| imported=imported, | ||||
| exported=exported, | ||||
| powers=powers[1:], | ||||
| power=power | ||||
| ) | ||||
| self.__store.set(counter_state) | ||||
| log.debug("Update completed successfully") | ||||
|
|
||||
|
|
||||
| component_descriptor = ComponentDescriptor(configuration_factory=E3dcCounterSetup) | ||||
Uh oh!
There was an error while loading. Please reload this page.