From e08efafbb0207ac0d79d6f424216bac26df89628 Mon Sep 17 00:00:00 2001 From: jneilliii Date: Sat, 10 Dec 2022 23:52:50 -0500 Subject: [PATCH] potential fix for switching endpoint --- .../websocket/simplyprint.py | 19 +++++++++---------- setup.py | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/octoprint_simplyprint/websocket/simplyprint.py b/octoprint_simplyprint/websocket/simplyprint.py index 065ac6f..e21aacc 100644 --- a/octoprint_simplyprint/websocket/simplyprint.py +++ b/octoprint_simplyprint/websocket/simplyprint.py @@ -658,23 +658,22 @@ def _on_uninstall_finished(uninstall_success: asyncio.Future): None, self.sys_manager.restart_octoprint ) elif demand == "goto_ws_prod": - self.test = False - self._set_ws_url() - self._save_item("endpoint", "production") - self.close() - self._connect() + self._loop.add_callback(self._switch_ws_connection, "production") elif demand == "goto_ws_test": - self.test = True - self._set_ws_url() - self._save_item("endpoint", "test") - self.close() - self._connect() + self._loop.add_callback(self._switch_ws_connection, "test") elif demand == "send_logs": if "token" in args: self._loop.run_in_executor(None, self._send_requested_logs, args.get("token"), args.get("logs", []), args.get("max_body")) else: self._logger.debug(f"Unknown demand: {demand}") + def _switch_ws_connection(self, endpoint: str) -> None: + self._logger.debug(f"Switching to {endpoint} endpoint.") + self.test = (endpoint == "test") + self._set_ws_url() + self._save_item("endpoint", endpoint) + self.ws.close(1000, "Switching endpoint") + def _send_requested_logs(self, token: str, logs: list[str], max_size: int) -> None: url = LOGS_UPLOAD_URL + self.settings.get(["printer_id"]) data = {"token": token} diff --git a/setup.py b/setup.py index c342ff8..9c1327f 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module # Remember to bump the version in octoprint_simplyprint/__init__.py as well -plugin_version = "4.0.5dev1" +plugin_version = "4.0.5dev2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module