klippy_connection: send an event when gcode commands are received

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-03-20 11:57:04 -04:00
parent fe3b7456f6
commit 366e68c8f4
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
2 changed files with 7 additions and 5 deletions

View File

@ -50,6 +50,9 @@ class DataStore:
"server:gcode_response", self._update_gcode_store)
self.server.register_event_handler(
"server:klippy_ready", self._init_sensors)
self.server.register_event_handler(
"klippy_connection:gcode_received", self._store_gcode_command
)
# Register endpoints
self.server.register_endpoint(
@ -145,7 +148,7 @@ class DataStore:
self.gcode_queue.append(
{'message': response, 'time': curtime, 'type': "response"})
def store_gcode_command(self, script: str) -> None:
def _store_gcode_command(self, script: str) -> None:
curtime = time.time()
for cmd in script.split('\n'):
cmd = cmd.strip()

View File

@ -30,7 +30,6 @@ from typing import (
if TYPE_CHECKING:
from app import MoonrakerApp
from websockets import WebRequest, Subscribable
from components.data_store import DataStore
from components.klippy_apis import KlippyAPI
from components.file_manager.file_manager import FileManager
FlexCallback = Callable[..., Optional[Coroutine]]
@ -417,9 +416,9 @@ class KlippyConnection:
else:
if rpc_method == "gcode/script":
script = web_request.get_str('script', "")
data_store: DataStore
data_store = self.server.lookup_component('data_store')
data_store.store_gcode_command(script)
if script:
self.server.send_event(
"klippy_connection:gcode_received", script)
return await self._request_standard(web_request)
async def _request_subscripton(self,