mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-07 23:17:37 -06:00
msgproto: Support default values in get_constant() calls
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
6eefbe5e30
commit
a67306c76b
2 changed files with 11 additions and 7 deletions
|
@ -324,12 +324,16 @@ class MessageParser:
|
|||
except Exception as e:
|
||||
logging.exception("process_identify error")
|
||||
raise error("Error during identify: %s" % (str(e),))
|
||||
def get_constant(self, name):
|
||||
try:
|
||||
return self.config[name]
|
||||
except KeyError:
|
||||
class sentinel: pass
|
||||
def get_constant(self, name, default=sentinel):
|
||||
if name not in self.config:
|
||||
if default is not self.sentinel:
|
||||
return default
|
||||
raise error("Firmware constant '%s' not found" % (name,))
|
||||
def get_constant_float(self, name):
|
||||
return self.config[name]
|
||||
def get_constant_float(self, name, default=sentinel):
|
||||
if name not in self.config and default is not self.sentinel:
|
||||
return default
|
||||
try:
|
||||
return float(self.config[name])
|
||||
except ValueError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue