spoolman: add a status endpoint
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
bf9223225c
commit
a5128f06ad
|
@ -14,6 +14,7 @@ from ..common import RequestType
|
|||
from ..utils import json_wrapper as jsonw
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
List,
|
||||
Dict,
|
||||
Any,
|
||||
Optional,
|
||||
|
@ -95,6 +96,11 @@ class SpoolManager:
|
|||
RequestType.POST,
|
||||
self._proxy_spoolman_request,
|
||||
)
|
||||
self.server.register_endpoint(
|
||||
"/server/spoolman/status",
|
||||
RequestType.GET,
|
||||
self._handle_status_request,
|
||||
)
|
||||
|
||||
async def component_init(self) -> None:
|
||||
self.spool_id = await self.database.get_item(
|
||||
|
@ -353,6 +359,17 @@ class SpoolManager:
|
|||
"error": None
|
||||
}
|
||||
|
||||
async def _handle_status_request(self, web_request: WebRequest) -> Dict[str, Any]:
|
||||
pending: List[Dict[str, Any]] = [
|
||||
{"spool_id": sid, "filament_used": used} for sid, used in
|
||||
self.pending_reports.items()
|
||||
]
|
||||
return {
|
||||
"spoolman_connected": self.ws_connected,
|
||||
"pending_reports": pending,
|
||||
"spool_id": self.spool_id
|
||||
}
|
||||
|
||||
async def close(self):
|
||||
self.is_closing = True
|
||||
self.report_timer.stop()
|
||||
|
|
Loading…
Reference in New Issue