From d98f7a2dcb8186c0e84f22e617d8eca17349d9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 1 Jun 2021 17:48:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20display=20of=20last=20conn?= =?UTF-8?q?ection=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comm/protocol/reprap/__init__.py | 2 +- src/octoprint/printer/standard.py | 82 +++++++++---------- .../static/js/app/viewmodels/connection.js | 5 +- 3 files changed, 42 insertions(+), 47 deletions(-) diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 685fb4dbd..e632b6c20 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -1876,7 +1876,7 @@ class ReprapGcodeProtocol( self._resend_ok_timer and line and not getattr(self.flavor, "comm_ok", lambda *a, **kwa: True)( - line, lower_line, self._state, self._protected_flags + line, lower_line, self._state ) ): # we got anything but an ok after a resend request - this means the ok after the resend request diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 0fcbe07be..bf2dc3a3c 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -114,6 +114,8 @@ class Printer( self._connection_profile_manager = connectionProfileManager self._printer_profile_manager = printerProfileManager + self._last_connection = {} + # state self._latest_temperatures = None self._temperature_history = TemperatureHistory( @@ -426,6 +428,12 @@ class Printer( "connection.log is currently not enabled, you can enable it via Settings > Connection > Log communication to connection.log" ) + injections = { + "settings": settings(), + "plugin_manager": plugin_manager(), + "event_bus": eventManager(), + } + connection_id = kwargs.get("connection") connection = None if connection_id is not None: @@ -438,7 +446,6 @@ class Printer( ##~~ Printer profile profile_id = kwargs.get("profile", connection.printer_profile) self._printer_profile_manager.select(profile_id) - profile = self._printer_profile_manager.get_current_or_default() ##~~ Transport @@ -449,14 +456,6 @@ class Printer( ) transport_kwargs = {} - transport_kwargs.update( - { - "settings": settings(), - "plugin_manager": plugin_manager(), - "event_bus": eventManager(), - "printer_profile": profile, - } - ) ##~~ Protocol @@ -464,14 +463,6 @@ class Printer( protocol_kwargs = dict_merge( connection.protocol_parameters, kwargs.get("protocol_options", {}) ) - protocol_kwargs.update( - { - "settings": settings(), - "plugin_manager": plugin_manager(), - "event_bus": eventManager(), - "printer_profile": profile, - } - ) else: self._connection_profile_manager.deselect() @@ -483,7 +474,6 @@ class Printer( profile_id = self._printer_profile_manager.get_default()["id"] self._printer_profile_manager.select(profile_id) - profile = self._printer_profile_manager.get_current_or_default() ##~~ Transport @@ -504,15 +494,6 @@ class Printer( transport_kwargs = kwargs.get("transport_kwargs", {}) transport_connect_kwargs = kwargs.get("transport_options", {}) - transport_kwargs.update( - { - "settings": settings(), - "plugin_manager": plugin_manager(), - "event_bus": eventManager(), - "printer_profile": profile, - } - ) - ##~~ Protocol # TODO make this depend on the printer profile @@ -523,14 +504,7 @@ class Printer( else: protocol_kwargs = kwargs.get("protocol_options", {}) - protocol_kwargs.update( - { - "settings": settings(), - "plugin_manager": plugin_manager(), - "event_bus": eventManager(), - "printer_profile": profile, - } - ) + profile = self._printer_profile_manager.get_current_or_default() ##~~ Lookup and create transport instances @@ -540,7 +514,12 @@ class Printer( if not transport_class: raise ValueError(f"Invalid transport: {selected_transport}") - transport = transport_class(**transport_kwargs) + final_transport_kwargs = { + **transport_kwargs, + **injections, + **{"printer_profile": profile}, + } + transport = transport_class(**final_transport_kwargs) self._transport = transport ##~~ Lookup and create protocol instance @@ -551,7 +530,12 @@ class Printer( if not protocol_class: raise ValueError(f"Invalid protocol: {selected_protocol}") - protocol = protocol_class(**protocol_kwargs) + final_protocol_kwargs = { + **protocol_kwargs, + **injections, + **{"printer_profile": profile}, + } + protocol = protocol_class(**final_protocol_kwargs) self._protocol = protocol ##~~ Register everything and connect @@ -559,6 +543,16 @@ class Printer( self._protocol.register_listener(self) self._protocol.connect(self._transport, transport_kwargs=transport_connect_kwargs) + ##~~ Remember last connection + self._last_connection = { + "connection": connection_id, + "protocol": selected_protocol, + "protocol_args": protocol_kwargs, + "transport": selected_transport, + "transport_args": transport_kwargs, + "printer_profile": profile_id, + } + def disconnect(self, *args, **kwargs): """ Closes the connection to the printer. @@ -1042,13 +1036,13 @@ class Printer( def get_current_connection_parameters(self, *args, **kwargs): if self._transport is None or self._protocol is None: return { - "state": "Closed", - "connection": None, - "protocol": None, - "protocol_args": {}, - "transport": None, - "transport_args": {}, - "printer_profile": None, + "state": "Offline", + "connection": self._last_connection.get("connection"), + "protocol": self._last_connection.get("protocol"), + "protocol_args": self._last_connection.get("protocol_args", {}), + "transport": self._last_connection.get("transport"), + "transport_args": self._last_connection.get("transport_args", {}), + "printer_profile": self._last_connection.get("printer_profile"), } printer_profile = self._printer_profile_manager.get_current_or_default() diff --git a/src/octoprint/static/js/app/viewmodels/connection.js b/src/octoprint/static/js/app/viewmodels/connection.js index c835d0a30..0f4bbd9c6 100644 --- a/src/octoprint/static/js/app/viewmodels/connection.js +++ b/src/octoprint/static/js/app/viewmodels/connection.js @@ -85,7 +85,6 @@ $(function () { option, override ? override[option.name] : undefined ); - // TODO is this call to extendOption correct wrt to the override? _.each(option.group.params, function (p) { extendOption( p, @@ -620,7 +619,9 @@ $(function () { }; self._sanitize = function (name) { - return name.replace(/[^a-zA-Z0-9\-_.() ]/g, "").replace(/ /g, "_"); + return name !== undefined + ? name.replace(/[^a-zA-Z0-9\-_.() ]/g, "").replace(/ /g, "_") + : undefined; }; }