klipper_utils.klipper_utils
Generic Klipper utility functions and classes.
- exception klipper_utils.klipper_utils.KlipperUtilsError
Bases:
ExceptionGeneric error for Klipper utility functions.
- add_note(note, /)
Add a note to the exception
- with_traceback(tb, /)
Set self.__traceback__ to tb and return self.
- class klipper_utils.klipper_utils.KlipperConfigDict
Bases:
ABCKlipper dictionary type config file of comma separated key-values pairs and helper functions.
Klipper config file example:
config-name=<key_1>=<value_1>, <key_2>=<value_2>, ...
Class represents the config file as instance variables:
@dataclass class KlipperConfImpl(KlipperConf): key_1: float key_2: float
- abstractmethod static get_title()
Get the list of config variables.
This defines the which instance variables are the config variables, their stored order and naturally the name of the values. E.g., returning [‘low’, ‘high’] means the class has to have members ‘low’ and ‘high’.
- get_data()
Get the dictionary of all config variables.
- to_string()
Comma separated list of all config variables
get_title()as <key>=<value> pairs.I.e.:
<key_1>=<value_1>, <key_2>=<value_2>
- Returns:
String of all config variables.
- Return type:
- class klipper_utils.klipper_utils.KlipperUtils
Bases:
objectCollection of Klipper utility functions.
- static call_command(gcmd, fun, syntax_prefix='')
Handle Klipper GCODE command automatically.
Parameters are checked for required/optional/unknown parameters and converted to the correct type.
- Parameters:
gcmd (Gcmd) – G-code object.
fun (Command) – Command function to be called.
syntax_prefix (str) – Prefix shown on syntax error, e.g. the command name.
- Raises:
gcmd.error – If the parameters are invalid or missing, or if there are unknown parameters.
- Return type:
None
- static klipper_from_config_string(class_entry, string)
Convert comma separated key-values pairs ‘<key>=<value>,…’ to an instance created with matching kwargs.
- static klipper_map_from_config(class_entry, entries)
Convert a list of comma separated key-values pairs [‘<key>=<value>,…’, …] to an instance created with matching kwargs.
Klipper config file example:
config-name=<key 1a>=<value 1a>, <key 2a>=<value 2a>, ... <key 1b>=<value 1b>, <key 2a>=<value 2b>, ... ...
- static register_command(gcode, function, cmd_name, help_text, fail_on_error)
Register a command with Klipper G-code parser.
- Parameters:
gcode (Gcmd) – G-code object to register the command with.
function (Command) – Function to handle the command. Signature should be function(gcmd, parameters…).
cmd_name (str) – Name of the command to register.
help_text (str) – Help text for the command shown in HELP G-code.
fail_on_error (bool) – True: raise an error on command failure. False: just log the error.
- Return type:
None