From 35d8d888556a94f724391d45084fc5a3194a0572 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 4 Feb 2022 11:20:31 -0500 Subject: [PATCH] confighelper: remove direct component imports Dont directly import components for instance checks. Instead check to see if the type is serializable, if not store the string representation. Signed-off-by: Eric Callahan --- moonraker/confighelper.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/moonraker/confighelper.py b/moonraker/confighelper.py index 335f44e..e2170a2 100644 --- a/moonraker/confighelper.py +++ b/moonraker/confighelper.py @@ -13,8 +13,6 @@ import filecmp import pathlib import logging from utils import SentinelClass -from components.gpio import GpioOutputPin -from components.template import JinjaTemplate # Annotation imports from typing import ( @@ -32,10 +30,10 @@ from typing import ( ) if TYPE_CHECKING: from moonraker import Server - from components.gpio import GpioFactory - from components.template import TemplateFactory + from components.gpio import GpioFactory, GpioOutputPin + from components.template import TemplateFactory, JinjaTemplate _T = TypeVar("_T") - ConfigVal = Union[None, int, float, bool, str] + ConfigVal = Union[None, int, float, bool, str, dict, list] SENTINEL = SentinelClass.get_instance() @@ -126,10 +124,14 @@ class ConfigHelper: self._check_option(option, val, above, below, minval, maxval) if self.section in self.orig_sections: # Only track sections included in the original config - if isinstance(val, (GpioOutputPin, JinjaTemplate)): - self.parsed[self.section][option] = str(val) - else: + if ( + val is None or + isinstance(val, (int, float, bool, str, dict, list)) + ): self.parsed[self.section][option] = val + else: + # If the item cannot be encoded to json serialize to a string + self.parsed[self.section][option] = str(val) return val def _check_option(self,