2014-11-23 17:51:16 +00:00
|
|
|
"""
|
2015-01-09 04:05:12 +00:00
|
|
|
tests.test_component_core
|
2014-12-01 07:14:08 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2014-11-23 17:51:16 +00:00
|
|
|
|
2014-11-23 20:57:29 +00:00
|
|
|
Tests core compoments.
|
2014-11-23 17:51:16 +00:00
|
|
|
"""
|
|
|
|
# pylint: disable=protected-access,too-many-public-methods
|
|
|
|
import unittest
|
|
|
|
|
2015-08-17 03:44:46 +00:00
|
|
|
import homeassistant.core as ha
|
2014-11-23 17:51:16 +00:00
|
|
|
import homeassistant.loader as loader
|
2014-12-07 07:57:02 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
STATE_ON, STATE_OFF, SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
2014-11-23 17:51:16 +00:00
|
|
|
import homeassistant.components as comps
|
|
|
|
|
|
|
|
|
|
|
|
class TestComponentsCore(unittest.TestCase):
|
|
|
|
""" Tests homeassistant.components module. """
|
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
|
|
|
""" Init needed objects. """
|
|
|
|
self.hass = ha.HomeAssistant()
|
|
|
|
self.assertTrue(comps.setup(self.hass, {}))
|
|
|
|
|
2014-12-07 07:57:02 +00:00
|
|
|
self.hass.states.set('light.Bowl', STATE_ON)
|
|
|
|
self.hass.states.set('light.Ceiling', STATE_OFF)
|
2014-11-23 17:51:16 +00:00
|
|
|
|
2014-11-23 20:57:29 +00:00
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
|
|
""" Stop down stuff we started. """
|
2014-11-29 04:22:08 +00:00
|
|
|
self.hass.stop()
|
2014-11-23 20:57:29 +00:00
|
|
|
|
2014-11-23 17:51:16 +00:00
|
|
|
def test_is_on(self):
|
|
|
|
""" Test is_on method. """
|
|
|
|
self.assertTrue(comps.is_on(self.hass, 'light.Bowl'))
|
|
|
|
self.assertFalse(comps.is_on(self.hass, 'light.Ceiling'))
|
|
|
|
self.assertTrue(comps.is_on(self.hass))
|
|
|
|
|
|
|
|
def test_turn_on(self):
|
|
|
|
""" Test turn_on method. """
|
|
|
|
runs = []
|
|
|
|
self.hass.services.register(
|
2014-12-07 07:57:02 +00:00
|
|
|
'light', SERVICE_TURN_ON, lambda x: runs.append(1))
|
2014-11-23 17:51:16 +00:00
|
|
|
|
|
|
|
comps.turn_on(self.hass, 'light.Ceiling')
|
|
|
|
|
2014-12-17 05:46:02 +00:00
|
|
|
self.hass.pool.block_till_done()
|
2014-11-23 17:51:16 +00:00
|
|
|
|
|
|
|
self.assertEqual(1, len(runs))
|
|
|
|
|
|
|
|
def test_turn_off(self):
|
|
|
|
""" Test turn_off method. """
|
|
|
|
runs = []
|
|
|
|
self.hass.services.register(
|
2014-12-07 07:57:02 +00:00
|
|
|
'light', SERVICE_TURN_OFF, lambda x: runs.append(1))
|
2014-11-23 17:51:16 +00:00
|
|
|
|
|
|
|
comps.turn_off(self.hass, 'light.Bowl')
|
|
|
|
|
2014-12-17 05:46:02 +00:00
|
|
|
self.hass.pool.block_till_done()
|
2014-11-23 17:51:16 +00:00
|
|
|
|
|
|
|
self.assertEqual(1, len(runs))
|