From c3d846440d6bf9c3ef1b0eba33d74bc797bdff4c Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Tue, 1 Oct 2019 19:31:35 +0200 Subject: [PATCH] Set some meta data before switching active stacks, fix manual added device pairing --- .../src/Cloud/CloudOutputDevice.py | 4 ++-- .../src/Cloud/CloudOutputDeviceManager.py | 15 +++++++-------- .../Network/LocalClusterOutputDeviceManager.py | 14 ++++++++------ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 75e2b30ff1..bfe5a5728a 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -127,8 +127,8 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): if network_key.startswith(self.clusterData.host_name): return True # However, for manually added printers, the local IP address is used in lieu of a proper - # network key, so check for that as well - if self.clusterData.host_internal_ip is not None and network_key in self.clusterData.host_internal_ip: + # network key, so check for that as well. It is in the format "manual:10.1.10.1". + if network_key.endswith(self.clusterData.host_internal_ip): return True return False diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 8d35b41fa2..fcf29c018a 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -9,6 +9,7 @@ from UM.Logger import Logger # To log errors talking to the API. from UM.Signal import Signal from cura.API import Account from cura.CuraApplication import CuraApplication +from cura.Settings.CuraStackBuilder import CuraStackBuilder from cura.Settings.GlobalStack import GlobalStack from .CloudApiClient import CloudApiClient @@ -140,14 +141,12 @@ class CloudOutputDeviceManager: if not device: return - # The newly added machine is automatically activated. - machine_manager = CuraApplication.getInstance().getMachineManager() - machine_manager.addMachine(device.printerType, device.clusterData.friendly_name) - active_machine = CuraApplication.getInstance().getGlobalContainerStack() - if not active_machine: - return - active_machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key) - self._connectToOutputDevice(device, active_machine) + # Create a new machine and activate it. + # We do not use use MachineManager.addMachine here because we need to set the cluster ID before activating it. + new_machine = CuraStackBuilder.createMachine(device.name, device.printerType) + new_machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key) + CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId()) + self._connectToOutputDevice(device, new_machine) ## Callback for when the active machine was changed by the user or a new remote cluster was found. def _connectToActiveMachine(self) -> None: diff --git a/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py index 557de4ec80..c4c4779a3c 100644 --- a/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Network/LocalClusterOutputDeviceManager.py @@ -9,6 +9,7 @@ from UM.Signal import Signal from UM.Version import Version from cura.CuraApplication import CuraApplication +from cura.Settings.CuraStackBuilder import CuraStackBuilder from cura.Settings.GlobalStack import GlobalStack from .ZeroConfClient import ZeroConfClient @@ -203,12 +204,13 @@ class LocalClusterOutputDeviceManager: if device is None: return - # The newly added machine is automatically activated. - CuraApplication.getInstance().getMachineManager().addMachine(device.printerType, device.name) - active_machine = CuraApplication.getInstance().getGlobalContainerStack() - if not active_machine: - return - self._connectToOutputDevice(device, active_machine) + # Create a new machine and activate it. + # We do not use use MachineManager.addMachine here because we need to set the network key before activating it. + # If we do not do this the auto-pairing with the cloud-equivalent device will not work. + new_machine = CuraStackBuilder.createMachine(device.name, device.printerType) + new_machine.setMetaDataEntry(self.META_NETWORK_KEY, device.key) + CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId()) + self._connectToOutputDevice(device, new_machine) self._showCloudFlowMessage(device) ## Add an address to the stored preferences.