From 014c06f8a20dd931fcd41e0068150dadafc7f74f Mon Sep 17 00:00:00 2001 From: Arksine Date: Tue, 23 Jun 2020 07:56:50 -0400 Subject: [PATCH] klippy: return message category in get_state_message() Signed-off-by: Eric Callahan --- klippy/gcode.py | 4 ++-- klippy/klippy.py | 8 +++++++- klippy/webhooks.py | 8 +++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/klippy/gcode.py b/klippy/gcode.py index c9f8a81b..22ec6606 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -437,7 +437,7 @@ class GCodeParser: gcmd.ack("T:0") return if not self.is_printer_ready: - raise gcmd.error(self.printer.get_state_message()) + raise gcmd.error(self.printer.get_state_message()[0]) return if not cmd: logging.debug(gcmd.get_commandline()) @@ -696,7 +696,7 @@ class GCodeParser: if self.is_printer_ready: self._respond_state("Ready") return - msg = self.printer.get_state_message() + msg = self.printer.get_state_message()[0] msg = msg.rstrip() + "\nKlipper state: Not ready" raise gcmd.error(msg) cmd_HELP_when_not_ready = True diff --git a/klippy/klippy.py b/klippy/klippy.py index 1da0a028..cd22ace9 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -65,7 +65,13 @@ class Printer: def get_reactor(self): return self.reactor def get_state_message(self): - return self.state_message + if self.state_message == message_ready: + category = "ready" + elif self.state_message == message_startup: + category = "startup" + else: + category = "error" + return self.state_message, category def is_shutdown(self): return self.in_shutdown_state def _set_state(self, msg): diff --git a/klippy/webhooks.py b/klippy/webhooks.py index 6c44b012..0379e3ab 100644 --- a/klippy/webhooks.py +++ b/klippy/webhooks.py @@ -8,7 +8,6 @@ import socket import errno import json import homing -from klippy import message_startup, message_ready SOCKET_LOCATION = "/tmp/moonraker" @@ -252,15 +251,14 @@ class WebHooks: if web_request.get_method() != 'GET': raise web_request.error("Invalid Request Method") start_args = self.printer.get_start_args() - state_message = self.printer.get_state_message() + state_message, msg_type = self.printer.get_state_message() version = start_args['software_version'] cpu_info = start_args['cpu_info'] - error = state_message != message_startup and \ - state_message != message_ready + error = msg_type == "error" web_request.send( {'cpu': cpu_info, 'version': version, 'hostname': socket.gethostname(), - 'is_ready': state_message == message_ready, + 'is_ready': msg_type == "ready", 'error_detected': error, 'message': state_message})