Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve and check printer status via server-API (#81) #88

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions MoonrakerConnection/MoonrakerOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions MoonrakerConnection/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}