Skip to content

Commit

Permalink
use legacy run in remaining modules (json, http, huawei)
Browse files Browse the repository at this point in the history
  • Loading branch information
yankee42 committed Jan 10, 2022
1 parent b29c062 commit 211bca3
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 61 deletions.
2 changes: 1 addition & 1 deletion modules/bezug_http/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion modules/bezug_json/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion modules/speicher_http/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion modules/speicher_json/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion modules/wr2_json/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion modules/wr_http/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/wr_huawei/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules/wr_json/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
6 changes: 3 additions & 3 deletions packages/modules/http/device.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
)
8 changes: 3 additions & 5 deletions packages/modules/huawei/device.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
73 changes: 28 additions & 45 deletions packages/modules/json/device.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
)

0 comments on commit 211bca3

Please sign in to comment.