From 10fab716d59c7734a4f9799cffb66751e4a86b28 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Fri, 29 Sep 2017 13:14:14 +0200 Subject: [PATCH 1/2] CL-460 do not downgrade Cura Connect printer to legacy --- .../NetworkClusterPrinterOutputDevice.py | 2 +- .../UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/NetworkClusterPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkClusterPrinterOutputDevice.py index 55f9d1247b..d5248c7ad4 100644 --- a/plugins/UM3NetworkPrinting/NetworkClusterPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkClusterPrinterOutputDevice.py @@ -144,7 +144,7 @@ class NetworkClusterPrinterOutputDevice(NetworkPrinterOutputDevice.NetworkPrinte name = self._selected_printer.get("friendly_name") if name != self._automatic_printer.get("friendly_name"): return name - # Return name of cluster master. + # Return name of cluster master. return self._properties.get(b"name", b"").decode("utf-8") def connect(self): diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py index 39e5faf938..7b2aae894e 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py @@ -31,6 +31,7 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin): self._zero_conf = None self._browser = None self._printers = {} + self._printers_seen = {} # do not forget a printer when we have seen one, also do not 'downgrade' to legacy printer from Connect self._api_version = "1" self._api_prefix = "/api/v" + self._api_version + "/" @@ -218,12 +219,16 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin): ## Because the model needs to be created in the same thread as the QMLEngine, we use a signal. def addPrinter(self, name, address, properties, force_cluster=False): cluster_size = int(properties.get(b"cluster_size", -1)) - if force_cluster or cluster_size >= 0: + was_cluster_before = isinstance(self._printers_seen.get(name, None), NetworkClusterPrinterOutputDevice.NetworkClusterPrinterOutputDevice) + if was_cluster_before: + Logger.log("d", "Printer [%s] had Cura Connect before, so assume it's still equipped with Cura Connect.", name) + if force_cluster or cluster_size >= 0 or was_cluster_before: printer = NetworkClusterPrinterOutputDevice.NetworkClusterPrinterOutputDevice( name, address, properties, self._api_prefix, self._plugin_path) else: printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties, self._api_prefix) self._printers[printer.getKey()] = printer + self._printers_seen[printer.getKey()] = printer # Printers that are temporary unreachable or is rebooted are stored here global_container_stack = Application.getInstance().getGlobalContainerStack() if global_container_stack and printer.getKey() == global_container_stack.getMetaDataEntry("um_network_key"): if printer.getKey() not in self._old_printers: # Was the printer already connected, but a re-scan forced? From 67d730c8516a3fac3607f9145a0115dc31d1a89a Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Fri, 29 Sep 2017 13:58:14 +0200 Subject: [PATCH 2/2] CL-460 use name instead of object to cluster_printers_seen --- .../UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py index 7b2aae894e..baca433b16 100644 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py @@ -31,7 +31,7 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin): self._zero_conf = None self._browser = None self._printers = {} - self._printers_seen = {} # do not forget a printer when we have seen one, also do not 'downgrade' to legacy printer from Connect + self._cluster_printers_seen = {} # do not forget a cluster printer when we have seen one, to not 'downgrade' from Connect to legacy printer self._api_version = "1" self._api_prefix = "/api/v" + self._api_version + "/" @@ -219,7 +219,7 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin): ## Because the model needs to be created in the same thread as the QMLEngine, we use a signal. def addPrinter(self, name, address, properties, force_cluster=False): cluster_size = int(properties.get(b"cluster_size", -1)) - was_cluster_before = isinstance(self._printers_seen.get(name, None), NetworkClusterPrinterOutputDevice.NetworkClusterPrinterOutputDevice) + was_cluster_before = name in self._cluster_printers_seen if was_cluster_before: Logger.log("d", "Printer [%s] had Cura Connect before, so assume it's still equipped with Cura Connect.", name) if force_cluster or cluster_size >= 0 or was_cluster_before: @@ -228,7 +228,7 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin): else: printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties, self._api_prefix) self._printers[printer.getKey()] = printer - self._printers_seen[printer.getKey()] = printer # Printers that are temporary unreachable or is rebooted are stored here + self._cluster_printers_seen[printer.getKey()] = name # Cluster printers that may be temporary unreachable or is rebooted keep being stored here global_container_stack = Application.getInstance().getGlobalContainerStack() if global_container_stack and printer.getKey() == global_container_stack.getMetaDataEntry("um_network_key"): if printer.getKey() not in self._old_printers: # Was the printer already connected, but a re-scan forced?