1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add Random binary sensor (#10164)

This commit is contained in:
Fabian Affolter
2017-10-29 11:15:57 +01:00
committed by GitHub
parent 6057b41151
commit 35805e51a3
2 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
"""The test for the Random binary sensor platform."""
import unittest
from unittest.mock import patch
from homeassistant.setup import setup_component
from tests.common import get_test_home_assistant
class TestRandomSensor(unittest.TestCase):
"""Test the Random binary sensor."""
def setup_method(self, method):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop()
@patch('random.getrandbits', return_value=1)
def test_random_binary_sensor_on(self, mocked):
"""Test the Random binary sensor."""
config = {
'binary_sensor': {
'platform': 'random',
'name': 'test',
}
}
assert setup_component(self.hass, 'binary_sensor', config)
state = self.hass.states.get('binary_sensor.test')
self.assertEqual(state.state, 'on')
@patch('random.getrandbits', return_value=False)
def test_random_binary_sensor_off(self, mocked):
"""Test the Random binary sensor."""
config = {
'binary_sensor': {
'platform': 'random',
'name': 'test',
}
}
assert setup_component(self.hass, 'binary_sensor', config)
state = self.hass.states.get('binary_sensor.test')
self.assertEqual(state.state, 'off')