Merge pull request #6461 from Ultimaker/CS-347_auto_switch_to_cloud

Fix cloud connection auto fallback
This commit is contained in:
Ian Paschal 2019-10-02 11:45:58 +02:00 committed by GitHub
commit 2d03bc6bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 15 deletions

View File

@ -124,11 +124,11 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice):
def matchesNetworkKey(self, network_key: str) -> bool: def matchesNetworkKey(self, network_key: str) -> bool:
# Typically, a network key looks like "ultimakersystem-aabbccdd0011._ultimaker._tcp.local." # Typically, a network key looks like "ultimakersystem-aabbccdd0011._ultimaker._tcp.local."
# the host name should then be "ultimakersystem-aabbccdd0011" # the host name should then be "ultimakersystem-aabbccdd0011"
if network_key.startswith(self.clusterData.host_name): if network_key.startswith(str(self.clusterData.host_name or "")):
return True return True
# However, for manually added printers, the local IP address is used in lieu of a proper # However, for manually added printers, the local IP address is used in lieu of a proper
# network key, so check for that as well # network key, so check for that as well. It is in the format "manual:10.1.10.1".
if self.clusterData.host_internal_ip is not None and network_key in self.clusterData.host_internal_ip: if network_key.endswith(str(self.clusterData.host_internal_ip or "")):
return True return True
return False return False

View File

@ -9,6 +9,7 @@ from UM.Logger import Logger # To log errors talking to the API.
from UM.Signal import Signal from UM.Signal import Signal
from cura.API import Account from cura.API import Account
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from cura.Settings.CuraStackBuilder import CuraStackBuilder
from cura.Settings.GlobalStack import GlobalStack from cura.Settings.GlobalStack import GlobalStack
from .CloudApiClient import CloudApiClient from .CloudApiClient import CloudApiClient
@ -140,14 +141,15 @@ class CloudOutputDeviceManager:
if not device: if not device:
return return
# The newly added machine is automatically activated. # Create a new machine and activate it.
machine_manager = CuraApplication.getInstance().getMachineManager() # We do not use use MachineManager.addMachine here because we need to set the cluster ID before activating it.
machine_manager.addMachine(device.printerType, device.clusterData.friendly_name) new_machine = CuraStackBuilder.createMachine(device.name, device.printerType)
active_machine = CuraApplication.getInstance().getGlobalContainerStack() if not new_machine:
if not active_machine: Logger.log("e", "Failed creating a new machine")
return return
active_machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key) new_machine.setMetaDataEntry(self.META_CLUSTER_ID, device.key)
self._connectToOutputDevice(device, active_machine) 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. ## Callback for when the active machine was changed by the user or a new remote cluster was found.
def _connectToActiveMachine(self) -> None: def _connectToActiveMachine(self) -> None:

View File

@ -9,6 +9,7 @@ from UM.Signal import Signal
from UM.Version import Version from UM.Version import Version
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from cura.Settings.CuraStackBuilder import CuraStackBuilder
from cura.Settings.GlobalStack import GlobalStack from cura.Settings.GlobalStack import GlobalStack
from .ZeroConfClient import ZeroConfClient from .ZeroConfClient import ZeroConfClient
@ -203,12 +204,16 @@ class LocalClusterOutputDeviceManager:
if device is None: if device is None:
return return
# The newly added machine is automatically activated. # Create a new machine and activate it.
CuraApplication.getInstance().getMachineManager().addMachine(device.printerType, device.name) # We do not use use MachineManager.addMachine here because we need to set the network key before activating it.
active_machine = CuraApplication.getInstance().getGlobalContainerStack() # If we do not do this the auto-pairing with the cloud-equivalent device will not work.
if not active_machine: new_machine = CuraStackBuilder.createMachine(device.name, device.printerType)
if not new_machine:
Logger.log("e", "Failed creating a new machine")
return return
self._connectToOutputDevice(device, active_machine) new_machine.setMetaDataEntry(self.META_NETWORK_KEY, device.key)
CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId())
self._connectToOutputDevice(device, new_machine)
self._showCloudFlowMessage(device) self._showCloudFlowMessage(device)
## Add an address to the stored preferences. ## Add an address to the stored preferences.