Skip to content

Commit

Permalink
Refactor code and improve error handling
Browse files Browse the repository at this point in the history
Move functions to helpers instead of constants, add unit tests, and improve function to handle cases where there are no inverters or templates to query. Also, remove the dependency on running tests within the main function.
  • Loading branch information
0x7878 committed Nov 16, 2024
1 parent 6370a8e commit 3645b52
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbus_opendtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def get_DbusServices(config):
logging.warning("NumberOfTemplates not set, using default")
number_of_templates = 0

# If there are no inverters or templates, return an empty list
if number_of_inverters == 0 and number_of_templates == 0:
logging.critical("No inverters or templates to query")
return services

try:
dtuvariant = config["DEFAULT"]["DTU"]
except KeyError:
Expand Down Expand Up @@ -158,7 +163,7 @@ def main():
logging.debug("SignOfLifeLog: %d", signofliveinterval)

# TODO: I think it is better to run the tests inside CI/CD pipeline instead of running it here
tests.run_tests()
# tests.run_tests()

try:
logging.info("Start")
Expand Down

0 comments on commit 3645b52

Please sign in to comment.