-
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 all 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,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 | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| 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
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
|
||||||||||||
| # 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) | ||||||||||||
| 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()) | ||
| 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 | ||||
|
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. "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): | ||||
|
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. |
||||
| 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 | ||||
|
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. Du hattest dich nicht zu meinem Einwand geäußert, dass
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. Du hattest dich nicht zu meinem Einwand geäußert, dass |
||||
|
|
||||
| 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) | ||||
Uh oh!
There was an error while loading. Please reload this page.