Fix typing issues

This commit is contained in:
ChrisTerBeke 2019-08-28 23:27:30 +02:00
parent 7b45100dd0
commit 13e85362b0
2 changed files with 6 additions and 4 deletions

View file

@ -14,7 +14,7 @@ class ClusterPrinterMaterialStation(BaseModel):
# \param: supported: Whether the material station is supported on this machine or not.
# \param material_slots: The active slots configurations of this material station.
def __init__(self, status: str, supported: bool = False,
material_slots: List[Union[None, Dict[str, Any], ClusterPrinterMaterialStationSlot]] = None,
material_slots: List[Union[ClusterPrinterMaterialStationSlot, Dict[str, Any]]] = None,
**kwargs) -> None:
self.status = status
self.supported = supported

View file

@ -81,9 +81,9 @@ class ClusterPrinterStatus(BaseModel):
model.setCameraUrl(QUrl("http://{}:8080/?action=stream".format(self.ip_address)))
# Set the possible configurations based on whether a Material Station is present or not.
if self.material_station is not None and len(self.material_station.material_slots):
if self.material_station and self.material_station.material_slots:
self._updateAvailableConfigurations(model)
if self.configuration is not None:
if self.configuration:
self._updateActiveConfiguration(model)
def _updateActiveConfiguration(self, model: PrinterOutputModel) -> None:
@ -103,6 +103,8 @@ class ClusterPrinterStatus(BaseModel):
## Create a list of Material Station slots for the given extruder index.
# Returns a list with a single empty material slot if none are found to ensure we don't miss configurations.
def _getSlotsForExtruder(self, extruder_index: int) -> List[ClusterPrinterMaterialStationSlot]:
if not self.material_station: # typing guard
return []
slots = [slot for slot in self.material_station.material_slots if self._isSupportedConfiguration(
slot = slot,
extruder_index = extruder_index
@ -113,7 +115,7 @@ class ClusterPrinterStatus(BaseModel):
# We filter out any slot that is not supported by the extruder index, print core type or if the material is empty.
@staticmethod
def _isSupportedConfiguration(slot: ClusterPrinterMaterialStationSlot, extruder_index: int) -> bool:
return slot.extruder_index == extruder_index and slot.compatible and slot.material
return slot.extruder_index == extruder_index and slot.compatible
## Create an empty material slot with a fake empty material.
@staticmethod