From 2d7486974cef889f8105a2a6bd831508d94c0061 Mon Sep 17 00:00:00 2001 From: alfrix Date: Sat, 3 Sep 2022 18:20:45 -0300 Subject: [PATCH] config: validator fix floats --- ks_includes/config.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ks_includes/config.py b/ks_includes/config.py index 1b758cb2..f1422723 100644 --- a/ks_includes/config.py +++ b/ks_includes/config.py @@ -163,7 +163,7 @@ class KlipperScreenConfig: msg = f'Option "{key}" not recognized for section "[{section}]"' self.errors.append(msg) # This most probably is not a big issue, continue to load the config - elif key in numbers and not self.config[section][key].isnumeric() \ + elif key in numbers and not self.is_float(self.config[section][key]) \ or key in bools and self.config[section][key] not in ["False", "false", "True", "true"]: msg = ( f'Unable to parse "{key}" from [{section}]\n' @@ -173,6 +173,14 @@ class KlipperScreenConfig: valid = False return valid + @staticmethod + def is_float(element): + try: + float(element) + return True + except ValueError: + return False + def get_errors(self): return "".join(f'{error}\n\n' for error in self.errors) @@ -392,7 +400,7 @@ class KlipperScreenConfig: if name not in self.config: return False cfg = self.config[name] - return {opt: cfg.get("gcode", None) if opt == "gcode" else cfg.getint(opt, None) for opt in cfg} + return {opt: cfg.get("gcode", None) if opt == "gcode" else cfg.getfloat(opt, None) for opt in cfg} def get_printer_config(self, name): if not name.startswith("printer "):