mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Extended group tests
This commit is contained in:
parent
a11ef38c9b
commit
c6cb2c27bd
@ -21,10 +21,14 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
|
|
||||||
self.hass.states.set('light.Bowl', comps.STATE_ON)
|
self.hass.states.set('light.Bowl', comps.STATE_ON)
|
||||||
self.hass.states.set('light.Ceiling', comps.STATE_OFF)
|
self.hass.states.set('light.Ceiling', comps.STATE_OFF)
|
||||||
|
self.hass.states.set('switch.AC', comps.STATE_OFF)
|
||||||
group.setup_group(self.hass, 'init_group',
|
group.setup_group(self.hass, 'init_group',
|
||||||
['light.Bowl', 'light.Ceiling'], False)
|
['light.Bowl', 'light.Ceiling'], False)
|
||||||
|
group.setup_group(self.hass, 'mixed_group',
|
||||||
|
['light.Bowl', 'switch.AC'], False)
|
||||||
|
|
||||||
self.group_name = group.ENTITY_ID_FORMAT.format('init_group')
|
self.group_name = group.ENTITY_ID_FORMAT.format('init_group')
|
||||||
|
self.mixed_group_name = group.ENTITY_ID_FORMAT.format('mixed_group')
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
@ -56,6 +60,26 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
group_state = self.hass.states.get(self.group_name)
|
group_state = self.hass.states.get(self.group_name)
|
||||||
self.assertEqual(comps.STATE_ON, group_state.state)
|
self.assertEqual(comps.STATE_ON, group_state.state)
|
||||||
|
|
||||||
|
# Try to setup a group with mixed groupable states
|
||||||
|
self.hass.states.set('device_tracker.Paulus', comps.STATE_HOME)
|
||||||
|
self.assertFalse(group.setup_group(
|
||||||
|
self.hass, 'person_and_light',
|
||||||
|
['light.Bowl', 'device_tracker.Paulus']))
|
||||||
|
|
||||||
|
# Try to setup a group with a non existing state
|
||||||
|
self.assertNotIn('non.existing', self.hass.states.entity_ids)
|
||||||
|
self.assertFalse(group.setup_group(
|
||||||
|
self.hass, 'light_and_nothing',
|
||||||
|
['light.Bowl', 'non.existing']))
|
||||||
|
|
||||||
|
# Try to setup a group with non groupable states
|
||||||
|
self.hass.states.set('cast.living_room', "Plex")
|
||||||
|
self.hass.states.set('cast.bedroom', "Netflix")
|
||||||
|
self.assertFalse(
|
||||||
|
group.setup_group(
|
||||||
|
self.hass, 'chromecasts',
|
||||||
|
['cast.living_room', 'cast.bedroom']))
|
||||||
|
|
||||||
def test__get_group_type(self):
|
def test__get_group_type(self):
|
||||||
""" Test _get_group_type method. """
|
""" 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_ON))
|
||||||
@ -65,6 +89,9 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
self.assertEqual('home_not_home',
|
self.assertEqual('home_not_home',
|
||||||
group._get_group_type(comps.STATE_NOT_HOME))
|
group._get_group_type(comps.STATE_NOT_HOME))
|
||||||
|
|
||||||
|
# Unsupported state
|
||||||
|
self.assertIsNone(group._get_group_type('unsupported_state'))
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
""" Test is_on method. """
|
""" Test is_on method. """
|
||||||
self.assertTrue(group.is_on(self.hass, self.group_name))
|
self.assertTrue(group.is_on(self.hass, self.group_name))
|
||||||
@ -72,23 +99,43 @@ class TestComponentsGroup(unittest.TestCase):
|
|||||||
self.hass._pool.block_till_done()
|
self.hass._pool.block_till_done()
|
||||||
self.assertFalse(group.is_on(self.hass, self.group_name))
|
self.assertFalse(group.is_on(self.hass, self.group_name))
|
||||||
|
|
||||||
|
# Try on non existing state
|
||||||
|
self.assertFalse(group.is_on(self.hass, 'non.existing'))
|
||||||
|
|
||||||
def test_expand_entity_ids(self):
|
def test_expand_entity_ids(self):
|
||||||
""" Test expand_entity_ids method. """
|
""" Test expand_entity_ids method. """
|
||||||
self.assertEqual(sorted(['light.Ceiling', 'light.Bowl']),
|
self.assertEqual(sorted(['light.Ceiling', 'light.Bowl']),
|
||||||
sorted(group.expand_entity_ids(
|
sorted(group.expand_entity_ids(
|
||||||
self.hass, [self.group_name])))
|
self.hass, [self.group_name])))
|
||||||
|
|
||||||
|
# Make sure that no duplicates are returned
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(['light.Ceiling', 'light.Bowl']),
|
sorted(['light.Ceiling', 'light.Bowl']),
|
||||||
sorted(group.expand_entity_ids(
|
sorted(group.expand_entity_ids(
|
||||||
self.hass, [self.group_name, 'light.Ceiling'])))
|
self.hass, [self.group_name, 'light.Ceiling'])))
|
||||||
|
|
||||||
|
# Test that non strings are ignored
|
||||||
|
self.assertEqual([], group.expand_entity_ids(self.hass, [5, True]))
|
||||||
|
|
||||||
def test_get_entity_ids(self):
|
def test_get_entity_ids(self):
|
||||||
""" Test get_entity_ids method. """
|
""" Test get_entity_ids method. """
|
||||||
|
# Get entity IDs from our group
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
sorted(['light.Ceiling', 'light.Bowl']),
|
sorted(['light.Ceiling', 'light.Bowl']),
|
||||||
sorted(group.get_entity_ids(self.hass, self.group_name)))
|
sorted(group.get_entity_ids(self.hass, self.group_name)))
|
||||||
|
|
||||||
|
# Test domain_filter
|
||||||
|
self.assertEqual(
|
||||||
|
['switch.AC'],
|
||||||
|
group.get_entity_ids(
|
||||||
|
self.hass, self.mixed_group_name, domain_filter="switch"))
|
||||||
|
|
||||||
|
# Test with non existing group name
|
||||||
|
self.assertEqual([], group.get_entity_ids(self.hass, 'non_existing'))
|
||||||
|
|
||||||
|
# Test with non-group state
|
||||||
|
self.assertEqual([], group.get_entity_ids(self.hass, 'switch.AC'))
|
||||||
|
|
||||||
def test_setup(self):
|
def test_setup(self):
|
||||||
""" Test setup method. """
|
""" Test setup method. """
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user