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).
|
||||
- `RESPOND TYPE=echo MSG="<message>"`: echo the message prepended with
|
||||
`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
|
||||
with `// `. OctoPrint can be configured to respond to these messages
|
||||
(e.g. `RESPOND TYPE=command MSG=action:pause`).
|
||||
|
|
|
@ -10,6 +10,10 @@ respond_types = {
|
|||
'error' : '!!',
|
||||
}
|
||||
|
||||
respond_types_no_space = {
|
||||
'echo_no_space': 'echo:',
|
||||
}
|
||||
|
||||
class HostResponder:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
|
@ -26,18 +30,25 @@ class HostResponder:
|
|||
gcmd.respond_raw("%s %s" % (self.default_prefix, msg))
|
||||
cmd_RESPOND_help = ("Echo the message prepended with a prefix")
|
||||
def cmd_RESPOND(self, gcmd):
|
||||
no_space = False
|
||||
respond_type = gcmd.get('TYPE', None)
|
||||
prefix = self.default_prefix
|
||||
if(respond_type != None):
|
||||
respond_type = respond_type.lower()
|
||||
if(respond_type in respond_types):
|
||||
prefix = respond_types[respond_type]
|
||||
elif(respond_type in respond_types_no_space):
|
||||
prefix = respond_types_no_space[respond_type]
|
||||
no_space = True
|
||||
else:
|
||||
raise gcmd.error(
|
||||
"RESPOND TYPE '%s' is invalid. Must be one"
|
||||
" of 'echo', 'command', or 'error'" % (respond_type,))
|
||||
prefix = gcmd.get('PREFIX', prefix)
|
||||
msg = gcmd.get('MSG', '')
|
||||
if(no_space):
|
||||
gcmd.respond_raw("%s%s" % (prefix, msg))
|
||||
else:
|
||||
gcmd.respond_raw("%s %s" % (prefix, msg))
|
||||
|
||||
def load_config(config):
|
||||
|
|
Loading…
Reference in New Issue