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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-02-04 11:20:31 -05:00
parent f6d8de2cee
commit 35d8d88855
1 changed files with 10 additions and 8 deletions

View File

@ -13,8 +13,6 @@ import filecmp
import pathlib import pathlib
import logging import logging
from utils import SentinelClass from utils import SentinelClass
from components.gpio import GpioOutputPin
from components.template import JinjaTemplate
# Annotation imports # Annotation imports
from typing import ( from typing import (
@ -32,10 +30,10 @@ from typing import (
) )
if TYPE_CHECKING: if TYPE_CHECKING:
from moonraker import Server from moonraker import Server
from components.gpio import GpioFactory from components.gpio import GpioFactory, GpioOutputPin
from components.template import TemplateFactory from components.template import TemplateFactory, JinjaTemplate
_T = TypeVar("_T") _T = TypeVar("_T")
ConfigVal = Union[None, int, float, bool, str] ConfigVal = Union[None, int, float, bool, str, dict, list]
SENTINEL = SentinelClass.get_instance() SENTINEL = SentinelClass.get_instance()
@ -126,10 +124,14 @@ class ConfigHelper:
self._check_option(option, val, above, below, minval, maxval) self._check_option(option, val, above, below, minval, maxval)
if self.section in self.orig_sections: if self.section in self.orig_sections:
# Only track sections included in the original config # Only track sections included in the original config
if isinstance(val, (GpioOutputPin, JinjaTemplate)): if (
self.parsed[self.section][option] = str(val) val is None or
else: isinstance(val, (int, float, bool, str, dict, list))
):
self.parsed[self.section][option] = val 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 return val
def _check_option(self, def _check_option(self,