From 6d458125a1b97c8bdc721ca7b3fb0ebaa5d433d5 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 9 Nov 2021 10:17:52 -0500 Subject: [PATCH] power: fix scheduled firmware restarts Determine if a firmware restart should be postponed by checking Klippy's state. This should correctly schedule the restart regardless of whether or not the device is bound to Klipper. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 1f3e5e1..bcbd454 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -316,7 +316,7 @@ class PowerDevice: return self.need_scheduled_restart = False if state == "ready": - logging.info("Klipper reports 'ready', aborting firmware restart") + logging.info("Klipper reports 'ready', aborting FIRMWARE_RESTART") return event_loop = self.server.get_event_loop() kapis: APIComp = self.server.lookup_component("klippy_apis") @@ -348,7 +348,11 @@ class PowerDevice: await machine_cmp.do_service_action(action, self.bound_service) if self.state == "on" and self.klipper_restart: self.need_scheduled_restart = True - if self._is_bound_to_klipper(): + klippy_state = self.server.get_klippy_state() + if klippy_state in ["disconnected", "startup"]: + # If klippy is currently disconnected or hasn't proceeded past + # the startup state, schedule the restart in the + # "klippy_started" event callback. return self._schedule_firmware_restart()