mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -06:00
Describe TODO for association by hostname, only connect when online
This commit is contained in:
parent
c40d76f9ee
commit
b50e942768
2 changed files with 20 additions and 20 deletions
|
@ -20,8 +20,6 @@ from .Models import CloudCluster
|
||||||
#
|
#
|
||||||
# API spec is available on https://api.ultimaker.com/docs/connect/spec/.
|
# API spec is available on https://api.ultimaker.com/docs/connect/spec/.
|
||||||
#
|
#
|
||||||
# TODO: figure out how to pair remote clusters, local networked clusters and local cura printer presets.
|
|
||||||
# TODO: for now we just have multiple output devices if the cluster is available both locally and remote.
|
|
||||||
class CloudOutputDeviceManager(NetworkClient):
|
class CloudOutputDeviceManager(NetworkClient):
|
||||||
|
|
||||||
# The cloud URL to use for remote clusters.
|
# The cloud URL to use for remote clusters.
|
||||||
|
@ -42,8 +40,9 @@ class CloudOutputDeviceManager(NetworkClient):
|
||||||
self._account.loginStateChanged.connect(self._getRemoteClusters)
|
self._account.loginStateChanged.connect(self._getRemoteClusters)
|
||||||
|
|
||||||
# When switching machines we check if we have to activate a remote cluster.
|
# When switching machines we check if we have to activate a remote cluster.
|
||||||
application.globalContainerStackChanged.connect(self._activeMachineChanged)
|
application.globalContainerStackChanged.connect(self._connectToActiveMachine)
|
||||||
|
|
||||||
|
# TODO: fix this
|
||||||
# Periodically check all remote clusters for the authenticated user.
|
# Periodically check all remote clusters for the authenticated user.
|
||||||
# self._update_clusters_thread = Thread(target=self._updateClusters, daemon=True)
|
# self._update_clusters_thread = Thread(target=self._updateClusters, daemon=True)
|
||||||
# self._update_clusters_thread.start()
|
# self._update_clusters_thread.start()
|
||||||
|
@ -89,15 +88,13 @@ class CloudOutputDeviceManager(NetworkClient):
|
||||||
|
|
||||||
# Add an output device for each new remote cluster.
|
# Add an output device for each new remote cluster.
|
||||||
for cluster_id in found_cluster_ids.difference(known_cluster_ids):
|
for cluster_id in found_cluster_ids.difference(known_cluster_ids):
|
||||||
self._addCloudOutputDevice(found_clusters[cluster_id])
|
if found_clusters[cluster_id].is_online:
|
||||||
|
self._addCloudOutputDevice(found_clusters[cluster_id])
|
||||||
|
|
||||||
# Remove output devices that are gone
|
# Remove output devices that are gone
|
||||||
for cluster_id in known_cluster_ids.difference(found_cluster_ids):
|
for cluster_id in known_cluster_ids.difference(found_cluster_ids):
|
||||||
self._removeCloudOutputDevice(found_clusters[cluster_id])
|
self._removeCloudOutputDevice(found_clusters[cluster_id])
|
||||||
|
|
||||||
# For testing we add a dummy device:
|
|
||||||
# self._addCloudOutputDevice(CloudCluster(cluster_id = "LJ0tciiuZZjarrXAvFLEZ6ox4Cvx8FvtXUlQv4vIhV6w"))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parseStatusResponse(reply: QNetworkReply) -> Dict[str, CloudCluster]:
|
def _parseStatusResponse(reply: QNetworkReply) -> Dict[str, CloudCluster]:
|
||||||
try:
|
try:
|
||||||
|
@ -116,7 +113,9 @@ class CloudOutputDeviceManager(NetworkClient):
|
||||||
device = CloudOutputDevice(cluster.cluster_id)
|
device = CloudOutputDevice(cluster.cluster_id)
|
||||||
self._output_device_manager.addOutputDevice(device)
|
self._output_device_manager.addOutputDevice(device)
|
||||||
self._remote_clusters[cluster.cluster_id] = device
|
self._remote_clusters[cluster.cluster_id] = device
|
||||||
device.connect() # TODO: Only connect the current device
|
if cluster.is_online:
|
||||||
|
# We found a new online cluster, we might need to connect to it.
|
||||||
|
self._connectToActiveMachine()
|
||||||
|
|
||||||
## Remove a CloudOutputDevice
|
## Remove a CloudOutputDevice
|
||||||
def _removeCloudOutputDevice(self, cluster: CloudCluster):
|
def _removeCloudOutputDevice(self, cluster: CloudCluster):
|
||||||
|
@ -124,20 +123,20 @@ class CloudOutputDeviceManager(NetworkClient):
|
||||||
del self._remote_clusters[cluster.cluster_id]
|
del self._remote_clusters[cluster.cluster_id]
|
||||||
|
|
||||||
## Callback for when the active machine was changed by the user.
|
## Callback for when the active machine was changed by the user.
|
||||||
def _activeMachineChanged(self):
|
def _connectToActiveMachine(self) -> None:
|
||||||
active_machine = CuraApplication.getInstance().getGlobalContainerStack()
|
active_machine = CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
if not active_machine:
|
if not active_machine:
|
||||||
return
|
return
|
||||||
|
|
||||||
local_device_id = active_machine.getMetaDataEntry("um_network_key")
|
# Check if the stored cluster_id for the active machine is in our list of remote clusters.
|
||||||
if local_device_id:
|
|
||||||
active_output_device = self._output_device_manager.getActiveDevice()
|
|
||||||
# TODO: We must find a match for the active machine and a cloud device
|
|
||||||
|
|
||||||
stored_cluster_id = active_machine.getMetaDataEntry("um_cloud_cluster_id")
|
stored_cluster_id = active_machine.getMetaDataEntry("um_cloud_cluster_id")
|
||||||
if stored_cluster_id not in self._remote_clusters.keys():
|
if stored_cluster_id in self._remote_clusters.keys():
|
||||||
# Currently authenticated user does not have access to stored cluster or no user is signed in.
|
self._remote_clusters.get(stored_cluster_id).connect()
|
||||||
return
|
return
|
||||||
|
|
||||||
# We found the active machine as remote cluster so let's connect to it.
|
# TODO: See if this cloud cluster still has to be associated to the active machine.
|
||||||
self._remote_clusters.get(stored_cluster_id).connect()
|
# TODO: We have to get a common piece of data, like local network hostname, from the active machine and
|
||||||
|
# TODO: cloud cluster and then set the "um_cloud_cluster_id" meta data key on the active machine.
|
||||||
|
# TODO: If so, we can also immediate connect to it.
|
||||||
|
# active_machine.setMetaDataEntry("um_cloud_cluster_id", "")
|
||||||
|
# self._remote_clusters.get(stored_cluster_id).connect()
|
||||||
|
|
|
@ -13,6 +13,7 @@ class CloudCluster(BaseModel):
|
||||||
self.host_name = None # type: str
|
self.host_name = None # type: str
|
||||||
self.host_version = None # type: str
|
self.host_version = None # type: str
|
||||||
self.status = None # type: str
|
self.status = None # type: str
|
||||||
|
self.is_online = None # type: bool
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue