-
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.
- Loading branch information
Showing
9 changed files
with
326 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
#!/bin/bash | ||
OPENWBBASEDIR=$(cd "$(dirname "$0")/../../" && pwd) | ||
RAMDISKDIR="$OPENWBBASEDIR/ramdisk" | ||
MODULEDIR=$(cd "$(dirname "$0")" && pwd) | ||
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd) | ||
RAMDISKDIR="${OPENWBBASEDIR}/ramdisk" | ||
MODULEDIR=$(cd `dirname $0` && pwd) | ||
#DMOD="EVU" | ||
DMOD="MAIN" | ||
Debug=$debug | ||
|
||
if [ $DMOD == "MAIN" ]; then | ||
MYLOGFILE="$RAMDISKDIR/openWB.log" | ||
#For development only | ||
#Debug=1 | ||
|
||
if [ ${DMOD} == "MAIN" ]; then | ||
MYLOGFILE="${RAMDISKDIR}/openWB.log" | ||
else | ||
MYLOGFILE="$RAMDISKDIR/evu_json.log" | ||
MYLOGFILE="${RAMDISKDIR}/evu.log" | ||
fi | ||
|
||
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "bezug_lgessv1.lgessv1" "${lgessv1ip}" "${lgessv1pass}" "${ess_api_ver}" >>${MYLOGFILE} 2>&1 | ||
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.lg.device" "counter" "${lgessv1ip}" "${lgessv1pass}" "${ess_api_ver}">>${MYLOGFILE} 2>&1 | ||
ret=$? | ||
|
||
openwbDebugLog ${DMOD} 2 "RET: ${ret}" | ||
|
||
wattbezug=$(</var/www/html/openWB/ramdisk/wattbezug) | ||
echo "$wattbezug" | ||
openwbDebugLog ${DMOD} 2 "EVU RET: ${ret}" | ||
wattbezug=$(<${RAMDISKDIR}/wattbezug) | ||
echo $wattbezug |
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 |
---|---|---|
@@ -1,26 +1,29 @@ | ||
#!/bin/bash | ||
|
||
OPENWBBASEDIR=$(cd "$(dirname "$0")/../../" && pwd) | ||
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd) | ||
RAMDISKDIR="${OPENWBBASEDIR}/ramdisk" | ||
MODULEDIR=$(cd "$(dirname "$0")" && pwd) | ||
#MODULEDIR=$(cd `dirname $0` && pwd) | ||
#DMOD="BATT" | ||
DMOD="MAIN" | ||
Debug=$debug | ||
|
||
#For Development only | ||
#Debug=1 | ||
|
||
if [ ${DMOD} == "MAIN" ]; then | ||
MYLOGFILE="${RAMDISKDIR}/openWB.log" | ||
MYLOGFILE="${RAMDISKDIR}/openWB.log" | ||
else | ||
MYLOGFILE="${RAMDISKDIR}/speicher.log" | ||
MYLOGFILE="${RAMDISKDIR}/speicher.log" | ||
fi | ||
|
||
openwbDebugLog ${DMOD} 2 "Speicher IP: ${lgessv1ip}" | ||
openwbDebugLog ${DMOD} 2 "Speicher Passwort: ${lgessv1pass}" | ||
openwbDebugLog ${DMOD} 2 "Speicher Version: ${ess_api_ver}" | ||
|
||
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "speicher_lgessv1.lgessv1" "${lgessv1ip}" "${lgessv1pass}" "${ess_api_ver}" >>${MYLOGFILE} 2>&1 | ||
openwbDebugLog ${DMOD} 2 "Speicher Version: ${alphav123}" | ||
|
||
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.lg.device" "bat" "${lgessv1ip}" "${lgessv1pass}" "${ess_api_ver}" >>$MYLOGFILE 2>&1 | ||
ret=$? | ||
|
||
openwbDebugLog ${DMOD} 2 "RET: ${ret}" | ||
|
||
speicherleistung=$(<"${RAMDISKDIR}/speicherleistung") | ||
speicherleistung=$(<${RAMDISKDIR}/speicherleistung) | ||
|
||
openwbDebugLog ${DMOD} 1 "BattLeistung: ${speicherleistung}" | ||
openwbDebugLog ${DMOD} 1 "BattLeistung: ${speicherleistung}" |
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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
#!/bin/bash | ||
|
||
OPENWBBASEDIR=$(cd "$(dirname "$0")/../../" && pwd) | ||
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd) | ||
RAMDISKDIR="${OPENWBBASEDIR}/ramdisk" | ||
MODULEDIR=$(cd "$(dirname "$0")" && pwd) | ||
#DMOD="EVU" | ||
DMOD="MAIN" | ||
#MODULEDIR=$(cd `dirname $0` && pwd) | ||
DMOD="PV" | ||
#DMOD="MAIN" | ||
Debug=$debug | ||
|
||
if [ ${DMOD} == "MAIN" ]; then | ||
#For Development only | ||
#Debug=1 | ||
|
||
if [ $DMOD == "MAIN" ]; then | ||
MYLOGFILE="${RAMDISKDIR}/openWB.log" | ||
else | ||
MYLOGFILE="${RAMDISKDIR}/wr_lgessv1.log" | ||
MYLOGFILE="${RAMDISKDIR}/nurpv.log" | ||
fi | ||
|
||
openwbDebugLog ${DMOD} 2 "WR IP: ${lgessv1ip}" | ||
openwbDebugLog ${DMOD} 2 "WR Passwort: ${ess_pass}" | ||
openwbDebugLog ${DMOD} 2 "WR Version: ${ess_api_ver}" | ||
|
||
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "wr_lgessv1.lgessv1" "${lgessv1ip}" "${ess_pass}" "${ess_api_ver}" >>$MYLOGFILE 2>&1 | ||
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.lg.device" "inverter" "${lgessv1ip}" "${ess_pass}" "${ess_api_ver}" "1">>$MYLOGFILE 2>&1 | ||
ret=$? | ||
|
||
openwbDebugLog ${DMOD} 2 "RET: ${ret}" | ||
|
||
pvwatt=$(</var/www/html/openWB/ramdisk/pvwatt) | ||
echo "$pvwatt" | ||
watt=$(<${RAMDISKDIR}/pvwatt) | ||
echo ${watt} |
File renamed without changes.
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,52 @@ | ||
#!/usr/bin/env python3 | ||
import requests | ||
|
||
from helpermodules import log | ||
from modules.common import simcount | ||
from modules.common.component_state import BatState | ||
from modules.common.fault_state import ComponentInfo | ||
from modules.common.store import get_bat_value_store | ||
from modules.common.fault_state import FaultState | ||
|
||
|
||
def get_default_config() -> dict: | ||
return { | ||
"name": "LG ESS V1.0 Speicher", | ||
"id": 0, | ||
"type": "bat", | ||
"configuration": {} | ||
} | ||
|
||
|
||
class LgBat: | ||
def __init__(self, device_id: int, component_config: dict) -> None: | ||
self.__device_id = device_id | ||
self.component_config = component_config | ||
self.__sim_count = simcount.SimCountFactory().get_sim_counter()() | ||
self.__simulation = {} | ||
self.__store = get_bat_value_store(component_config["id"]) | ||
self.component_info = ComponentInfo.from_component_config(component_config) | ||
|
||
def update(self, response) -> None: | ||
power = float(response["statistics"]["batconv_power"]) | ||
if response["direction"]["is_battery_discharging_"] == "1": | ||
power = power * -1 | ||
try: | ||
soc = float(response["statistics"]["bat_user_soc"]) | ||
except ValueError: | ||
FaultState.warning( | ||
'Speicher-SOC ist nicht numerisch und wird auf 0 gesetzt.').store_error(self.component_info) | ||
soc = 0 | ||
|
||
topic_str = "openWB/set/system/device/" + str( | ||
self.__device_id)+"/component/"+str(self.component_config["id"])+"/" | ||
imported, exported = self.__sim_count.sim_count( | ||
power, topic=topic_str, data=self.__simulation, prefix="speicher" | ||
) | ||
bat_state = BatState( | ||
power=power, | ||
soc=soc, | ||
imported=imported, | ||
exported=exported | ||
) | ||
self.__store.set(bat_state) |
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,45 @@ | ||
#!/usr/bin/env python3 | ||
from modules.common import simcount | ||
from modules.common.component_state import CounterState | ||
from modules.common.fault_state import ComponentInfo | ||
from modules.common.store import get_counter_value_store | ||
|
||
|
||
def get_default_config() -> dict: | ||
return { | ||
"name": "LG ESS V1.0 Zähler", | ||
"id": 0, | ||
"type": "counter", | ||
"configuration": {} | ||
} | ||
|
||
|
||
class LgCounter: | ||
def __init__(self, device_id: int, component_config: dict) -> None: | ||
self.__device_id = device_id | ||
self.component_config = component_config | ||
self.__sim_count = simcount.SimCountFactory().get_sim_counter()() | ||
self.simulation = {} | ||
self.__store = get_counter_value_store(component_config["id"]) | ||
self.component_info = ComponentInfo.from_component_config(component_config) | ||
|
||
def update(self, response) -> None: | ||
power = float(response["statistics"]["grid_power"]) | ||
if response["direction"]["is_grid_selling_"] == "1": | ||
power = power*-1 | ||
|
||
topic_str = "openWB/set/system/device/{}/component/{}/".format( | ||
self.__device_id, self.component_config["id"] | ||
) | ||
imported, exported = self.__sim_count.sim_count( | ||
power, | ||
topic=topic_str, | ||
data=self.simulation, | ||
prefix="bezug" | ||
) | ||
counter_state = CounterState( | ||
imported=imported, | ||
exported=exported, | ||
power=power | ||
) | ||
self.__store.set(counter_state) |
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,144 @@ | ||
#!/usr/bin/env python3 | ||
import json | ||
import os | ||
from typing import Dict, Union, Optional, List | ||
|
||
from helpermodules import log | ||
from helpermodules.cli import run_using_positional_cli_args | ||
from modules.common import req | ||
from modules.lg import bat | ||
from modules.lg import counter | ||
from modules.lg import inverter | ||
from modules.common.abstract_device import AbstractDevice | ||
from modules.common.component_context import MultiComponentUpdateContext | ||
from modules.common.fault_state import FaultState | ||
|
||
|
||
def get_default_config() -> dict: | ||
return { | ||
"name": "LG ESS V1.0", | ||
"type": "lg", | ||
"id": 0, | ||
"configuration": { | ||
"ip": "", | ||
"password": "abc" | ||
} | ||
} | ||
|
||
|
||
lg_component_classes = Union[bat.LgBat, counter.LgCounter, inverter.LgInverter] | ||
|
||
|
||
class Device(AbstractDevice): | ||
"""Beispiel JSON-Objekte liegen im Ordner lgessv1/JSON-Beispiele.txt | ||
lg_ess_url: IP/URL des LG ESS V1.0 | ||
lg_ess_pass: Passwort, um sich in den LG ESS V1.0 einzuloggen. | ||
Das Passwort ist standardmäßig die Registrierungsnummer, | ||
die sich auf dem PCS (dem Hybridwechselrichter und | ||
Batteriemanagementsystem) befindet (Aufkleber!). Alter- | ||
nativ findet man die Registrierungsnummer in der App unter | ||
dem Menüpunkt "Systeminformationen". | ||
Mit der Registrierungsnummer kann man sich dann in der | ||
Rolle "installer" einloggen.""" | ||
COMPONENT_TYPE_TO_CLASS = { | ||
"bat": bat.LgBat, | ||
"counter": counter.LgCounter, | ||
"inverter": inverter.LgInverter | ||
} | ||
|
||
def __init__(self, device_config: dict) -> None: | ||
self._components = {} # type: Dict[str, lg_component_classes] | ||
self.session_key = " " | ||
try: | ||
self.device_config = device_config | ||
except Exception: | ||
log.MainLogger().exception("Fehler im Modul "+device_config["name"]) | ||
|
||
def add_component(self, component_config: dict) -> None: | ||
component_type = component_config["type"] | ||
if component_type in self.COMPONENT_TYPE_TO_CLASS: | ||
self._components["component"+str(component_config["id"])] = (self.COMPONENT_TYPE_TO_CLASS[component_type]( | ||
self.device_config["id"], | ||
component_config)) | ||
else: | ||
raise Exception( | ||
"illegal component type " + component_type + ". Allowed values: " + | ||
','.join(self.COMPONENT_TYPE_TO_CLASS.keys()) | ||
) | ||
|
||
def update(self) -> None: | ||
log.MainLogger().debug("Start device reading " + str(self._components)) | ||
if self._components: | ||
response = self.get_state() | ||
with MultiComponentUpdateContext(self._components): | ||
for component in self._components: | ||
self._components[component].update(response) | ||
else: | ||
log.MainLogger().warning( | ||
self.device_config["name"] + | ||
": Es konnten keine Werte gelesen werden, da noch keine Komponenten konfiguriert wurden." | ||
) | ||
|
||
def get_state(self) -> Dict: | ||
session = req.get_http_session() | ||
response = self.__post_data(session) | ||
# missing "auth" in response indicates successful data request. | ||
if "auth" in response: | ||
# Prüfen, ob Sessionkey ungültig ist, wenn ja, Login und neuen Sessionkey empfangen. | ||
auth_check = response['auth'] | ||
if auth_check == "auth_key failed" or auth_check == "auth timeout" or auth_check == "not done": | ||
headers = {'Content-Type': 'application/json', } | ||
data = json.dumps({"password": self.device_config["configuration"]["password"]}) | ||
response = session.put( | ||
"https://"+self.device_config["configuration"]["ip"] + "/v1/login", headers=headers, data=data, verify=False, timeout=5).json() | ||
self.session_key = response["auth_key"] | ||
return self.__post_data(session) | ||
else: | ||
raise FaultState.error("Unbekannter Fehler im Login-Prozess: "+str(auth_check)) | ||
else: | ||
return response | ||
|
||
def __post_data(self, session) -> Dict: | ||
headers = {'Content-Type': 'application/json', } | ||
data = json.dumps({"auth_key": self.session_key}) | ||
return session.post("https://"+self.device_config["configuration"]["ip"] + "/v1/user/essinfo/home", headers=headers, | ||
data=data, verify=False, timeout=5).json() | ||
|
||
|
||
def read_legacy(component_type: str, ip: str, password: str, num: Optional[int] = None) -> None: | ||
COMPONENT_TYPE_TO_MODULE = { | ||
"bat": bat, | ||
"counter": counter, | ||
"inverter": inverter | ||
} | ||
device_config = get_default_config() | ||
device_config["configuration"]["ip"] = ip | ||
device_config["configuration"]["password"] = password | ||
dev = Device(device_config) | ||
|
||
if os.path.isfile("/var/www/html/openWB/ramdisk/ess_session_key"): | ||
with open("/var/www/html/openWB/ramdisk/ess_session_key", "r") as f: | ||
# erste Zeile ohne Zeilenumbruch lesen | ||
old_session_key = f.readline().strip() | ||
dev.session_key = old_session_key | ||
|
||
if component_type in COMPONENT_TYPE_TO_MODULE: | ||
component_config = COMPONENT_TYPE_TO_MODULE[component_type].get_default_config() | ||
else: | ||
raise Exception( | ||
"illegal component type " + component_type + ". Allowed values: " + | ||
','.join(COMPONENT_TYPE_TO_MODULE.keys()) | ||
) | ||
component_config["id"] = num | ||
dev.add_component(component_config) | ||
log.MainLogger().debug('LG ESS V1.0 IP: ' + ip) | ||
log.MainLogger().debug('LG ESS V1.0 password: ' + password) | ||
dev.update() | ||
|
||
if dev.session_key != old_session_key: | ||
with open("/var/www/html/openWB/ramdisk/ess_session_key", "w") as f: | ||
f.write(str(dev.session_key)) | ||
|
||
|
||
def main(argv: List[str]): | ||
run_using_positional_cli_args(read_legacy, argv) |
Oops, something went wrong.