Allow pipes in command sensors and services

pull/544/head^2
Paulus Schoutsen 2015-10-24 12:40:36 -07:00
parent e461ceae36
commit 96181a555a
3 changed files with 3 additions and 3 deletions

View File

@ -98,7 +98,7 @@ class CommandSensorData(object):
_LOGGER.info('Running command: %s', self.command) _LOGGER.info('Running command: %s', self.command)
try: try:
return_value = subprocess.check_output(self.command.split()) return_value = subprocess.check_output(self.command, shell=True)
self.value = return_value.strip().decode('utf-8') self.value = return_value.strip().decode('utf-8')
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
_LOGGER.error('Command failed: %s', self.command) _LOGGER.error('Command failed: %s', self.command)

View File

@ -34,7 +34,7 @@ def setup(hass, config):
def service_handler(call): def service_handler(call):
""" Execute a shell command service. """ """ Execute a shell command service. """
try: try:
subprocess.call(conf[call.service].split(' '), subprocess.call(conf[call.service], shell=True,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) stderr=subprocess.DEVNULL)
except subprocess.SubprocessError: except subprocess.SubprocessError:

View File

@ -30,7 +30,7 @@ class TestShellCommand(unittest.TestCase):
path = os.path.join(tempdirname, 'called.txt') path = os.path.join(tempdirname, 'called.txt')
self.assertTrue(shell_command.setup(self.hass, { self.assertTrue(shell_command.setup(self.hass, {
'shell_command': { 'shell_command': {
'test_service': "touch {}".format(path) 'test_service': "date > {}".format(path)
} }
})) }))