From 0f1aea8df8607b795e313e9cf100de19f3ec7fef Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Wed, 29 Sep 2021 19:49:47 -0400 Subject: [PATCH] moonraker: refactor component loading Remove the "load_component_multi" method as it is not necessary. Components are responsible for loading "child" sections as required. Core components can now have their own config section. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 2 +- moonraker/moonraker.py | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 6712c28..9a9b051 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -920,5 +920,5 @@ class Loxonev1(HTTPDevice): # The power component has multiple configuration sections -def load_component_multi(config: ConfigHelper) -> PrinterPower: +def load_component(config: ConfigHelper) -> PrinterPower: return PrinterPower(config) diff --git a/moonraker/moonraker.py b/moonraker/moonraker.py index 7d01332..3b507a2 100755 --- a/moonraker/moonraker.py +++ b/moonraker/moonraker.py @@ -195,13 +195,9 @@ class Server: return self.components[component_name] try: module = importlib.import_module("components." + component_name) - func_name = "load_component" - if hasattr(module, "load_component_multi"): - func_name = "load_component_multi" - if component_name not in CORE_COMPONENTS and \ - func_name == "load_component": + if component_name in config: config = config[component_name] - load_func = getattr(module, func_name) + load_func = getattr(module, "load_component") component = load_func(config) except Exception: msg = f"Unable to load component: ({component_name})"