core/tests/components/random/test_sensor.py

37 lines
1.0 KiB
Python
Raw Normal View History

2016-10-31 07:01:25 +00:00
"""The test for the random number sensor platform."""
import unittest
from homeassistant.setup import setup_component
2016-10-31 07:01:25 +00:00
from tests.common import get_test_home_assistant
class TestRandomSensor(unittest.TestCase):
"""Test the Random number 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()
def test_random_sensor(self):
"""Test the Random number sensor."""
2016-10-31 07:01:25 +00:00
config = {
2019-07-31 19:25:30 +00:00
"sensor": {
"platform": "random",
"name": "test",
"minimum": 10,
"maximum": 20,
2016-10-31 07:01:25 +00:00
}
}
2019-07-31 19:25:30 +00:00
assert setup_component(self.hass, "sensor", config)
2016-10-31 07:01:25 +00:00
2019-07-31 19:25:30 +00:00
state = self.hass.states.get("sensor.test")
2016-10-31 07:01:25 +00:00
2019-07-31 19:25:30 +00:00
assert int(state.state) <= config["sensor"]["maximum"]
assert int(state.state) >= config["sensor"]["minimum"]