Prevent continued connect / disconnect loop

If a cloud printer was connected, it would time out all the time. In some cases
it would do this in a single update loop (so connect and disconnect). Depending
on the machine of the user, this would either be visible or not at all.
This commit is contained in:
Jaime van Kessel 2020-08-25 17:02:39 +02:00
parent bf9c413516
commit f6cbb0f88c
No known key found for this signature in database
GPG Key ID: 3710727397403C91

View File

@ -45,10 +45,6 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
# States indicating if a print job is queued.
QUEUED_PRINT_JOBS_STATES = {"queued", "error"}
# Time in seconds since last network response after which we consider this device offline.
# We set this a bit higher than some of the other intervals to make sure they don't overlap.
NETWORK_RESPONSE_CONSIDER_OFFLINE = 10.0 # seconds
def __init__(self, device_id: str, address: str, properties: Dict[bytes, bytes], connection_type: ConnectionType,
parent=None) -> None:
@ -87,6 +83,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
# The job upload progress message modal.
self._progress = PrintJobUploadProgressMessage()
self._timeout_time = 30
@pyqtProperty(str, constant=True)
def address(self) -> str:
"""The IP address of the printer."""
@ -213,8 +211,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
return Duration(seconds).getDisplayString(DurationFormat.Format.Short)
def _update(self) -> None:
self._checkStillConnected()
super()._update()
self._checkStillConnected()
def _checkStillConnected(self) -> None:
"""Check if we're still connected by comparing the last timestamps for network response and the current time.
@ -224,7 +222,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
TODO: it would be nice to have this logic in the managers, but connecting those with signals causes crashes.
"""
time_since_last_response = time() - self._time_of_last_response
if time_since_last_response > self.NETWORK_RESPONSE_CONSIDER_OFFLINE:
if time_since_last_response > self._timeout_time:
Logger.log("d", "It has been %s seconds since the last response for outputdevice %s, so assume a timeout", time_since_last_response, self.key)
self.setConnectionState(ConnectionState.Closed)
if self.key in CuraApplication.getInstance().getOutputDeviceManager().getOutputDeviceIds():
CuraApplication.getInstance().getOutputDeviceManager().removeOutputDevice(self.key)
@ -241,6 +240,7 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
return
# Indicate this device is now connected again.
Logger.log("d", "Reconnecting output device after timeout.")
self.setConnectionState(ConnectionState.Connected)
# If the device was already registered we don't need to register it again.