Use voluptuous for Command line platforms (#2968)

* Migrate to voluptuous

* Fix pylint issues

* Remove FIXME

* Split setup test

* Test with bootstrap

* Remove lon and lat

* Fix pylint issues
This commit is contained in:
Fabian Affolter authored and Teagan Glenn committed 2016-09-02 08:09:09 -06:00
1 parent 81628b01c2
commit 40c71b5d96
11 files changed
+199 -134

No files matched your search

@@ -3,6 +3,7 @@ import unittest
from homeassistant.const import (STATE_ON, STATE_OFF)
from homeassistant.components.binary_sensor import command_line
from homeassistant import bootstrap
from tests.common import get_test_home_assistant
@@ -24,6 +25,7 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
'command': 'echo 1',
'payload_on': '1',
'payload_off': '0'}
devices = []
def add_dev_callback(devs):
@@ -31,8 +33,7 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
for dev in devs:
devices.append(dev)
command_line.setup_platform(
self.hass, config, add_dev_callback)
command_line.setup_platform(self.hass, config, add_dev_callback)
self.assertEqual(1, len(devices))
entity = devices[0]
@@ -41,19 +42,13 @@ class TestCommandSensorBinarySensor(unittest.TestCase):
def test_setup_bad_config(self):
"""Test the setup with a bad configuration."""
config = {}
config = {'name': 'test',
'platform': 'not_command_line',
}
devices = []
def add_dev_callback(devs):
"""Add callback to add devices."""
for dev in devs:
devices.append(dev)
self.assertFalse(command_line.setup_platform(
self.hass, config, add_dev_callback))
self.assertEqual(0, len(devices))
self.assertFalse(bootstrap.setup_component(self.hass, 'test', {
'command_line': config,
}))
def test_template(self):
"""Test setting the state with a template."""
+7 -9
View File
@@ -17,12 +17,10 @@ class TestCommandCover(unittest.TestCase):
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = ha.HomeAssistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
self.rs = cmd_rs.CommandCover(self.hass, 'foo',
'cmd_open', 'cmd_close',
'cmd_stop', 'cmd_state',
None) # FIXME
'command_open', 'command_close',
'command_stop', 'command_state',
None)
def teardown_method(self, method):
"""Stop down everything that was started."""
@@ -47,10 +45,10 @@ class TestCommandCover(unittest.TestCase):
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'cover_status')
test_cover = {
'statecmd': 'cat {}'.format(path),
'opencmd': 'echo 1 > {}'.format(path),
'closecmd': 'echo 1 > {}'.format(path),
'stopcmd': 'echo 0 > {}'.format(path),
'command_state': 'cat {}'.format(path),
'command_open': 'echo 1 > {}'.format(path),
'command_close': 'echo 1 > {}'.format(path),
'command_stop': 'echo 0 > {}'.format(path),
'value_template': '{{ value }}'
}
self.assertTrue(cover.setup(self.hass, {
+12 -10
View File
@@ -2,13 +2,12 @@
import os
import tempfile
import unittest
from unittest.mock import patch
import homeassistant.components.notify as notify
from homeassistant import bootstrap
from tests.common import get_test_home_assistant
from unittest.mock import patch
class TestCommandLine(unittest.TestCase):
"""Test the command line notifications."""
@@ -21,20 +20,23 @@ class TestCommandLine(unittest.TestCase):
"""Stop down everything that was started."""
self.hass.stop()
def test_setup(self):
"""Test setup."""
assert bootstrap.setup_component(self.hass, 'notify', {
'notify': {
'name': 'test',
'platform': 'command_line',
'command': 'echo $(cat); exit 1',
}})
def test_bad_config(self):
"""Test set up the platform with bad/missing config."""
"""Test set up the platform with bad/missing configuration."""
self.assertFalse(notify.setup(self.hass, {
'notify': {
'name': 'test',
'platform': 'bad_platform',
}
}))
self.assertFalse(notify.setup(self.hass, {
'notify': {
'name': 'test',
'platform': 'command_line',
}
}))
def test_command_line_output(self):
"""Test the command line output."""
+10 -16
View File
@@ -2,7 +2,7 @@
import unittest
from homeassistant.components.sensor import command_line
from homeassistant import bootstrap
from tests.common import get_test_home_assistant
@@ -21,7 +21,8 @@ class TestCommandSensorSensor(unittest.TestCase):
"""Test sensor setup."""
config = {'name': 'Test',
'unit_of_measurement': 'in',
'command': 'echo 5'}
'command': 'echo 5'
}
devices = []
def add_dev_callback(devs):
@@ -29,8 +30,7 @@ class TestCommandSensorSensor(unittest.TestCase):
for dev in devs:
devices.append(dev)
command_line.setup_platform(
self.hass, config, add_dev_callback)
command_line.setup_platform(self.hass, config, add_dev_callback)
self.assertEqual(1, len(devices))
entity = devices[0]
@@ -40,19 +40,13 @@ class TestCommandSensorSensor(unittest.TestCase):
def test_setup_bad_config(self):
"""Test setup with a bad configuration."""
config = {}
config = {'name': 'test',
'platform': 'not_command_line',
}
devices = []
def add_dev_callback(devs):
"""Add a callback to add devices."""
for dev in devs:
devices.append(dev)
self.assertFalse(command_line.setup_platform(
self.hass, config, add_dev_callback))
self.assertEqual(0, len(devices))
self.assertFalse(bootstrap.setup_component(self.hass, 'test', {
'command_line': config,
}))
def test_template(self):
"""Test command sensor with template."""
+11 -11
View File
@@ -27,8 +27,8 @@ class TestCommandSwitch(unittest.TestCase):
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {
'oncmd': 'echo 1 > {}'.format(path),
'offcmd': 'echo 0 > {}'.format(path),
'command_on': 'echo 1 > {}'.format(path),
'command_off': 'echo 0 > {}'.format(path),
}
self.assertTrue(switch.setup(self.hass, {
'switch': {
@@ -59,9 +59,9 @@ class TestCommandSwitch(unittest.TestCase):
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {
'statecmd': 'cat {}'.format(path),
'oncmd': 'echo 1 > {}'.format(path),
'offcmd': 'echo 0 > {}'.format(path),
'command_state': 'cat {}'.format(path),
'command_on': 'echo 1 > {}'.format(path),
'command_off': 'echo 0 > {}'.format(path),
'value_template': '{{ value=="1" }}'
}
self.assertTrue(switch.setup(self.hass, {
@@ -95,9 +95,9 @@ class TestCommandSwitch(unittest.TestCase):
oncmd = json.dumps({'status': 'ok'})
offcmd = json.dumps({'status': 'nope'})
test_switch = {
'statecmd': 'cat {}'.format(path),
'oncmd': 'echo \'{}\' > {}'.format(oncmd, path),
'offcmd': 'echo \'{}\' > {}'.format(offcmd, path),
'command_state': 'cat {}'.format(path),
'command_on': 'echo \'{}\' > {}'.format(oncmd, path),
'command_off': 'echo \'{}\' > {}'.format(offcmd, path),
'value_template': '{{ value_json.status=="ok" }}'
}
self.assertTrue(switch.setup(self.hass, {
@@ -129,9 +129,9 @@ class TestCommandSwitch(unittest.TestCase):
with tempfile.TemporaryDirectory() as tempdirname:
path = os.path.join(tempdirname, 'switch_status')
test_switch = {
'statecmd': 'cat {}'.format(path),
'oncmd': 'echo 1 > {}'.format(path),
'offcmd': 'echo 0 > {}'.format(path),
'command_state': 'cat {}'.format(path),
'command_on': 'echo 1 > {}'.format(path),
'command_off': 'echo 0 > {}'.format(path),
}
self.assertTrue(switch.setup(self.hass, {
'switch': {