mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Added group component tests
This commit is contained in:
parent
bc4b81d525
commit
a11ef38c9b
107
test/test_component_group.py
Normal file
107
test/test_component_group.py
Normal file
@ -0,0 +1,107 @@
|
||||
"""
|
||||
test.test_component_group
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests the group compoments.
|
||||
"""
|
||||
# pylint: disable=protected-access,too-many-public-methods
|
||||
import unittest
|
||||
|
||||
import homeassistant as ha
|
||||
import homeassistant.components as comps
|
||||
import homeassistant.components.group as group
|
||||
|
||||
|
||||
class TestComponentsGroup(unittest.TestCase):
|
||||
""" Tests homeassistant.components.group module. """
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
""" Init needed objects. """
|
||||
self.hass = ha.HomeAssistant()
|
||||
|
||||
self.hass.states.set('light.Bowl', comps.STATE_ON)
|
||||
self.hass.states.set('light.Ceiling', comps.STATE_OFF)
|
||||
group.setup_group(self.hass, 'init_group',
|
||||
['light.Bowl', 'light.Ceiling'], False)
|
||||
|
||||
self.group_name = group.ENTITY_ID_FORMAT.format('init_group')
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
""" Stop down stuff we started. """
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_and_monitor_group(self):
|
||||
""" Test setup_group method. """
|
||||
|
||||
# Test if group setup in our init mode is ok
|
||||
self.assertIn(self.group_name, self.hass.states.entity_ids)
|
||||
|
||||
group_state = self.hass.states.get(self.group_name)
|
||||
self.assertEqual(comps.STATE_ON, group_state.state)
|
||||
self.assertTrue(group_state.attributes[group.ATTR_AUTO])
|
||||
|
||||
# Turn the Bowl off and see if group turns off
|
||||
self.hass.states.set('light.Bowl', comps.STATE_OFF)
|
||||
|
||||
self.hass._pool.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(self.group_name)
|
||||
self.assertEqual(comps.STATE_OFF, group_state.state)
|
||||
|
||||
# Turn the Ceiling on and see if group turns on
|
||||
self.hass.states.set('light.Ceiling', comps.STATE_ON)
|
||||
|
||||
self.hass._pool.block_till_done()
|
||||
|
||||
group_state = self.hass.states.get(self.group_name)
|
||||
self.assertEqual(comps.STATE_ON, group_state.state)
|
||||
|
||||
def test__get_group_type(self):
|
||||
""" Test _get_group_type method. """
|
||||
self.assertEqual('on_off', group._get_group_type(comps.STATE_ON))
|
||||
self.assertEqual('on_off', group._get_group_type(comps.STATE_OFF))
|
||||
self.assertEqual('home_not_home',
|
||||
group._get_group_type(comps.STATE_HOME))
|
||||
self.assertEqual('home_not_home',
|
||||
group._get_group_type(comps.STATE_NOT_HOME))
|
||||
|
||||
def test_is_on(self):
|
||||
""" Test is_on method. """
|
||||
self.assertTrue(group.is_on(self.hass, self.group_name))
|
||||
self.hass.states.set('light.Bowl', comps.STATE_OFF)
|
||||
self.hass._pool.block_till_done()
|
||||
self.assertFalse(group.is_on(self.hass, self.group_name))
|
||||
|
||||
def test_expand_entity_ids(self):
|
||||
""" Test expand_entity_ids method. """
|
||||
self.assertEqual(sorted(['light.Ceiling', 'light.Bowl']),
|
||||
sorted(group.expand_entity_ids(
|
||||
self.hass, [self.group_name])))
|
||||
|
||||
self.assertEqual(
|
||||
sorted(['light.Ceiling', 'light.Bowl']),
|
||||
sorted(group.expand_entity_ids(
|
||||
self.hass, [self.group_name, 'light.Ceiling'])))
|
||||
|
||||
def test_get_entity_ids(self):
|
||||
""" Test get_entity_ids method. """
|
||||
self.assertEqual(
|
||||
sorted(['light.Ceiling', 'light.Bowl']),
|
||||
sorted(group.get_entity_ids(self.hass, self.group_name)))
|
||||
|
||||
def test_setup(self):
|
||||
""" Test setup method. """
|
||||
self.assertTrue(
|
||||
group.setup(
|
||||
self.hass,
|
||||
{
|
||||
group.DOMAIN: {
|
||||
'second_group': '{},light.Bowl'.format(self.group_name)
|
||||
}
|
||||
}))
|
||||
|
||||
group_state = self.hass.states.get(
|
||||
group.ENTITY_ID_FORMAT.format('second_group'))
|
||||
|
||||
self.assertEqual(comps.STATE_ON, group_state.state)
|
||||
self.assertFalse(group_state.attributes[group.ATTR_AUTO])
|
Loading…
x
Reference in New Issue
Block a user