From 96181a555a73107b7b462dabb4ebe6f2ce3ce4a0 Mon Sep 17 00:00:00 2001
From: Paulus Schoutsen <paulus@paulusschoutsen.nl>
Date: Sat, 24 Oct 2015 12:40:36 -0700
Subject: [PATCH] Allow pipes in command sensors and services

---
 homeassistant/components/sensor/command_sensor.py | 2 +-
 homeassistant/components/shell_command.py         | 2 +-
 tests/components/test_shell_command.py            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/homeassistant/components/sensor/command_sensor.py b/homeassistant/components/sensor/command_sensor.py
index fc651fcc157..82ac36be500 100644
--- a/homeassistant/components/sensor/command_sensor.py
+++ b/homeassistant/components/sensor/command_sensor.py
@@ -98,7 +98,7 @@ class CommandSensorData(object):
         _LOGGER.info('Running command: %s', self.command)
 
         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')
         except subprocess.CalledProcessError:
             _LOGGER.error('Command failed: %s', self.command)
diff --git a/homeassistant/components/shell_command.py b/homeassistant/components/shell_command.py
index c5c60e98e7d..493b605091a 100644
--- a/homeassistant/components/shell_command.py
+++ b/homeassistant/components/shell_command.py
@@ -34,7 +34,7 @@ def setup(hass, config):
     def service_handler(call):
         """ Execute a shell command service. """
         try:
-            subprocess.call(conf[call.service].split(' '),
+            subprocess.call(conf[call.service], shell=True,
                             stdout=subprocess.DEVNULL,
                             stderr=subprocess.DEVNULL)
         except subprocess.SubprocessError:
diff --git a/tests/components/test_shell_command.py b/tests/components/test_shell_command.py
index d9248d8f861..eefbdc5b230 100644
--- a/tests/components/test_shell_command.py
+++ b/tests/components/test_shell_command.py
@@ -30,7 +30,7 @@ class TestShellCommand(unittest.TestCase):
             path = os.path.join(tempdirname, 'called.txt')
             self.assertTrue(shell_command.setup(self.hass, {
                 'shell_command': {
-                    'test_service': "touch {}".format(path)
+                    'test_service': "date > {}".format(path)
                 }
             }))
 
-- 
GitLab