diff --git a/modules/bezug_http/main.sh b/modules/bezug_http/main.sh index 4dbb67102..2c9e8ddd0 100755 --- a/modules/bezug_http/main.sh +++ b/modules/bezug_http/main.sh @@ -15,7 +15,7 @@ else MYLOGFILE="$RAMDISKDIR/evu.log" fi -python3 /var/www/html/openWB/packages/modules/http/device.py "counter" "${bezug_http_w_url}" "${bezug_http_ikwh_url}" "${bezug_http_ekwh_url}" "${bezug_http_l1_url}" "${bezug_http_l2_url}" "${bezug_http_l3_url}" >>$MYLOGFILE 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.http.device" "counter" "${bezug_http_w_url}" "${bezug_http_ikwh_url}" "${bezug_http_ekwh_url}" "${bezug_http_l1_url}" "${bezug_http_l2_url}" "${bezug_http_l3_url}" >>$MYLOGFILE 2>&1 ret=$? openwbDebugLog ${DMOD} 2 "RET: ${ret}" diff --git a/modules/bezug_json/main.sh b/modules/bezug_json/main.sh index c3fe9afe2..c51ba87b8 100755 --- a/modules/bezug_json/main.sh +++ b/modules/bezug_json/main.sh @@ -20,7 +20,7 @@ openwbDebugLog ${DMOD} 2 "Filter Watt : ${bezugjsonwatt}" openwbDebugLog ${DMOD} 2 "Filter Bezug: ${bezugjsonkwh}" openwbDebugLog ${DMOD} 2 "Filter Einsp: ${einspeisungjsonkwh}" -python3 $OPENWBBASEDIR/packages/modules/json/device.py "counter" "${bezugjsonurl}" "${bezugjsonwatt}" "${bezugjsonkwh}" "${einspeisungjsonkwh}" >>$MYLOGFILE 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.json.device" "counter" "${bezugjsonurl}" "${bezugjsonwatt}" "${bezugjsonkwh}" "${einspeisungjsonkwh}" >>$MYLOGFILE 2>&1 ret=$? openwbDebugLog ${DMOD} 2 "RET: ${ret}" diff --git a/modules/speicher_http/main.sh b/modules/speicher_http/main.sh index df85cf813..791d4ea11 100755 --- a/modules/speicher_http/main.sh +++ b/modules/speicher_http/main.sh @@ -21,7 +21,7 @@ openwbDebugLog ${DMOD} 2 "Speicher Import: ${speicherikwh_http}" openwbDebugLog ${DMOD} 2 "Speicher Watt: ${speicherleistung_http}" openwbDebugLog ${DMOD} 2 "Speicher SoC: ${speichersoc_http}" -python3 /var/www/html/openWB/packages/modules/http/device.py "bat" "${speicherleistung_http}" "${speicherikwh_http}" "${speicherekwh_http}" "${speichersoc_http}" >>$MYLOGFILE 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.http.device" "bat" "${speicherleistung_http}" "${speicherikwh_http}" "${speicherekwh_http}" "${speichersoc_http}" >>$MYLOGFILE 2>&1 ret=$? openwbDebugLog ${DMOD} 2 "RET: ${ret}" diff --git a/modules/speicher_json/main.sh b/modules/speicher_json/main.sh index 5d6e56141..9aa3b9b57 100755 --- a/modules/speicher_json/main.sh +++ b/modules/speicher_json/main.sh @@ -21,7 +21,7 @@ openwbDebugLog ${DMOD} 2 "Speicher URL: ${battjsonurl}" openwbDebugLog ${DMOD} 2 "Speicher Watt: ${battjsonwatt}" openwbDebugLog ${DMOD} 2 "Speicher SoC: ${battjsonsoc}" -python3 $OPENWBBASEDIR/packages/modules/json/device.py "bat" "${battjsonurl}" "${battjsonwatt}" "${battjsonsoc}" >>$MYLOGFILE 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.json.device" "bat" "${battjsonurl}" "${battjsonwatt}" "${battjsonsoc}" >>$MYLOGFILE 2>&1 ret=$? openwbDebugLog ${DMOD} 2 "RET: ${ret}" diff --git a/modules/wr2_json/main.sh b/modules/wr2_json/main.sh index 206bebbe5..6d456a425 100755 --- a/modules/wr2_json/main.sh +++ b/modules/wr2_json/main.sh @@ -23,7 +23,7 @@ openwbDebugLog ${DMOD} 2 "PV URL : ${wr2jsonurl}" openwbDebugLog ${DMOD} 2 "PV Watt: ${wr2jsonwatt}" openwbDebugLog ${DMOD} 2 "PV kWh : ${wr2jsonkwh}" -python3 $OPENWBBASEDIR/packages/modules/json/device.py "inverter" "${wr2jsonurl}" "${wr2jsonwatt}" "${wr2jsonkwh}" "2" >>$MYLOGFILE 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.json.device" "inverter" "${wr2jsonurl}" "${wr2jsonwatt}" "${wr2jsonkwh}" "2" >>$MYLOGFILE 2>&1 ret=$? openwbDebugLog ${DMOD} 2 "RET: ${ret}" diff --git a/modules/wr_http/main.sh b/modules/wr_http/main.sh index ab377bf19..43fca0cc6 100755 --- a/modules/wr_http/main.sh +++ b/modules/wr_http/main.sh @@ -16,7 +16,7 @@ else fi -python3 ${OPENWBBASEDIR}/packages/modules/http/device.py "inverter" "${wr_http_w_url}" "${wr_http_kwh_url}" "1">>${MYLOGFILE} 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.http.device" "inverter" "${wr_http_w_url}" "${wr_http_kwh_url}" "1">>${MYLOGFILE} 2>&1 pvwatt=$(<${RAMDISKDIR}/pvwatt) echo $pvwatt diff --git a/modules/wr_huawei/main.sh b/modules/wr_huawei/main.sh index d5b7c6a27..94109154a 100755 --- a/modules/wr_huawei/main.sh +++ b/modules/wr_huawei/main.sh @@ -16,7 +16,7 @@ else fi -python3 ${OPENWBBASEDIR}/packages/modules/huawei/device.py "${pv1_ipa}" "${pv1_ida}">>${MYLOGFILE} 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.huawei.device" "${pv1_ipa}" "${pv1_ida}">>${MYLOGFILE} 2>&1 pvwatt=$(<${RAMDISKDIR}/pvwatt) echo $pvwatt diff --git a/modules/wr_json/main.sh b/modules/wr_json/main.sh index a0ae212b1..a7282a2d3 100755 --- a/modules/wr_json/main.sh +++ b/modules/wr_json/main.sh @@ -23,7 +23,7 @@ openwbDebugLog ${DMOD} 2 "PV URL : ${wrjsonurl}" openwbDebugLog ${DMOD} 2 "PV Watt: ${wrjsonwatt}" openwbDebugLog ${DMOD} 2 "PV kWh : ${wrjsonkwh}" -python3 $OPENWBBASEDIR/packages/modules/json/device.py "inverter" "${wrjsonurl}" "${wrjsonwatt}" "${wrjsonkwh}" "1" >>$MYLOGFILE 2>&1 +bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.json.device" "inverter" "${wrjsonurl}" "${wrjsonwatt}" "${wrjsonkwh}" "1" >>$MYLOGFILE 2>&1 ret=$? openwbDebugLog ${DMOD} 2 "RET: ${ret}" diff --git a/packages/modules/http/device.py b/packages/modules/http/device.py index 306ebcf71..446fd6d82 100644 --- a/packages/modules/http/device.py +++ b/packages/modules/http/device.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import re -from typing import Dict, Union +from typing import Dict, Union, List from urllib3.util import parse_url @@ -141,7 +141,7 @@ def read_legacy_inverter(power_path: str, counter_path: str, num: int): run_device_legacy(create_legacy_device_config(power_path), component_config) -if __name__ == "__main__": +def main(argv: List[str]): run_using_positional_cli_args( - {"bat": read_legacy_bat, "counter": read_legacy_counter, "inverter": read_legacy_inverter} + {"bat": read_legacy_bat, "counter": read_legacy_counter, "inverter": read_legacy_inverter}, argv ) diff --git a/packages/modules/huawei/device.py b/packages/modules/huawei/device.py index 2057800a1..d59bb22e7 100644 --- a/packages/modules/huawei/device.py +++ b/packages/modules/huawei/device.py @@ -1,10 +1,9 @@ #!/usr/bin/env python3 import time -from typing import Dict, Union +from typing import Dict, Union, List from helpermodules import log from helpermodules.cli import run_using_positional_cli_args -from helpermodules.log import setup_logging_stdout from modules.common import modbus from modules.common.abstract_device import AbstractDevice from modules.common.component_context import SingleComponentUpdateContext @@ -106,6 +105,5 @@ def read_legacy(ip_address: str, modbus_id: int) -> None: dev.update() -if __name__ == "__main__": - setup_logging_stdout() - run_using_positional_cli_args(read_legacy) +def main(argv: List[str]): + run_using_positional_cli_args(read_legacy, argv) diff --git a/packages/modules/json/device.py b/packages/modules/json/device.py index 91770e576..bea77c6ea 100644 --- a/packages/modules/json/device.py +++ b/packages/modules/json/device.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 -import sys -from typing import Dict, List, Union +from typing import Dict, List, Union, Optional from helpermodules import log +from helpermodules.cli import run_using_positional_cli_args from modules.common import req from modules.common.abstract_device import AbstractDevice from modules.common.component_context import MultiComponentUpdateContext @@ -65,54 +65,37 @@ def update(self) -> None: ) -def read_legacy(argv: List[str]) -> None: - COMPONENT_TYPE_TO_MODULE = { - "bat": bat, - "counter": counter, - "inverter": inverter - } - component_type = argv[1] +def read_legacy(ip_address: str, component_config: dict, num: Optional[int] = None, **kwargs) -> None: + component_config["configuration"].update(kwargs) + component_config["id"] = num device_config = get_default_config() - device_config["configuration"]["ip_address"] = argv[2] - dev = Device(device_config) - 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()) - ) - if component_type == "bat": - component_config["configuration"] = { - "jq_power": argv[3], - "jq_soc": argv[4] - } - num = None - elif component_type == "counter": - component_config["configuration"] = { - "jq_power": argv[3], - "jq_imported": argv[4], - "jq_exported": argv[5] - } - num = None - else: - component_config["configuration"] = { - "jq_power": argv[3], - "jq_counter": argv[4] - } - num = int(argv[5]) + device_config["configuration"]["ip_address"] = ip_address - component_config["id"] = num + dev = Device(device_config) dev.add_component(component_config) + dev.update() - log.MainLogger().debug('Json Konfiguration: ' + str(component_config["configuration"])) - dev.update() +def read_legacy_bat(ip_address: str, jq_power: str, jq_soc: str): + read_legacy(ip_address, bat.get_default_config(), jq_power=jq_power, jq_soc=jq_soc) + + +def read_legacy_counter(ip_address: str, jq_power: str, jq_imported: str, jq_exported: str): + read_legacy( + ip_address, + counter.get_default_config(), + jq_power=jq_power, + jq_imported=jq_imported, + jq_exported=jq_exported + ) + + +def read_legacy_inverter(ip_address: str, jq_power: str, jq_counter: str, num: int): + read_legacy(ip_address, inverter.get_default_config(), num, jq_power=jq_power, jq_counter=jq_counter) -if __name__ == "__main__": - try: - read_legacy(sys.argv) - except Exception: - log.MainLogger().exception("Fehler im Json Skript") +def main(argv: List[str]): + run_using_positional_cli_args( + {"bat": read_legacy_bat, "counter": read_legacy_counter, "inverter": read_legacy_inverter}, argv + )