From c6fee3c1f4058569d1bd0ccd98f220598f3af5e1 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 6 Jul 2021 14:56:18 -0400 Subject: [PATCH] moonraker: send status eventtime as a second parameter to "notify_status_update" This resolves a potential issue where clients could anticipate that all items in the status parameter are objects. Signed-off-by: Eric Callahan --- moonraker/components/klippy_apis.py | 5 ++++- moonraker/moonraker.py | 3 +-- moonraker/websockets.py | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/moonraker/components/klippy_apis.py b/moonraker/components/klippy_apis.py index 19bac81..b52dea7 100644 --- a/moonraker/components/klippy_apis.py +++ b/moonraker/components/klippy_apis.py @@ -191,7 +191,10 @@ class KlippyAPI(Subscribable): {'response_template': {"method": method_name}, 'remote_method': method_name}) - def send_status(self, status: Dict[str, Any]) -> None: + def send_status(self, + status: Dict[str, Any], + eventtime: float + ) -> None: self.server.send_event("server:status_update", status) def load_component(config: ConfigHelper) -> KlippyAPI: diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index a7fe0e4..4fe8850 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -469,8 +469,7 @@ class Server: else: conn_status[name] = { k: v for k, v in val.items() if k in fields} - conn_status['eventtime'] = eventtime - conn.send_status(conn_status) + conn.send_status(conn_status, eventtime) async def make_request(self, web_request: WebRequest) -> Any: rpc_method = web_request.get_endpoint() diff --git a/moonraker/websockets.py b/moonraker/websockets.py index a6f5a46..5163f81 100644 --- a/moonraker/websockets.py +++ b/moonraker/websockets.py @@ -42,7 +42,10 @@ if TYPE_CHECKING: SENTINEL = SentinelClass.get_instance() class Subscribable: - def send_status(self, status: Dict[str, Any]) -> None: + def send_status(self, + status: Dict[str, Any], + eventtime: float + ) -> None: raise NotImplementedError class WebRequest: @@ -428,13 +431,16 @@ class WebSocket(WebSocketHandler, Subscribable): f"Error sending data over websocket: {self.uid}") self.queue_busy = False - def send_status(self, status: Dict[str, Any]) -> None: + def send_status(self, + status: Dict[str, Any], + eventtime: float + ) -> None: if not status: return self.queue_message({ 'jsonrpc': "2.0", 'method': "notify_status_update", - 'params': [status]}) + 'params': [status, eventtime]}) def on_close(self) -> None: self.is_closed = True