From 94a2949c006c9e4b60372d54f2011a2089302c4c Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 10 Feb 2022 08:28:51 -0500 Subject: [PATCH] moonraker: report missing klippy requirements Moonraker requires that some Klipper objects be configured and loaded. This check has always been performed and logged, now track and report missing requirements. Signed-off-by: Eric Callahan --- moonraker/klippy_connection.py | 16 ++++++++++++---- moonraker/moonraker.py | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/moonraker/klippy_connection.py b/moonraker/klippy_connection.py index b6924a8..c635c9a 100644 --- a/moonraker/klippy_connection.py +++ b/moonraker/klippy_connection.py @@ -25,6 +25,7 @@ from typing import ( Coroutine, Dict, List, + Set, ) if TYPE_CHECKING: from app import MoonrakerApp @@ -53,6 +54,7 @@ class KlippyConnection: self.closing: bool = False self._klippy_info: Dict[str, Any] = {} self.init_list: List[str] = [] + self._missing_reqs: Set[str] = set() self.init_attempts: int = 0 self._state: str = "disconnected" self.subscriptions: Dict[Subscribable, Dict[str, Any]] = {} @@ -82,6 +84,10 @@ class KlippyConnection: def klippy_info(self) -> Dict[str, Any]: return self._klippy_info + @property + def missing_requirements(self) -> List[str]: + return list(self._missing_reqs) + async def wait_connected(self) -> bool: if ( self.connection_task is None or @@ -204,6 +210,7 @@ class KlippyConnection: async def _init_klippy_connection(self) -> bool: self.init_list = [] + self._missing_reqs.clear() self.init_attempts = 0 self._state = "initializing" webhooks_err_logged = False @@ -303,14 +310,14 @@ class KlippyConnection: f"Unable to retrieve Klipper Object List") return req_objs = set(["virtual_sdcard", "display_status", "pause_resume"]) - missing_objs = req_objs - set(result) - if missing_objs: - err_str = ", ".join([f"[{o}]" for o in missing_objs]) + self._missing_reqs = req_objs - set(result) + if self._missing_reqs: + err_str = ", ".join([f"[{o}]" for o in self._missing_reqs]) logging.info( f"\nWarning, unable to detect the following printer " f"objects:\n{err_str}\nPlease add the the above sections " f"to printer.cfg for full Moonraker functionality.") - if "virtual_sdcard" not in missing_objs: + if "virtual_sdcard" not in self._missing_reqs: # Update the gcode path query_res = await self.klippy_apis.query_objects( {'configfile': None}, default=None) @@ -475,6 +482,7 @@ class KlippyConnection: request.notify(ServerError("Klippy Disconnected", 503)) self.pending_requests = {} self.subscriptions = {} + self._missing_reqs.clear() logging.info("Klippy Connection Removed") await self.server.send_event("server:klippy_disconnect") if self.server.is_running(): diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 018c48d..7c5e173 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -388,6 +388,7 @@ class Server: if file_manager is not None: reg_dirs = file_manager.get_registered_dirs() wsm: WebsocketManager = self.lookup_component('websockets') + mreqs = self.klippy_connection.missing_requirements return { 'klippy_connected': self.klippy_connection.is_connected(), 'klippy_state': self.klippy_connection.state, @@ -396,7 +397,8 @@ class Server: 'registered_directories': reg_dirs, 'warnings': self.warnings, 'websocket_count': wsm.get_count(), - 'moonraker_version': self.app_args['software_version'] + 'moonraker_version': self.app_args['software_version'], + 'missing_klippy_requirements': mreqs } async def _handle_config_request(self,