@@ -242,15 +242,25 @@ def _send_arbitrary_notification(self, settings, message, image):
242
242
return self ._alerts .send_alert (settings , apns_token , url , printer_name , message , None , image ) < 300
243
243
244
244
def _is_printer_printing (self , printer ):
245
- completion = None
245
+ (completion , print_time_in_seconds , print_time_left_in_seconds ) = self ._get_progress_data (printer )
246
+ # Check that we are in the middle of a print
247
+ return not (completion is None or completion == 0 or completion == 100 )
248
+
249
+ def _get_progress_data (self , printer , reported_progress = None ):
250
+ completion = None if reported_progress is None else reported_progress
251
+ print_time_in_seconds = None
252
+ print_time_left_in_seconds = None
246
253
current_data = printer .get_current_data ()
247
254
if "progress" in current_data and current_data ["progress" ] is not None \
248
255
and "completion" in current_data ["progress" ] and current_data ["progress" ][
249
256
"completion" ] is not None :
250
- completion = current_data ["progress" ]["completion" ]
257
+ print_time_left_in_seconds = current_data ["progress" ]["printTimeLeft" ]
258
+ print_time_in_seconds = current_data ["progress" ]["printTime" ]
259
+ completion = current_data ["progress" ]["completion" ] if reported_progress is None else reported_progress
260
+ # Ugly hack - PrintTimeGenius changed reported completion so we need to use their conversion function
261
+ completion = self ._convert_progress (completion , print_time_in_seconds , print_time_left_in_seconds )
262
+ return completion , print_time_in_seconds , print_time_left_in_seconds
251
263
252
- # Check that we are in the middle of a print
253
- return not (completion is None or completion == 0 or completion == 100 )
254
264
255
265
@staticmethod
256
266
def _get_server_url (settings ):
@@ -262,3 +272,17 @@ def _get_server_url(settings):
262
272
if server_url .endswith ('/' ):
263
273
server_url = server_url [:- 1 ]
264
274
return server_url
275
+
276
+ def _convert_progress (self , progress , print_time , time_left ):
277
+ """
278
+ PrintTimeGenius plugin changed the way progress is calculated. If this plugin is installed then the reported
279
+ progress by OctoPrint might be wrong and hence needs to be calculated based on printing time.
280
+ """
281
+ if print_time is None or time_left is None :
282
+ return progress
283
+ # Check if PrintTimeGenius plugin is installed and enabled
284
+ print_time_genius_plugin = self ._plugin_manager .plugins .get ("PrintTimeGenius" )
285
+ if print_time_genius_plugin is not None and print_time_genius_plugin .enabled and time_left > 0 :
286
+ return print_time / (print_time + time_left ) * 100
287
+ return progress
288
+
0 commit comments