diff --git a/klippy/extras/ad5206.py b/klippy/extras/ad5206.py index f71655df..1f30c89a 100644 --- a/klippy/extras/ad5206.py +++ b/klippy/extras/ad5206.py @@ -26,5 +26,5 @@ class ad5206: self.mcu.add_config_cmd( "send_spi_message pin=%s msg=%02x%02x" % (self.pin, i, val)) -def load_config(config): +def load_config_prefix(config): return ad5206(config) diff --git a/klippy/extras/bed_tilt.py b/klippy/extras/bed_tilt.py index 4307e8c7..0b766328 100644 --- a/klippy/extras/bed_tilt.py +++ b/klippy/extras/bed_tilt.py @@ -90,6 +90,4 @@ class BedTiltCalibrate: z_warn, new_params['x_adjust'], new_params['y_adjust'])) def load_config(config): - if config.get_name() != 'bed_tilt': - raise config.error("Invalid bed_tilt config name") return BedTilt(config) diff --git a/klippy/extras/delta_calibrate.py b/klippy/extras/delta_calibrate.py index 5c69aa8d..7953493c 100644 --- a/klippy/extras/delta_calibrate.py +++ b/klippy/extras/delta_calibrate.py @@ -71,6 +71,4 @@ class DeltaCalibrate: new_params['radius'])) def load_config(config): - if config.get_name() != 'delta_calibrate': - raise config.error("Invalid delta_calibrate config name") return DeltaCalibrate(config) diff --git a/klippy/extras/fan.py b/klippy/extras/fan.py index 7bc4a26d..cbfdd678 100644 --- a/klippy/extras/fan.py +++ b/klippy/extras/fan.py @@ -34,6 +34,4 @@ class PrinterFan: self.last_fan_value = value def load_config(config): - if config.get_name() != 'fan': - raise config.error("Invalid print cooling fan config name") return PrinterFan(config) diff --git a/klippy/extras/heater_fan.py b/klippy/extras/heater_fan.py index 2b5ff904..fdeb9f71 100644 --- a/klippy/extras/heater_fan.py +++ b/klippy/extras/heater_fan.py @@ -33,5 +33,5 @@ class PrinterHeaterFan: self.fan.set_speed(print_time, power) return eventtime + 1. -def load_config(config): +def load_config_prefix(config): return PrinterHeaterFan(config) diff --git a/klippy/extras/homing_override.py b/klippy/extras/homing_override.py index c773f444..62a97aa4 100644 --- a/klippy/extras/homing_override.py +++ b/klippy/extras/homing_override.py @@ -36,6 +36,4 @@ class HomingOverride: self.in_script = False def load_config(config): - if config.get_name() != 'homing_override': - raise config.error("Invalid homing_override config name") return HomingOverride(config) diff --git a/klippy/extras/multi_pin.py b/klippy/extras/multi_pin.py index 5ffaed80..d06e14f2 100644 --- a/klippy/extras/multi_pin.py +++ b/klippy/extras/multi_pin.py @@ -50,5 +50,5 @@ class PrinterMultiPin: for mcu_pin in self.mcu_pins: mcu_pin.set_pwm(print_time, value) -def load_config(config): +def load_config_prefix(config): return PrinterMultiPin(config) diff --git a/klippy/extras/probe.py b/klippy/extras/probe.py index 084612fe..05634139 100644 --- a/klippy/extras/probe.py +++ b/klippy/extras/probe.py @@ -172,6 +172,4 @@ def coordinate_descent(adj_params, params, error_func): return params def load_config(config): - if config.get_name() != 'probe': - raise config.error("Invalid probe config name") return PrinterProbe(config) diff --git a/klippy/extras/replicape.py b/klippy/extras/replicape.py index 742607c5..aa1d14fd 100644 --- a/klippy/extras/replicape.py +++ b/klippy/extras/replicape.py @@ -218,6 +218,4 @@ class Replicape: return pclass(self, channel, pin_params) def load_config(config): - if config.get_name() != 'replicape': - raise config.error("Invalid replicape config name") return Replicape(config) diff --git a/klippy/extras/servo.py b/klippy/extras/servo.py index 547178e8..e2e10b41 100644 --- a/klippy/extras/servo.py +++ b/klippy/extras/servo.py @@ -55,5 +55,5 @@ class PrinterServo: else: self.set_angle(print_time, self.gcode.get_float('ANGLE', params)) -def load_config(config): +def load_config_prefix(config): return PrinterServo(config) diff --git a/klippy/klippy.py b/klippy/klippy.py index 12f82ebe..fba527a2 100644 --- a/klippy/klippy.py +++ b/klippy/klippy.py @@ -185,13 +185,19 @@ class Printer: def _try_load_module(self, config, section): if section in self.objects: return - module_name = section.split()[0] + module_parts = section.split() + module_name = module_parts[0] py_name = os.path.join(os.path.dirname(__file__), 'extras', module_name + '.py') if not os.path.exists(py_name): return mod = importlib.import_module('extras.' + module_name) - self.objects[section] = mod.load_config(config.getsection(section)) + init_func = 'load_config' + if len(module_parts) > 1: + init_func = 'load_config_prefix' + init_func = getattr(mod, init_func, None) + if init_func is not None: + self.objects[section] = init_func(config.getsection(section)) def _read_config(self): fileconfig = ConfigParser.RawConfigParser() config_file = self.start_args['config_file']