refactor: add __repr__ to Klipper class

This commit adds a __repr__ method to the Klipper class. This method returns a JSON string representation of the instance, which can be used for debugging purposes.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-07-07 17:25:58 +02:00
parent 75ac8a22d5
commit ed2e318d0e

View File

@@ -6,7 +6,7 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license #
# ======================================================================= #
import json
from pathlib import Path
from subprocess import CalledProcessError, run
from typing import List
@@ -41,6 +41,20 @@ class Klipper(BaseInstance):
self._serial = self.comms_dir.joinpath(KLIPPER_SERIAL_NAME)
self._uds = self.comms_dir.joinpath(KLIPPER_UDS_NAME)
def __repr__(self):
return json.dumps(
{
"suffix": self.suffix,
"klipper_dir": self.klipper_dir.as_posix(),
"env_dir": self.env_dir.as_posix(),
"cfg_file": self.cfg_file.as_posix(),
"log": self.log.as_posix(),
"serial": self.serial.as_posix(),
"uds": self.uds.as_posix(),
},
indent=4,
)
@property
def cfg_file(self) -> Path:
return self._cfg_file