config: validator fix floats

This commit is contained in:
alfrix 2022-09-03 18:20:45 -03:00
parent fd7ff6b0cd
commit 2d7486974c

View File

@ -163,7 +163,7 @@ class KlipperScreenConfig:
msg = f'Option "{key}" not recognized for section "[{section}]"' msg = f'Option "{key}" not recognized for section "[{section}]"'
self.errors.append(msg) self.errors.append(msg)
# This most probably is not a big issue, continue to load the config # 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"]: or key in bools and self.config[section][key] not in ["False", "false", "True", "true"]:
msg = ( msg = (
f'Unable to parse "{key}" from [{section}]\n' f'Unable to parse "{key}" from [{section}]\n'
@ -173,6 +173,14 @@ class KlipperScreenConfig:
valid = False valid = False
return valid return valid
@staticmethod
def is_float(element):
try:
float(element)
return True
except ValueError:
return False
def get_errors(self): def get_errors(self):
return "".join(f'{error}\n\n' for error in self.errors) return "".join(f'{error}\n\n' for error in self.errors)
@ -392,7 +400,7 @@ class KlipperScreenConfig:
if name not in self.config: if name not in self.config:
return False return False
cfg = self.config[name] 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): def get_printer_config(self, name):
if not name.startswith("printer "): if not name.startswith("printer "):