Skip to content

Commit

Permalink
refactor discovergy for full oWB2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yankee42 committed Jan 17, 2022
1 parent 41c9185 commit 9d9f6dd
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 281 deletions.
61 changes: 0 additions & 61 deletions modules/bezug_discovergy/discovergy.py

This file was deleted.

143 changes: 0 additions & 143 deletions modules/bezug_discovergy/discovergy_test.py

This file was deleted.

14 changes: 13 additions & 1 deletion modules/bezug_discovergy/main.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#!/bin/bash
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)

python3 /var/www/html/openWB/modules/bezug_discovergy/discovergy.py "$discovergyuser" "$discovergypass" "$discovergyevuid" &>> "$OPENWBBASEDIR/ramdisk/openWB.log"
# If both wr_discovergy and bezug_discovergy are activated, then runs/loadvars.sh will run `wr_discovergy` first.
# In this case that wr_discovergy will fetch data for both inverter end counter and there is nothing left for us to do
# except reading the `wattbezug` file from ramdisk.
#
# If only bezug_discovery is activated then we fetch counter data here.
#
# The usage of wr_discovergy without bezug_discovergy is not intended and thus not handled.

if [[ "$pvwattmodul" != "wr_discovergy" ]]
then
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.discovergy.device" "$discovergyuser" "$discovergypass" "$discovergyevuid" "" >> "$OPENWBBASEDIR/ramdisk/openWB.log" 2>&1
fi

cat /var/www/html/openWB/ramdisk/wattbezug
52 changes: 0 additions & 52 deletions modules/wr_discovergy/discovergy.py

This file was deleted.

26 changes: 2 additions & 24 deletions modules/wr_discovergy/main.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
#!/bin/bash
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="${OPENWBBASEDIR}/ramdisk"
MODULEDIR=$(cd `dirname $0` && pwd)
#DMOD="EVU"
DMOD="MAIN"
Debug=$debug

#For development only
#Debug=1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.discovergy.device" "$discovergyuser" "$discovergypass" "$discovergyevuid" "$discovergypvid" &>> "$OPENWBBASEDIR/ramdisk/openWB.log"

if [ ${DMOD} == "MAIN" ]; then
MYLOGFILE="${RAMDISKDIR}/openWB.log"
else
MYLOGFILE="${RAMDISKDIR}/wr_discovergy.log"
fi

openwbDebugLog ${DMOD} 2 "WR User: ${discovergyuser}"
openwbDebugLog ${DMOD} 2 "WR Passwort: ${discovergypass}"
openwbDebugLog ${DMOD} 2 "WR ID: ${discovergypvid}"

python3 /var/www/html/openWB/modules/wr_discovergy/discovergy.py "${discovergyuser}" "${discovergypass}" "${discovergypvid}" >>$MYLOGFILE 2>&1
ret=$?

openwbDebugLog ${DMOD} 2 "RET: ${ret}"

pvwatt=$(</var/www/html/openWB/ramdisk/pvwatt)
echo $pvwatt
cat "$OPENWBBASEDIR/ramdisk/pvwatt"
Empty file.
34 changes: 34 additions & 0 deletions packages/modules/discovergy/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from itertools import repeat

from requests import Session

from modules.common.component_state import CounterState


def get_last_reading(session: Session, meter_id: str):
values = session.get(
"https://api.discovergy.com/public/v1/last_reading",
params={"meterId": meter_id},
timeout=3
).json()["values"]

def read_phases(*args: str, required: bool):
for format in args:
try:
return [values[format % phase] / 1000 for phase in range(1, 4)]
except KeyError:
pass
if required:
raise Exception("None of %s found in %s", args, values)

voltages = read_phases("voltage%i", "phase%iVoltage", required=False)
powers = read_phases("power%i", "phase%iPower", required=True)

return CounterState(
imported=values["energy"] / 10000000,
exported=values["energyOut"] / 10000000,
power=values["power"] / 1000,
voltages=voltages,
currents=[power / voltage for power, voltage in zip(powers, repeat(230) if voltages is None else voltages)],
powers=powers
)
Loading

0 comments on commit 9d9f6dd

Please sign in to comment.