Fix case where both a "normal" and an "abstract" ouput device could be active

CURA-8463
This commit is contained in:
Jaime van Kessel 2022-08-31 10:27:52 +02:00
parent dd5981d85e
commit 5ff07b00d0
No known key found for this signature in database
GPG key ID: C85F7A3AF1BAA7C4

View file

@ -64,7 +64,6 @@ class CloudOutputDeviceManager:
self._running = False self._running = False
self._syncing = False self._syncing = False
CuraApplication.getInstance().getContainerRegistry().containerRemoved.connect(self._printerRemoved) CuraApplication.getInstance().getContainerRegistry().containerRemoved.connect(self._printerRemoved)
def start(self): def start(self):
@ -375,7 +374,6 @@ class CloudOutputDeviceManager:
def _connectToActiveMachine(self) -> None: def _connectToActiveMachine(self) -> None:
"""Callback for when the active machine was changed by the user""" """Callback for when the active machine was changed by the user"""
active_machine = CuraApplication.getInstance().getGlobalContainerStack() active_machine = CuraApplication.getInstance().getGlobalContainerStack()
if not active_machine: if not active_machine:
return return
@ -383,29 +381,29 @@ class CloudOutputDeviceManager:
# Check if we should directly connect with a "normal" CloudOutputDevice or that we should connect to an # Check if we should directly connect with a "normal" CloudOutputDevice or that we should connect to an
# 'abstract' one # 'abstract' one
output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() output_device_manager = CuraApplication.getInstance().getOutputDeviceManager()
if active_machine.getMetaDataEntry("is_abstract_machine") != "True": stored_cluster_id = active_machine.getMetaDataEntry(self.META_CLUSTER_ID)
stored_cluster_id = active_machine.getMetaDataEntry(self.META_CLUSTER_ID) local_network_key = active_machine.getMetaDataEntry(self.META_NETWORK_KEY)
local_network_key = active_machine.getMetaDataEntry(self.META_NETWORK_KEY)
# Copy of the device list, to prevent modifying the list while iterating, if a device gets added asynchronously. # Copy of the device list, to prevent modifying the list while iterating, if a device gets added asynchronously.
remote_cluster_copy: List[CloudOutputDevice] = list(self._remote_clusters.values()) remote_cluster_copy: List[CloudOutputDevice] = list(self._remote_clusters.values())
for device in remote_cluster_copy: for device in remote_cluster_copy:
if device.key == stored_cluster_id: if device.key == stored_cluster_id:
# Connect to it if the stored ID matches. # Connect to it if the stored ID matches.
self._connectToOutputDevice(device, active_machine) self._connectToOutputDevice(device, active_machine)
elif local_network_key and device.matchesNetworkKey(local_network_key): elif local_network_key and device.matchesNetworkKey(local_network_key):
# Connect to it if we can match the local network key that was already present. # Connect to it if we can match the local network key that was already present.
self._connectToOutputDevice(device, active_machine) self._connectToOutputDevice(device, active_machine)
elif device.key in output_device_manager.getOutputDeviceIds(): elif device.key in output_device_manager.getOutputDeviceIds():
# Remove device if it is not meant for the active machine. # Remove device if it is not meant for the active machine.
output_device_manager.removeOutputDevice(device.key) output_device_manager.removeOutputDevice(device.key)
else: # Abstract it is!
remote_abstract_cluster_copy: List[CloudOutputDevice] = list(self._abstract_clusters.values()) # Update state of all abstract output devices
for device in remote_abstract_cluster_copy: remote_abstract_cluster_copy: List[CloudOutputDevice] = list(self._abstract_clusters.values())
if device.printerType == active_machine.definition.getId(): for device in remote_abstract_cluster_copy:
self._connectToAbstractOutputDevice(device, active_machine) if device.printerType == active_machine.definition.getId() and parseBool(active_machine.getMetaDataEntry("is_abstract_machine", False)):
elif device.key in output_device_manager.getOutputDeviceIds(): self._connectToAbstractOutputDevice(device, active_machine)
output_device_manager.removeOutputDevice(device.key) elif device.key in output_device_manager.getOutputDeviceIds():
output_device_manager.removeOutputDevice(device.key)
def _setOutputDeviceMetadata(self, device: CloudOutputDevice, machine: GlobalStack): def _setOutputDeviceMetadata(self, device: CloudOutputDevice, machine: GlobalStack):
machine.setName(device.name) machine.setName(device.name)