Allow service data to be passed to shell_command (#2362)
parent
3349bdc2bd
commit
600a3e3965
|
@ -6,6 +6,7 @@ https://home-assistant.io/components/shell_command/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
@ -23,8 +24,6 @@ CONFIG_SCHEMA = vol.Schema({
|
||||||
}),
|
}),
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
SHELL_COMMAND_SCHEMA = vol.Schema({})
|
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Setup the shell_command component."""
|
"""Setup the shell_command component."""
|
||||||
|
@ -44,8 +43,7 @@ def setup(hass, config):
|
||||||
_LOGGER.exception('Error running command: %s', cmd)
|
_LOGGER.exception('Error running command: %s', cmd)
|
||||||
|
|
||||||
for name in conf.keys():
|
for name in conf.keys():
|
||||||
hass.services.register(DOMAIN, name, service_handler,
|
hass.services.register(DOMAIN, name, service_handler)
|
||||||
schema=SHELL_COMMAND_SCHEMA)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +62,6 @@ def _parse_command(hass, cmd, variables):
|
||||||
shell = True
|
shell = True
|
||||||
else:
|
else:
|
||||||
# template used. Must break into list and use shell=False for security
|
# template used. Must break into list and use shell=False for security
|
||||||
cmd = [prog] + rendered_args.split()
|
cmd = [prog] + shlex.split(rendered_args)
|
||||||
shell = False
|
shell = False
|
||||||
return cmd, shell
|
return cmd, shell
|
||||||
|
|
Loading…
Reference in New Issue