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

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

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-01-08 10:55:18 -05:00
parent f4be0ac7be
commit 797367b9f5
8 changed files with 72 additions and 71 deletions

View file

@ -11,13 +11,13 @@ class PrinterStats:
reactor = self.printer.get_reactor()
self.stats_timer = reactor.register_timer(self.generate_stats)
self.stats_cb = []
def printer_state(self, state):
if state == 'ready':
self.stats_cb = [o.stats for n, o in self.printer.lookup_objects()
if hasattr(o, 'stats')]
if self.printer.get_start_args().get('debugoutput') is None:
reactor = self.printer.get_reactor()
reactor.update_timer(self.stats_timer, reactor.NOW)
self.printer.register_event_handler("klippy:ready", self.handle_ready)
def handle_ready(self):
self.stats_cb = [o.stats for n, o in self.printer.lookup_objects()
if hasattr(o, 'stats')]
if self.printer.get_start_args().get('debugoutput') is None:
reactor = self.printer.get_reactor()
reactor.update_timer(self.stats_timer, reactor.NOW)
def generate_stats(self, eventtime):
stats = [cb(eventtime) for cb in self.stats_cb]
if max([s[0] for s in stats]):