2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the notify demo platform."""
|
2015-12-10 07:46:50 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import homeassistant.components.notify as notify
|
|
|
|
from homeassistant.components.notify import demo
|
|
|
|
|
2016-02-14 23:08:23 +00:00
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
2015-12-10 07:46:50 +00:00
|
|
|
|
|
|
|
class TestNotifyDemo(unittest.TestCase):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the demo notify."""
|
2015-12-10 07:46:50 +00:00
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Setup things to be run when tests are started."""
|
2016-02-14 23:08:23 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2015-12-10 07:46:50 +00:00
|
|
|
self.assertTrue(notify.setup(self.hass, {
|
|
|
|
'notify': {
|
|
|
|
'platform': 'demo'
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
self.events = []
|
|
|
|
|
|
|
|
def record_event(event):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Record event to send notification."""
|
2015-12-10 07:46:50 +00:00
|
|
|
self.events.append(event)
|
|
|
|
|
|
|
|
self.hass.bus.listen(demo.EVENT_NOTIFY, record_event)
|
|
|
|
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
2016-03-09 09:25:50 +00:00
|
|
|
""""Stop down everything that was started."""
|
2015-12-10 07:46:50 +00:00
|
|
|
self.hass.stop()
|
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_sending_none_message(self):
|
|
|
|
"""Test send with None as message."""
|
|
|
|
notify.send_message(self.hass, None)
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
self.assertTrue(len(self.events) == 0)
|
|
|
|
|
2015-12-10 07:46:50 +00:00
|
|
|
def test_sending_templated_message(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Send a templated message."""
|
2015-12-10 07:46:50 +00:00
|
|
|
self.hass.states.set('sensor.temperature', 10)
|
|
|
|
notify.send_message(self.hass, '{{ states.sensor.temperature.state }}',
|
|
|
|
'{{ states.sensor.temperature.name }}')
|
|
|
|
self.hass.pool.block_till_done()
|
|
|
|
last_event = self.events[-1]
|
|
|
|
self.assertEqual(last_event.data[notify.ATTR_TITLE], 'temperature')
|
|
|
|
self.assertEqual(last_event.data[notify.ATTR_MESSAGE], '10')
|