Skip to content

Commit

Permalink
[ skip ci ] refactor previous commit to use a dedicated flag to handl…
Browse files Browse the repository at this point in the history
…e manual restarts
  • Loading branch information
JoshuaDodds committed Oct 25, 2024
1 parent 66202cf commit 519187d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def shutdown():
publish_message("Cerbomoticzgx/system/shutdown", message="True", retain=True)

def init():
# clear any previously published shutdown directives
if retrieve_message("system_shutdown"):
# let post_startup() know that this is a manually requested restart
publish_message("Cerbomoticzgx/system/manual_restart", message="True", retain=True)

# Set shutdown state to false (prevent a looping restart condition)
publish_message("Cerbomoticzgx/system/shutdown", message="False", retain=True)


Expand Down Expand Up @@ -146,13 +150,15 @@ def post_startup():
manage_grid_usage_based_on_current_price()

# re-run the charging scheduler based on current info and pricing if this was not a manual restart request
requested_restart = retrieve_message("system_shutdown")
system_manual_restart = retrieve_message("system/manual_restart")

if requested_restart is False or requested_restart is None:
if system_manual_restart is False or system_manual_restart is None:
logging.info(f"post_startup(): Updating the charging schedule based on currently available data...")
set_charging_schedule("main.post_startup()")
else:
logging.info(f"post_startup(): Manual restart was requested. Skipping charge schedule update.")
# set the system_manual_restart value back to False
publish_message("Cerbomoticzgx/system/manual_restart", message="False", retain=True)

# Start the general scheduled tasks
TaskScheduler()
Expand Down

0 comments on commit 519187d

Please sign in to comment.