klippy_connection: report Klippy's state message
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b52b0bd98a
commit
25e79c78b2
|
@ -61,6 +61,7 @@ class KlippyConnection:
|
||||||
self._peer_cred: Dict[str, int] = {}
|
self._peer_cred: Dict[str, int] = {}
|
||||||
self.init_attempts: int = 0
|
self.init_attempts: int = 0
|
||||||
self._state: str = "disconnected"
|
self._state: str = "disconnected"
|
||||||
|
self._state_message: str = "Klippy Disconnected"
|
||||||
self.subscriptions: Dict[Subscribable, Dict[str, Any]] = {}
|
self.subscriptions: Dict[Subscribable, Dict[str, Any]] = {}
|
||||||
# Setup remote methods accessable to Klippy. Note that all
|
# Setup remote methods accessable to Klippy. Note that all
|
||||||
# registered remote methods should be of the notification type,
|
# registered remote methods should be of the notification type,
|
||||||
|
@ -84,6 +85,10 @@ class KlippyConnection:
|
||||||
def state(self) -> str:
|
def state(self) -> str:
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_message(self) -> str:
|
||||||
|
return self._state_message
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def klippy_info(self) -> Dict[str, Any]:
|
def klippy_info(self) -> Dict[str, Any]:
|
||||||
return self._klippy_info
|
return self._klippy_info
|
||||||
|
@ -329,6 +334,8 @@ class KlippyConnection:
|
||||||
msg = f"Klipper Version: {version}"
|
msg = f"Klipper Version: {version}"
|
||||||
self.server.add_log_rollover_item("klipper_version", msg)
|
self.server.add_log_rollover_item("klipper_version", msg)
|
||||||
self._klippy_info = dict(result)
|
self._klippy_info = dict(result)
|
||||||
|
if "state_message" in self._klippy_info:
|
||||||
|
self._state_message = self._klippy_info["state_message"]
|
||||||
state = result.get('state', "unknown")
|
state = result.get('state', "unknown")
|
||||||
if state != "startup" and "endpoints_requested" not in self.init_list:
|
if state != "startup" and "endpoints_requested" not in self.init_list:
|
||||||
await self._request_endpoints()
|
await self._request_endpoints()
|
||||||
|
@ -342,8 +349,7 @@ class KlippyConnection:
|
||||||
await self.server.send_event("server:klippy_started",
|
await self.server.send_event("server:klippy_started",
|
||||||
self._state)
|
self._state)
|
||||||
if self._state != "ready":
|
if self._state != "ready":
|
||||||
msg = result.get('state_message', "Klippy Not Ready")
|
logging.info("\n" + self._state_message)
|
||||||
logging.info("\n" + msg)
|
|
||||||
else:
|
else:
|
||||||
await self._verify_klippy_requirements()
|
await self._verify_klippy_requirements()
|
||||||
# register methods with klippy
|
# register methods with klippy
|
||||||
|
@ -435,9 +441,12 @@ class KlippyConnection:
|
||||||
status: Dict[str, Any]
|
status: Dict[str, Any]
|
||||||
) -> None:
|
) -> None:
|
||||||
if 'webhooks' in status:
|
if 'webhooks' in status:
|
||||||
|
wh: Dict[str, str] = status['webhooks']
|
||||||
|
if "state_message" in wh:
|
||||||
|
self._state_message = wh["state_message"]
|
||||||
# XXX - process other states (startup, ready, error, etc)?
|
# XXX - process other states (startup, ready, error, etc)?
|
||||||
state: Optional[str] = status['webhooks'].get('state', None)
|
if "state" in wh:
|
||||||
if state is not None:
|
state = wh["state"]
|
||||||
if state == "shutdown":
|
if state == "shutdown":
|
||||||
logging.info("Klippy has shutdown")
|
logging.info("Klippy has shutdown")
|
||||||
self.server.send_event("server:klippy_shutdown")
|
self.server.send_event("server:klippy_shutdown")
|
||||||
|
@ -531,6 +540,7 @@ class KlippyConnection:
|
||||||
async def _on_connection_closed(self) -> None:
|
async def _on_connection_closed(self) -> None:
|
||||||
self.init_list = []
|
self.init_list = []
|
||||||
self._state = "disconnected"
|
self._state = "disconnected"
|
||||||
|
self._state_message = "Klippy Disconnected"
|
||||||
for request in self.pending_requests.values():
|
for request in self.pending_requests.values():
|
||||||
request.notify(ServerError("Klippy Disconnected", 503))
|
request.notify(ServerError("Klippy Disconnected", 503))
|
||||||
self.pending_requests = {}
|
self.pending_requests = {}
|
||||||
|
|
Loading…
Reference in New Issue