-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Varta * remove varta from loadvars * review fix
- Loading branch information
Showing
11 changed files
with
327 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
import xml.etree.ElementTree as ET | ||
|
||
from dataclass_utils import dataclass_from_dict | ||
from modules.common import req | ||
from modules.common.component_state import BatState | ||
from modules.common.component_type import ComponentDescriptor | ||
from modules.common.fault_state import ComponentInfo | ||
from modules.common.simcount import SimCounter | ||
from modules.common.store import get_bat_value_store | ||
from modules.devices.varta.config import VartaBatApiSetup | ||
|
||
|
||
class VartaBatApi: | ||
def __init__(self, device_id: int, component_config: VartaBatApiSetup, device_address: str) -> None: | ||
self.__device_id = device_id | ||
self.component_config = dataclass_from_dict(VartaBatApiSetup, component_config) | ||
self.__device_address = device_address | ||
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) | ||
|
||
def update(self) -> None: | ||
def get_xml_text(attribute_value: str) -> float: | ||
value = None | ||
for element in root[0].iter("var"): | ||
if element.attrib["name"] == attribute_value: | ||
value = element.attrib["value"] | ||
try: | ||
return float(value) | ||
except ValueError: | ||
# Wenn Speicher aus bzw. im Standby (keine Antwort), ersetze leeren Wert durch eine 0. | ||
return 0 | ||
|
||
response = req.get_http_session().get('http://'+self.__device_address+'/cgi/ems_data.xml', | ||
timeout=5) | ||
response.encoding = 'utf-8' | ||
response = response.text.replace("\n", "") | ||
root = ET.fromstring(response) | ||
|
||
power = get_xml_text("P") | ||
soc = get_xml_text("SOC") / 10 | ||
|
||
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=VartaBatApiSetup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
from dataclass_utils import dataclass_from_dict | ||
from modules.common.component_state import BatState | ||
from modules.common.component_type import ComponentDescriptor | ||
from modules.common.fault_state import ComponentInfo | ||
from modules.common.modbus import ModbusDataType, ModbusTcpClient_ | ||
from modules.common.simcount import SimCounter | ||
from modules.common.store import get_bat_value_store | ||
from modules.devices.varta.config import VartaBatModbusSetup | ||
|
||
|
||
class VartaBatModbus: | ||
def __init__(self, device_id: int, component_config: VartaBatModbusSetup) -> None: | ||
self.__device_id = device_id | ||
self.component_config = dataclass_from_dict(VartaBatModbusSetup, component_config) | ||
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) | ||
|
||
def update(self, client: ModbusTcpClient_) -> None: | ||
self.set_state(self.get_state(client)) | ||
|
||
def get_state(self, client: ModbusTcpClient_) -> BatState: | ||
soc = client.read_holding_registers(1068, ModbusDataType.INT_16, unit=1) | ||
power = client.read_holding_registers(1066, ModbusDataType.INT_16, unit=1) | ||
return BatState( | ||
power=power, | ||
soc=soc, | ||
) | ||
|
||
def set_state(self, state: BatState) -> None: | ||
state.imported, state.exported = self.sim_counter.sim_count(state.power) | ||
self.store.set(state) | ||
|
||
|
||
component_descriptor = ComponentDescriptor(configuration_factory=VartaBatModbusSetup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from typing import Optional | ||
from helpermodules.auto_str import auto_str | ||
from modules.common.component_setup import ComponentSetup | ||
|
||
|
||
@auto_str | ||
class VartaConfiguration: | ||
def __init__(self, ip_address: Optional[str] = None): | ||
self.ip_address = ip_address | ||
|
||
|
||
@auto_str | ||
class Varta: | ||
def __init__(self, | ||
name: str = "Varta", | ||
type: str = "varta", | ||
id: int = 0, | ||
configuration: VartaConfiguration = None) -> None: | ||
self.name = name | ||
self.type = type | ||
self.id = id | ||
self.configuration = configuration or VartaConfiguration() | ||
|
||
|
||
@auto_str | ||
class VartaBatApiConfiguration: | ||
def __init__(self): | ||
pass | ||
|
||
|
||
@auto_str | ||
class VartaBatApiSetup(ComponentSetup[VartaBatApiConfiguration]): | ||
def __init__(self, | ||
name: str = "Varta Speicher (Abfrage per API)", | ||
type: str = "bat_api", | ||
id: int = 0, | ||
configuration: VartaBatApiConfiguration = None) -> None: | ||
super().__init__(name, type, id, configuration or VartaBatApiConfiguration()) | ||
|
||
|
||
@auto_str | ||
class VartaBatModbusConfiguration: | ||
def __init__(self): | ||
pass | ||
|
||
|
||
@auto_str | ||
class VartaBatModbusSetup(ComponentSetup[VartaBatModbusConfiguration]): | ||
def __init__(self, | ||
name: str = "Speicher Varta Pulse, Element, Neo, u.a. (Abfrage per Modbus)", | ||
type: str = "bat_modbus", | ||
id: int = 0, | ||
configuration: VartaBatModbusConfiguration = None) -> None: | ||
super().__init__(name, type, id, configuration or VartaBatModbusConfiguration()) | ||
|
||
|
||
@auto_str | ||
class VartaCounterConfiguration: | ||
def __init__(self): | ||
pass | ||
|
||
|
||
@auto_str | ||
class VartaCounterSetup(ComponentSetup[VartaCounterConfiguration]): | ||
def __init__(self, | ||
name: str = "Varta Zähler", | ||
type: str = "counter", | ||
id: int = 0, | ||
configuration: VartaCounterConfiguration = None) -> None: | ||
super().__init__(name, type, id, configuration or VartaCounterConfiguration()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
from dataclass_utils import dataclass_from_dict | ||
from modules.common.component_state import CounterState | ||
from modules.common.component_type import ComponentDescriptor | ||
from modules.common.fault_state import ComponentInfo | ||
from modules.common.modbus import ModbusDataType, ModbusTcpClient_ | ||
from modules.common.simcount import SimCounter | ||
from modules.common.store import get_counter_value_store | ||
from modules.devices.varta.config import VartaCounterSetup | ||
|
||
|
||
class VartaCounter: | ||
def __init__(self, device_id: int, component_config: VartaCounterSetup) -> None: | ||
self.__device_id = device_id | ||
self.component_config = dataclass_from_dict(VartaCounterSetup, 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) | ||
|
||
def update(self, client: ModbusTcpClient_): | ||
power = client.read_holding_registers(1078, ModbusDataType.INT_16, unit=1) * -1 | ||
frequency = client.read_holding_registers(1082, ModbusDataType.UINT_16, unit=1) / 100 | ||
imported, exported = self.sim_counter.sim_count(power) | ||
|
||
counter_state = CounterState( | ||
imported=imported, | ||
exported=exported, | ||
power=power, | ||
frequency=frequency | ||
) | ||
self.store.set(counter_state) | ||
|
||
|
||
component_descriptor = ComponentDescriptor(configuration_factory=VartaCounterSetup) |
Oops, something went wrong.