From 92dc4492e14991053a53a634d5e951a30f08a9d6 Mon Sep 17 00:00:00 2001 From: emtrax-ltd <60063640+emtrax-ltd@users.noreply.github.com> Date: Fri, 10 May 2024 14:34:26 +0200 Subject: [PATCH] Retrieve and check printer status via server-API (#81) --- MoonrakerConnection/MoonrakerOutputDevice.py | 11 +++++------ MoonrakerConnection/plugin.json | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/MoonrakerConnection/MoonrakerOutputDevice.py b/MoonrakerConnection/MoonrakerOutputDevice.py index e6e9ad4..837bfcd 100644 --- a/MoonrakerConnection/MoonrakerOutputDevice.py +++ b/MoonrakerConnection/MoonrakerOutputDevice.py @@ -293,19 +293,18 @@ def _turnPowerDeviceOn(self) -> None: self._sendRequest('machine/device_power/device?' + urllib.parse.urlencode({'device': powerDevice, 'action': 'on'}), data = '{}'.encode(), dataIsJSON = True, on_success = self._getPrinterStatus if index == 0 else None) def _getPrinterStatus(self, reply: QNetworkReply = None) -> None: - self._sendRequest('printer/info', on_success = self._checkPrinterStatus, on_error = self._onPrinterError) + self._sendRequest('server/info', on_success = self._checkPrinterStatus, on_error = self._onPrinterError) def _checkPrinterStatus(self, reply: QNetworkReply) -> None: response = self._getResponse(reply) - status = response['result']['state'] - message = response['result']['state_message'] + status = response['result']['klippy_state'] - if self._startPrint and status == 'ready' or not self._startPrint and status != 'error': - # status == 'ready' => printer is online || status != 'error' => upload possible + if self._startPrint and status == 'ready' or not self._startPrint: + # startPrint & status == 'ready' => printer is online || no startPrint => upload only self._onPrinterOnline(reply) else: # printer is not ready => increase timeoutCounter - self._onPrinterError(reply, "The status of the printer is '{}'.\n\n{}".format(status, message.strip())) + self._onPrinterError(reply, "The status of the printer is '{}'.\n\n{}".format(status, status.strip())) def _onPrinterOnline(self, reply: QNetworkReply) -> None: # remove connection timeout message diff --git a/MoonrakerConnection/plugin.json b/MoonrakerConnection/plugin.json index 67b56f1..9378188 100644 --- a/MoonrakerConnection/plugin.json +++ b/MoonrakerConnection/plugin.json @@ -2,6 +2,6 @@ "name": "Klipper/Moonraker Connection", "author": "emtrax", "description": "Upload and Print with Klipper via Moonraker API.", - "version": "1.8.0", - "supported_sdk_versions": ["7.3.0", "7.4.0", "7.5.0", "7.6.0", "7.7.0", "7.8.0", "7.9.0", "8.0.0", "8.1.0", "8.2.0", "8.3.0", "8.4.0", "8.5.0", "8.6.0"] + "version": "1.8.1", + "supported_sdk_versions": ["7.3.0", "7.4.0", "7.5.0", "7.6.0", "7.7.0", "7.8.0", "7.9.0", "8.0.0", "8.1.0", "8.2.0", "8.3.0", "8.4.0", "8.5.0", "8.6.0", "8.7.0"] }