core/tests/components/sensor/test_template.py

45 lines
1.1 KiB
Python
Raw Normal View History

2016-01-21 18:31:44 +00:00
"""
tests.components.sensor.template
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests template sensor.
"""
from unittest.mock import patch
import pytest
import homeassistant.core as ha
import homeassistant.components.sensor as sensor
class TestSensorYr:
""" Test the Yr sensor. """
def setup_method(self, method):
self.hass = ha.HomeAssistant()
def teardown_method(self, method):
""" Stop down stuff we started. """
self.hass.stop()
def test_template(self, betamax_session):
2016-01-21 23:17:19 +00:00
assert sensor.setup(self.hass, {
'sensor': {
'platform': 'template',
'sensors': {
'test_template_sensor': {
'value_template':
'{{ states.sensor.test_state.state }}'
2016-01-21 18:31:44 +00:00
}
}
2016-01-21 23:17:19 +00:00
}
})
2016-01-21 18:31:44 +00:00
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == ''
self.hass.states.set('sensor.test_state', 'Works')
self.hass.pool.block_till_done()
state = self.hass.states.get('sensor.test_template_sensor')
assert state.state == 'Works'