klippy: Convert printer_state("connect") to an event handler

Convert all users of the printer_state("connect") handler to register
a "klippy:connect" event handler instead.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2019-01-08 11:09:55 -05:00
parent 797367b9f5
commit 857e7ed5f1
8 changed files with 32 additions and 37 deletions

View File

@@ -13,6 +13,8 @@ for the parameters that control this check.
class HeaterCheck:
def __init__(self, config):
self.printer = config.get_printer()
self.printer.register_event_handler("klippy:connect",
self.handle_connect)
self.printer.register_event_handler("klippy:shutdown",
self.handle_shutdown)
self.heater_name = config.get_name().split()[1]
@@ -29,17 +31,15 @@ class HeaterCheck:
self.last_target = self.goal_temp = self.error = 0.
self.fault_systime = self.printer.get_reactor().NEVER
self.check_timer = None
def printer_state(self, state):
if state == 'connect':
if self.printer.get_start_args().get('debugoutput') is not None:
# Disable verify_heater if outputting to a debug file
return
pheater = self.printer.lookup_object('heater')
self.heater = pheater.lookup_heater(self.heater_name)
logging.info("Starting heater checks for %s", self.heater_name)
reactor = self.printer.get_reactor()
self.check_timer = reactor.register_timer(self.check_event,
reactor.NOW)
def handle_connect(self):
if self.printer.get_start_args().get('debugoutput') is not None:
# Disable verify_heater if outputting to a debug file
return
pheater = self.printer.lookup_object('heater')
self.heater = pheater.lookup_heater(self.heater_name)
logging.info("Starting heater checks for %s", self.heater_name)
reactor = self.printer.get_reactor()
self.check_timer = reactor.register_timer(self.check_event, reactor.NOW)
def handle_shutdown(self):
if self.check_timer is not None:
reactor = self.printer.get_reactor()