simplyprint: automate file reset for sp uploads

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-08-28 12:19:53 -04:00
parent 3a03f48e0f
commit 7f2d43de3d
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 16 additions and 0 deletions

View File

@ -687,6 +687,16 @@ class SimplyPrint(Subscribable):
}
self._send_job_event(job_info)
def _reset_file(self) -> None:
cur_job = self.cache.job_info.get("filename", "")
last_started = self.print_handler.last_started
if last_started and last_started == cur_job:
kapi: KlippyAPI = self.server.lookup_component("klippy_apis")
self.eventloop.create_task(
kapi.run_gcode("SDCARD_RESET_FILE", default=None)
)
self.print_handler.last_started = ""
def _on_print_paused(self, *args) -> None:
self.send_sp("job_info", {"paused": True})
self._update_state("paused")
@ -698,6 +708,7 @@ class SimplyPrint(Subscribable):
def _on_print_cancelled(self, *args) -> None:
self._check_job_started(*args)
self._reset_file()
self._send_job_event({"cancelled": True})
self._update_state_from_klippy()
self.cache.job_info = {}
@ -705,6 +716,7 @@ class SimplyPrint(Subscribable):
def _on_print_error(self, *args) -> None:
self._check_job_started(*args)
self._reset_file()
payload: Dict[str, Any] = {"failed": True}
new_stats: Dict[str, Any] = args[1]
msg = new_stats.get("message", "Unknown Error")
@ -716,6 +728,7 @@ class SimplyPrint(Subscribable):
def _on_print_complete(self, *args) -> None:
self._check_job_started(*args)
self._reset_file()
self._send_job_event({"finished": True})
self._update_state_from_klippy()
self.cache.job_info = {}
@ -1399,6 +1412,7 @@ class PrintHandler:
self.print_ready_event: asyncio.Event = asyncio.Event()
self.download_progress: int = -1
self.pending_file: str = ""
self.last_started: str = ""
def download_file(self, url: str, start: bool):
coro = self._download_sp_file(url, start)
@ -1509,6 +1523,8 @@ class PrintHandler:
logging.exception("Print Failed to start")
data["state"] = "error"
data["message"] = "Failed to start print"
else:
self._last_started = pending
self.simplyprint.send_sp("file_progress", data)
async def _check_can_print(self) -> bool: