Add minimal support for discovering cloud printers outside of LAN

This commit is contained in:
ChrisTerBeke 2019-04-18 00:19:12 +02:00
parent b5d4ef61f5
commit 3cbd8a94a9
No known key found for this signature in database
GPG key ID: A49F1AB9D7E0C263
3 changed files with 79 additions and 20 deletions

View file

@ -58,6 +58,14 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
# Therefore we create a private signal used to trigger the printersChanged signal.
_clusterPrintersChanged = pyqtSignal()
# Map of Cura Connect machine_variant field to Cura machine types.
# Needed for printer discovery stack creation.
_host_machine_variant_to_machine_type_map = {
"Ultimaker 3": "ultimaker3",
"Ultimaker 3 Extended": "ultimaker3_extended",
"Ultimaker S5": "ultimaker_s5"
}
## Creates a new cloud output device
# \param api_client: The client that will run the API calls
# \param cluster: The device response received from the cloud API.
@ -68,10 +76,10 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
# Because the cloud connection does not off all of these, we manually construct this version here.
# An example of why this is needed is the selection of the compatible file type when exporting the tool path.
properties = {
b"address": b"",
b"name": cluster.host_name.encode() if cluster.host_name else b"",
b"address": cluster.host_internal_ip.encode() if cluster.host_internal_ip else b"",
b"name": cluster.friendly_name.encode() if cluster.friendly_name else b"",
b"firmware_version": cluster.host_version.encode() if cluster.host_version else b"",
b"printer_type": b""
b"cluster_size": 1 # cloud devices are always clusters of at least one
}
super().__init__(device_id = cluster.cluster_id, address = "",
@ -95,6 +103,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
# We keep track of which printer is visible in the monitor page.
self._active_printer = None # type: Optional[PrinterOutputModel]
self._host_machine_type = ""
# Properties to populate later on with received cloud data.
self._print_jobs = [] # type: List[UM3PrintJobOutputModel]
@ -234,6 +243,9 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
def _updatePrinters(self, printers: List[CloudClusterPrinterStatus]) -> None:
previous = {p.key: p for p in self._printers} # type: Dict[str, PrinterOutputModel]
received = {p.uuid: p for p in printers} # type: Dict[str, CloudClusterPrinterStatus]
# We need the machine type of the host (1st list entry) to allow discovery to work.
self._host_machine_type = printers[0].machine_variant
removed_printers, added_printers, updated_printers = findChanges(previous, received)
@ -358,6 +370,19 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
).show()
self.writeFinished.emit()
## Gets the printer type of the cluster host. Falls back to the printer type in the device properties.
@pyqtProperty(str, notify=_clusterPrintersChanged)
def printerType(self) -> str:
if self._printers and self._host_machine_type in self._host_machine_variant_to_machine_type_map:
return self._host_machine_variant_to_machine_type_map[self._host_machine_type]
return super().printerType
## Gets the number of printers in the cluster.
# We use a minimum of 1 because cloud devices are always a cluster and printer discovery needs it.
@pyqtProperty(int, notify = _clusterPrintersChanged)
def clusterSize(self) -> int:
return max(1, len(self._printers))
## Gets the remote printers.
@pyqtProperty("QVariantList", notify=_clusterPrintersChanged)
def printers(self) -> List[PrinterOutputModel]:
@ -375,10 +400,6 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
self._active_printer = printer
self.activePrinterChanged.emit()
@pyqtProperty(int, notify = _clusterPrintersChanged)
def clusterSize(self) -> int:
return len(self._printers)
## Get remote print jobs.
@pyqtProperty("QVariantList", notify = printJobsChanged)
def printJobs(self) -> List[UM3PrintJobOutputModel]: