From a7c67721b6dd6abd3c5d852bb731bd5a66a6647a Mon Sep 17 00:00:00 2001 From: dw-0 Date: Sat, 27 Jul 2024 22:30:53 +0200 Subject: [PATCH] refactor: make Moonraker to dataclass Signed-off-by: Dominik Willner --- kiauh/components/moonraker/moonraker.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kiauh/components/moonraker/moonraker.py b/kiauh/components/moonraker/moonraker.py index f4db5de..f62f5bd 100644 --- a/kiauh/components/moonraker/moonraker.py +++ b/kiauh/components/moonraker/moonraker.py @@ -8,6 +8,7 @@ # ======================================================================= # from __future__ import annotations +from dataclasses import dataclass from pathlib import Path from subprocess import CalledProcessError, run @@ -28,11 +29,22 @@ from utils.logger import Logger # noinspection PyMethodMayBeStatic +@dataclass class Moonraker(BaseInstance): + moonraker_dir: Path = MOONRAKER_DIR + env_dir: Path = MOONRAKER_ENV_DIR + cfg_file: Path = None + port: int = None + backup_dir: Path = None + certs_dir: Path = None + db_dir: Path = None + log: Path = None + def __init__(self, suffix: str = ""): super().__init__(instance_type=self, suffix=suffix) - self.moonraker_dir: Path = MOONRAKER_DIR - self.env_dir: Path = MOONRAKER_ENV_DIR + + def __post_init__(self) -> None: + super().__post_init__() self.cfg_file = self.cfg_dir.joinpath(MOONRAKER_CFG_NAME) self.port = self._get_port() self.backup_dir = self.data_dir.joinpath("backup")