def process_octoprint_status_with_ts(op_status, printer): op_event = op_status.get('octoprint_event', {}) op_data = op_status.get('octoprint_data', {}) print_ts = op_status.get('current_print_ts') current_filename = op_event.get('name') or op_data.get('job', {}).get( 'file', {}).get('name') if not current_filename: return printer.update_current_print(current_filename, print_ts) if not printer.current_print: return if op_event.get('event_type') in ('PrintCancelled', 'PrintFailed'): printer.current_print.cancelled_at = timezone.now() printer.current_print.save() if op_event.get('event_type') in ('PrintFailed', 'PrintDone'): printer.unset_current_print() if op_event.get('event_type') == 'PrintPaused': printer.current_print.paused_at = timezone.now() printer.current_print.save() PrintEvent.create(printer.current_print, PrintEvent.PAUSED) if op_event.get('event_type') == 'PrintResumed': printer.current_print.paused_at = None printer.current_print.save() PrintEvent.create(printer.current_print, PrintEvent.RESUMED)
def process_octoprint_status_with_ts(op_status, printer): op_event = op_status.get('octoprint_event', {}) op_data = op_status.get('octoprint_data', {}) print_ts = op_status.get('current_print_ts') current_filename = op_event.get('name') or op_data.get('job', {}).get('file', {}).get('name') if not current_filename: return printer.update_current_print(current_filename, print_ts) if not printer.current_print: return # Notification for mobile devices or for external service webhooks such as 3D Geeks # This has to happen before event saving, as `current_print` may change after event saving. mobile_notifications.send_if_needed(printer.current_print, op_event, op_data) call_service_webhook_if_needed(printer, op_event, op_data) if op_event.get('event_type') in ('PrintCancelled', 'PrintFailed'): printer.current_print.cancelled_at = timezone.now() printer.current_print.save() if op_event.get('event_type') in ('PrintFailed', 'PrintDone'): printer.unset_current_print() if op_event.get('event_type') == 'PrintPaused': printer.current_print.paused_at = timezone.now() printer.current_print.save() PrintEvent.create(printer.current_print, PrintEvent.PAUSED) if op_event.get('event_type') == 'PrintResumed': printer.current_print.paused_at = None printer.current_print.save() PrintEvent.create(printer.current_print, PrintEvent.RESUMED)
def process_octoprint_status_with_ts(op_status, printer): op_event = op_status.get('octoprint_event', {}) op_data = op_status.get('octoprint_data', {}) print_ts = op_status.get('current_print_ts') current_filename = op_event.get('name') or op_data.get('job', {}).get( 'file', {}).get('name') if not current_filename: return printer.update_current_print(current_filename, print_ts) if not printer.current_print: return # Notification for mobile devices # This has to happen before event saving, as `current_print` may change after event saving. mobile_notifications.send_if_needed(printer.current_print, op_event, op_data) if op_event.get('event_type') == 'PrintCancelled': printer.current_print.cancelled_at = timezone.now() printer.current_print.save() elif op_event.get('event_type') == 'PrintFailed': # setting cancelled_at here, original commit: # https://github.com/TheSpaghettiDetective/TheSpaghettiDetective/commit/86d1a18d34a9d895e9d9284d5048e45afa1e56a1 printer.current_print.cancelled_at = timezone.now() printer.current_print.save() printer.unset_current_print() elif op_event.get('event_type') == 'PrintDone': printer.unset_current_print() elif op_event.get('event_type') == 'PrintPaused': printer.current_print.paused_at = timezone.now() printer.current_print.save() PrintEvent.create(printer.current_print, PrintEvent.PAUSED) elif op_event.get('event_type') == 'PrintResumed': printer.current_print.paused_at = None printer.current_print.save() PrintEvent.create(printer.current_print, PrintEvent.RESUMED) elif op_event.get('event_type') == 'FilamentChange': PrintEvent.create(printer.current_print, PrintEvent.FILAMENT_CHANGE)