mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Added tests for Binary Command Sensor
This commit is contained in:
parent
2d0004f46a
commit
283d621e90
68
tests/components/binary_sensor/test_command_sensor.py
Normal file
68
tests/components/binary_sensor/test_command_sensor.py
Normal file
@ -0,0 +1,68 @@
|
||||
"""
|
||||
tests.components.binary_sensor.command_sensor
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests command binary sensor.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.components.binary_sensor import command_sensor
|
||||
|
||||
|
||||
class TestCommandSensorBinarySensor(unittest.TestCase):
|
||||
""" Test the Template sensor. """
|
||||
|
||||
def setUp(self):
|
||||
self.hass = ha.HomeAssistant()
|
||||
|
||||
def tearDown(self):
|
||||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup(self):
|
||||
""" Test sensor setup """
|
||||
config = {'name': 'Test',
|
||||
'command': 'echo 1',
|
||||
'payload_on': '1',
|
||||
'payload_off': '0'}
|
||||
devices = []
|
||||
|
||||
def add_dev_callback(devs):
|
||||
""" callback to add device """
|
||||
for dev in devs:
|
||||
devices.append(dev)
|
||||
|
||||
command_sensor.setup_platform(
|
||||
self.hass, config, add_dev_callback)
|
||||
|
||||
self.assertEqual(1, len(devices))
|
||||
entity = devices[0]
|
||||
self.assertEqual('Test', entity.name)
|
||||
self.assertTrue(entity.state)
|
||||
|
||||
def test_setup_bad_config(self):
|
||||
""" Test setup with a bad config """
|
||||
config = {}
|
||||
|
||||
devices = []
|
||||
|
||||
def add_dev_callback(devs):
|
||||
""" callback to add device """
|
||||
for dev in devs:
|
||||
devices.append(dev)
|
||||
|
||||
self.assertFalse(command_sensor.setup_platform(
|
||||
self.hass, config, add_dev_callback))
|
||||
|
||||
self.assertEqual(0, len(devices))
|
||||
|
||||
def test_template(self):
|
||||
""" Test command sensor with template """
|
||||
data = command_sensor.CommandSensorData('echo 10')
|
||||
|
||||
entity = command_sensor.CommandBinarySensor(
|
||||
self.hass, data, 'test', '1.0', '0', '{{ value | multiply(0.1) }}')
|
||||
|
||||
self.assertTrue(entity.state)
|
Loading…
x
Reference in New Issue
Block a user