mirror of https://github.com/Desuuuu/klipper.git
respond: No forced spaces (#5152)
Signed-off-by: Adrian Joachim <adi.joachim12@gmail.com>
This commit is contained in:
parent
a8f08b08ca
commit
167736ad1c
|
@ -1010,6 +1010,8 @@ The following additional commands are also available.
|
||||||
configured default prefix (or `echo: ` if no prefix is configured).
|
configured default prefix (or `echo: ` if no prefix is configured).
|
||||||
- `RESPOND TYPE=echo MSG="<message>"`: echo the message prepended with
|
- `RESPOND TYPE=echo MSG="<message>"`: echo the message prepended with
|
||||||
`echo: `.
|
`echo: `.
|
||||||
|
- `RESPOND TYPE=echo_no_space MSG="<message>"`: echo the message prepended with
|
||||||
|
`echo:` without a space between prefix and message, helpful for compatibility with some octoprint plugins that expect very specific formatting.
|
||||||
- `RESPOND TYPE=command MSG="<message>"`: echo the message prepended
|
- `RESPOND TYPE=command MSG="<message>"`: echo the message prepended
|
||||||
with `// `. OctoPrint can be configured to respond to these messages
|
with `// `. OctoPrint can be configured to respond to these messages
|
||||||
(e.g. `RESPOND TYPE=command MSG=action:pause`).
|
(e.g. `RESPOND TYPE=command MSG=action:pause`).
|
||||||
|
|
|
@ -10,6 +10,10 @@ respond_types = {
|
||||||
'error' : '!!',
|
'error' : '!!',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
respond_types_no_space = {
|
||||||
|
'echo_no_space': 'echo:',
|
||||||
|
}
|
||||||
|
|
||||||
class HostResponder:
|
class HostResponder:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.printer = config.get_printer()
|
self.printer = config.get_printer()
|
||||||
|
@ -26,19 +30,26 @@ class HostResponder:
|
||||||
gcmd.respond_raw("%s %s" % (self.default_prefix, msg))
|
gcmd.respond_raw("%s %s" % (self.default_prefix, msg))
|
||||||
cmd_RESPOND_help = ("Echo the message prepended with a prefix")
|
cmd_RESPOND_help = ("Echo the message prepended with a prefix")
|
||||||
def cmd_RESPOND(self, gcmd):
|
def cmd_RESPOND(self, gcmd):
|
||||||
|
no_space = False
|
||||||
respond_type = gcmd.get('TYPE', None)
|
respond_type = gcmd.get('TYPE', None)
|
||||||
prefix = self.default_prefix
|
prefix = self.default_prefix
|
||||||
if(respond_type != None):
|
if(respond_type != None):
|
||||||
respond_type = respond_type.lower()
|
respond_type = respond_type.lower()
|
||||||
if(respond_type in respond_types):
|
if(respond_type in respond_types):
|
||||||
prefix = respond_types[respond_type]
|
prefix = respond_types[respond_type]
|
||||||
|
elif(respond_type in respond_types_no_space):
|
||||||
|
prefix = respond_types_no_space[respond_type]
|
||||||
|
no_space = True
|
||||||
else:
|
else:
|
||||||
raise gcmd.error(
|
raise gcmd.error(
|
||||||
"RESPOND TYPE '%s' is invalid. Must be one"
|
"RESPOND TYPE '%s' is invalid. Must be one"
|
||||||
" of 'echo', 'command', or 'error'" % (respond_type,))
|
" of 'echo', 'command', or 'error'" % (respond_type,))
|
||||||
prefix = gcmd.get('PREFIX', prefix)
|
prefix = gcmd.get('PREFIX', prefix)
|
||||||
msg = gcmd.get('MSG', '')
|
msg = gcmd.get('MSG', '')
|
||||||
gcmd.respond_raw("%s %s" % (prefix, msg))
|
if(no_space):
|
||||||
|
gcmd.respond_raw("%s%s" % (prefix, msg))
|
||||||
|
else:
|
||||||
|
gcmd.respond_raw("%s %s" % (prefix, msg))
|
||||||
|
|
||||||
def load_config(config):
|
def load_config(config):
|
||||||
return HostResponder(config)
|
return HostResponder(config)
|
||||||
|
|
Loading…
Reference in New Issue