From d90c3bc57a5f0da29d944dd522bb4ca3cd7d0b39 Mon Sep 17 00:00:00 2001
From: Eric Callahan <arksine.code@gmail.com>
Date: Wed, 27 Oct 2021 14:41:33 -0400
Subject: [PATCH] idle_timeout: exit the timer if the printer is shutdown

This resolves an issue where the timer can get stuck
in an attempt to transition from Ready to Idle if
the printer is shutdown.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
---
 klippy/extras/idle_timeout.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/klippy/extras/idle_timeout.py b/klippy/extras/idle_timeout.py
index 9a4cd4501..479c0b5c7 100644
--- a/klippy/extras/idle_timeout.py
+++ b/klippy/extras/idle_timeout.py
@@ -71,6 +71,8 @@ class IdleTimeout:
         # Idle timeout has elapsed
         return self.transition_idle_state(eventtime)
     def timeout_handler(self, eventtime):
+        if self.printer.is_shutdown():
+            return self.reactor.NEVER
         if self.state == "Ready":
             return self.check_idle_timeout(eventtime)
         # Check if need to transition to "ready" state