forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor discovergy for full oWB2 compatibility
- Loading branch information
Showing
13 changed files
with
356 additions
and
281 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
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
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.
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 @@ | ||
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 | ||
) |
Oops, something went wrong.