Skip to content

Commit 1d120e7

Browse files
committed
Add error handling in inverter control operations
This commit introduces try-except blocks to handle exceptions during inverter status and mode operations. If an error occurs, the exception is logged, and the script exits with an error code. Additionally, a log message is added to indicate when the inverter is manually controlled by the user.
1 parent 8a61522 commit 1d120e7

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

inverter

+17-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from goodwe.et import OperationMode
1010
from inverter import Inverter
1111
1212
inverter = Inverter()
13+
inverter.log.info("Inverter is manually controlled by user")
1314
EOF
1415

1516

@@ -27,10 +28,15 @@ fi
2728
if [[ ${1} == "--status" ]]; then
2829
python3 - << EOF
2930
${setup_code}
30-
mode = inverter.get_operation_mode().name
31-
soc = inverter.get_state_of_charge()
32-
print(f"SoC: {soc} %\nmode: {mode}")
31+
try:
32+
mode = inverter.get_operation_mode().name
33+
soc = inverter.get_state_of_charge()
34+
print(f"SoC: {soc} %\nmode: {mode}")
35+
except Exception as e:
36+
inverter.log.exception(e)
37+
exit(1)
3338
EOF
39+
exit $?
3440
fi
3541

3642
if [[ ${1} == "--mode" ]]; then
@@ -41,8 +47,13 @@ if [[ ${1} == "--mode" ]]; then
4147

4248
python3 - << EOF
4349
${setup_code}
44-
last_mode = inverter.get_operation_mode().name
45-
inverter.set_operation_mode(OperationMode.${2})
46-
print(f"last mode: {last_mode}\nnew mode: ${2}")
50+
try:
51+
last_mode = inverter.get_operation_mode().name
52+
inverter.set_operation_mode(OperationMode.${2})
53+
print(f"last mode: {last_mode}\nnew mode: ${2}")
54+
except Exception as e:
55+
inverter.log.exception(e)
56+
exit(1)
4757
EOF
58+
exit $?
4859
fi

0 commit comments

Comments
 (0)