From 70c679859a9657f0488665324ea0dfef9a66bba1 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Tue, 14 May 2019 20:56:28 +0200 Subject: [PATCH] Use default value for printer type, allow printer_type field from cloud --- plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py | 5 +++-- .../src/Cloud/CloudOutputDeviceManager.py | 4 ++-- .../src/Cloud/Models/CloudClusterResponse.py | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 4f89513e1e..6a2186a87a 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -79,6 +79,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): 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": cluster.printer_type.encode() if cluster.printer_type else b"", b"cluster_size": b"1" # cloud devices are always clusters of at least one } @@ -104,7 +105,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 = "" + self._host_machine_type = cluster.printer_type # type: str # Properties to populate later on with received cloud data. self._print_jobs = [] # type: List[UM3PrintJobOutputModel] @@ -375,7 +376,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): ## 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: + if 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 diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 498e141b73..ced53e347b 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -96,7 +96,7 @@ class CloudOutputDeviceManager: device = CloudOutputDevice(self._api, cluster) self._remote_clusters[cluster.cluster_id] = device self._application.getDiscoveredPrintersModel().addDiscoveredPrinter( - cluster.cluster_id, + device.key, device.key, cluster.friendly_name, self._createMachineFromDiscoveredPrinter, @@ -109,7 +109,7 @@ class CloudOutputDeviceManager: for device, cluster in updates: device.clusterData = cluster self._application.getDiscoveredPrintersModel().updateDiscoveredPrinter( - cluster.cluster_id, + device.key, cluster.friendly_name, device.printerType, ) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/Models/CloudClusterResponse.py b/plugins/UM3NetworkPrinting/src/Cloud/Models/CloudClusterResponse.py index 5549da02aa..a5b4dfdf40 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/Models/CloudClusterResponse.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/Models/CloudClusterResponse.py @@ -15,9 +15,12 @@ class CloudClusterResponse(BaseCloudModel): # \param is_online: Whether this cluster is currently connected to the cloud. # \param status: The status of the cluster authentication (active or inactive). # \param host_version: The firmware version of the cluster host. This is where the Stardust client is running on. + # \param host_internal_ip: The internal IP address of the host printer. + # \param friendly_name: The human readable name of the host printer. + # \param printer_type: The machine type of the host printer. def __init__(self, cluster_id: str, host_guid: str, host_name: str, is_online: bool, status: str, host_internal_ip: Optional[str] = None, host_version: Optional[str] = None, - friendly_name: Optional[str] = None, **kwargs) -> None: + friendly_name: Optional[str] = None, printer_type: Optional[str] = "Ultimaker 3", **kwargs) -> None: self.cluster_id = cluster_id self.host_guid = host_guid self.host_name = host_name @@ -26,6 +29,7 @@ class CloudClusterResponse(BaseCloudModel): self.host_version = host_version self.host_internal_ip = host_internal_ip self.friendly_name = friendly_name + self.printer_type = printer_type super().__init__(**kwargs) # Validates the model, raising an exception if the model is invalid.