spoolman: add a status endpoint

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-01-20 11:43:17 -05:00
parent bf9223225c
commit a5128f06ad
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 17 additions and 0 deletions

View File

@ -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()