-
Notifications
You must be signed in to change notification settings - Fork 0
/
inverter
executable file
·59 lines (50 loc) · 1.43 KB
/
inverter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
source "${SCRIPT_DIR}"/.venv/bin/activate
cd "${SCRIPT_DIR}"/source || exit 1
read -r -d '' setup_code <<'EOF'
from goodwe.et import OperationMode
from inverter import Inverter
inverter = Inverter()
inverter.log.info("Inverter is manually controlled by a user")
EOF
if [[ ! ${1} =~ ^(--status|--mode)$ ]]; then
echo "This script allows you to interact with the inverter."
echo ""
echo "You have to supply one of the following arguments:"
echo " --status Get the current state of charge and operation mode of the inverter"
echo " --mode {GENERAL,ECO_CHARGE} Set the operation mode of the inverter"
echo ""
echo "It uses the hostname defined in the .env file"
exit 1
fi
if [[ ${1} == "--status" ]]; then
python3 - << EOF
${setup_code}
try:
mode = inverter.get_operation_mode().name
soc = inverter.get_state_of_charge()
print(f"SoC: {soc} %\nmode: {mode}")
except Exception as e:
inverter.log.exception(e)
exit(1)
EOF
exit $?
fi
if [[ ${1} == "--mode" ]]; then
if [[ ! ${2} =~ ^(GENERAL|ECO_CHARGE)$ ]]; then
echo "Unsupported mode, valid modes are \"GENERAL\" and \"ECO_CHARGE\""
exit 1
fi
python3 - << EOF
${setup_code}
try:
last_mode = inverter.get_operation_mode().name
inverter.set_operation_mode(OperationMode.${2})
print(f"last mode: {last_mode}\nnew mode: ${2}")
except Exception as e:
inverter.log.exception(e)
exit(1)
EOF
exit $?
fi